From 063e7e716874c673bd93f11808471dd6e7258757 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Wed, 29 Aug 2012 12:55:40 +0200 Subject: [PATCH 01/60] Added Abiquo support in labs --- labs/abiquo/NOTICE | 25 + labs/abiquo/README.md | 21 + labs/abiquo/pom.xml | 331 +++ .../java/org/jclouds/abiquo/AbiquoApi.java | 101 + .../org/jclouds/abiquo/AbiquoApiMetadata.java | 124 + .../org/jclouds/abiquo/AbiquoAsyncApi.java | 108 + .../org/jclouds/abiquo/AbiquoContext.java | 90 + .../jclouds/abiquo/binders/AppendToPath.java | 56 + .../abiquo/binders/BindLinkToPath.java | 49 + .../BindLinkToPathAndAcceptHeader.java | 54 + .../abiquo/binders/BindRefsToPayload.java | 73 + .../jclouds/abiquo/binders/BindToPath.java | 159 ++ .../binders/BindToXMLPayloadAndPath.java | 82 + .../cloud/BindHardDiskRefsToPayload.java | 50 + .../binders/cloud/BindIpRefToPayload.java | 65 + .../binders/cloud/BindIpRefsToPayload.java | 75 + .../binders/cloud/BindMoveVolumeToPath.java | 52 + .../BindNetworkConfigurationRefToPayload.java | 79 + .../cloud/BindNetworkRefToPayload.java | 83 + .../cloud/BindUnmanagedIpRefToPayload.java | 70 + .../BindVirtualDatacenterRefToPayload.java | 67 + .../cloud/BindVolumeRefsToPayload.java | 51 + .../infrastructure/AppendMachineIdToPath.java | 53 + .../AppendRemoteServiceTypeToPath.java | 54 + .../BindSupportedDevicesLinkToPath.java | 42 + .../ucs/BindLogicServerParameters.java | 53 + .../ucs/BindOrganizationParameters.java | 54 + .../AbiquoComputeServiceContextModule.java | 83 + .../NotEnoughResourcesException.java | 53 + .../functions/DatacenterToLocation.java | 58 + .../VirtualMachineStateToNodeState.java | 60 + .../VirtualMachineTemplateToHardware.java | 73 + .../VirtualMachineTemplateToImage.java | 65 + .../VirtualMachineToNodeMetadata.java | 156 ++ .../options/AbiquoTemplateOptions.java | 257 ++ .../strategy/AbiquoComputeServiceAdapter.java | 251 ++ .../strategy/AbiquoComputeServiceHelper.java | 256 ++ .../abiquo/config/AbiquoRestClientModule.java | 154 ++ .../domain/DomainWithLimitsWrapper.java | 195 ++ .../abiquo/domain/DomainWithTasksWrapper.java | 83 + .../jclouds/abiquo/domain/DomainWrapper.java | 241 ++ .../abiquo/domain/builder/LimitsBuilder.java | 104 + .../abiquo/domain/cloud/Conversion.java | 163 ++ .../jclouds/abiquo/domain/cloud/HardDisk.java | 181 ++ .../abiquo/domain/cloud/VirtualAppliance.java | 403 ++++ .../domain/cloud/VirtualDatacenter.java | 680 ++++++ .../abiquo/domain/cloud/VirtualMachine.java | 1014 ++++++++ .../domain/cloud/VirtualMachineTemplate.java | 407 ++++ .../jclouds/abiquo/domain/cloud/Volume.java | 250 ++ .../cloud/options/ConversionOptions.java | 82 + .../options/VirtualApplianceOptions.java | 68 + .../options/VirtualDatacenterOptions.java | 84 + .../cloud/options/VirtualMachineOptions.java | 67 + .../VirtualMachineTemplateOptions.java | 120 + .../domain/cloud/options/VolumeOptions.java | 69 + .../abiquo/domain/config/Category.java | 186 ++ .../abiquo/domain/config/Currency.java | 191 ++ .../jclouds/abiquo/domain/config/License.java | 142 ++ .../abiquo/domain/config/Privilege.java | 66 + .../abiquo/domain/config/SystemProperty.java | 84 + .../domain/config/options/IconOptions.java | 65 + .../domain/config/options/LicenseOptions.java | 78 + .../config/options/PropertyOptions.java | 77 + .../abiquo/domain/enterprise/Enterprise.java | 1000 ++++++++ .../enterprise/EnterpriseProperties.java | 88 + .../abiquo/domain/enterprise/Limits.java | 165 ++ .../abiquo/domain/enterprise/Role.java | 250 ++ .../enterprise/TemplateDefinitionList.java | 236 ++ .../domain/enterprise/TemplateState.java | 81 + .../abiquo/domain/enterprise/User.java | 509 ++++ .../enterprise/options/EnterpriseOptions.java | 132 + .../jclouds/abiquo/domain/event/Event.java | 393 +++ .../domain/event/options/EventOptions.java | 196 ++ .../domain/exception/AbiquoException.java | 128 + .../domain/exception/BuilderException.java | 61 + .../domain/exception/WrapperException.java | 75 + .../AbstractPhysicalMachine.java | 356 +++ .../abiquo/domain/infrastructure/Blade.java | 176 ++ .../infrastructure/BladeLocatorLed.java | 81 + .../domain/infrastructure/Datacenter.java | 1174 +++++++++ .../domain/infrastructure/Datastore.java | 101 + .../abiquo/domain/infrastructure/Fsm.java | 84 + .../domain/infrastructure/LogicServer.java | 102 + .../abiquo/domain/infrastructure/Machine.java | 549 +++++ .../domain/infrastructure/ManagedRack.java | 786 ++++++ .../domain/infrastructure/Organization.java | 108 + .../abiquo/domain/infrastructure/Rack.java | 421 ++++ .../domain/infrastructure/RemoteService.java | 277 +++ .../domain/infrastructure/StorageDevice.java | 532 ++++ .../infrastructure/StorageDeviceMetadata.java | 67 + .../domain/infrastructure/StoragePool.java | 376 +++ .../abiquo/domain/infrastructure/Tier.java | 187 ++ .../options/DatacenterOptions.java | 64 + .../infrastructure/options/IpmiOptions.java | 68 + .../options/MachineOptions.java | 84 + .../options/StoragePoolOptions.java | 71 + .../domain/network/AbstractPublicIp.java | 68 + .../abiquo/domain/network/ExternalIp.java | 89 + .../domain/network/ExternalNetwork.java | 259 ++ .../org/jclouds/abiquo/domain/network/Ip.java | 85 + .../abiquo/domain/network/Network.java | 379 +++ .../jclouds/abiquo/domain/network/Nic.java | 66 + .../abiquo/domain/network/PrivateIp.java | 89 + .../abiquo/domain/network/PrivateNetwork.java | 193 ++ .../abiquo/domain/network/PublicIp.java | 87 + .../abiquo/domain/network/PublicNetwork.java | 215 ++ .../abiquo/domain/network/UnmanagedIp.java | 89 + .../domain/network/UnmanagedNetwork.java | 260 ++ .../domain/network/options/IpOptions.java | 67 + .../network/options/NetworkOptions.java | 81 + .../domain/options/search/FilterOptions.java | 143 ++ .../options/search/reference/OrderBy.java | 44 + .../jclouds/abiquo/domain/task/AsyncJob.java | 87 + .../jclouds/abiquo/domain/task/AsyncTask.java | 115 + .../jclouds/abiquo/domain/util/LinkUtils.java | 61 + .../events/handlers/AbstractEventHandler.java | 57 + .../events/handlers/BlockingEventHandler.java | 169 ++ .../abiquo/events/monitor/CompletedEvent.java | 34 + .../abiquo/events/monitor/FailedEvent.java | 34 + .../abiquo/events/monitor/MonitorEvent.java | 78 + .../abiquo/events/monitor/TimeoutEvent.java | 34 + .../org/jclouds/abiquo/features/AdminApi.java | 115 + .../abiquo/features/AdminAsyncApi.java | 153 ++ .../org/jclouds/abiquo/features/CloudApi.java | 680 ++++++ .../abiquo/features/CloudAsyncApi.java | 764 ++++++ .../jclouds/abiquo/features/ConfigApi.java | 167 ++ .../abiquo/features/ConfigAsyncApi.java | 211 ++ .../abiquo/features/EnterpriseApi.java | 359 +++ .../abiquo/features/EnterpriseAsyncApi.java | 425 ++++ .../org/jclouds/abiquo/features/EventApi.java | 54 + .../abiquo/features/EventAsyncApi.java | 64 + .../abiquo/features/InfrastructureApi.java | 1038 ++++++++ .../features/InfrastructureAsyncApi.java | 1110 +++++++++ .../jclouds/abiquo/features/PricingApi.java | 80 + .../abiquo/features/PricingAsyncApi.java | 108 + .../org/jclouds/abiquo/features/TaskApi.java | 60 + .../jclouds/abiquo/features/TaskAsyncApi.java | 73 + .../features/VirtualMachineTemplateApi.java | 151 ++ .../VirtualMachineTemplateAsyncApi.java | 184 ++ .../services/AdministrationService.java | 241 ++ .../features/services/CloudService.java | 111 + .../features/services/EventService.java | 46 + .../features/services/MonitoringService.java | 137 ++ .../features/services/PricingService.java | 54 + .../features/services/SearchService.java | 143 ++ .../AppendApiVersionToAbiquoMimeType.java | 72 + .../jclouds/abiquo/functions/ParseErrors.java | 45 + .../ReturnAbiquoExceptionOnNotFoundOr4xx.java | 63 + .../functions/ReturnFalseIfNotAvailable.java | 87 + .../abiquo/functions/ReturnFalseOn5xx.java | 73 + .../abiquo/functions/ReturnMovedResource.java | 77 + .../abiquo/functions/ReturnNullOn303.java | 73 + .../functions/ReturnTaskReferenceOrNull.java | 72 + .../cloud/ReturnMoveVolumeReference.java | 45 + .../functions/cloud/ReturnMovedVolume.java | 52 + .../enterprise/ParseEnterpriseId.java | 47 + .../infrastructure/ParseDatacenterId.java | 47 + .../infrastructure/ParseMachineId.java | 47 + .../ParseRemoteServiceType.java | 48 + .../abiquo/handlers/AbiquoErrorHandler.java | 137 ++ .../http/filters/AbiquoAuthentication.java | 100 + .../filters/AppendApiVersionToMediaType.java | 85 + .../abiquo/internal/AbiquoContextImpl.java | 125 + .../internal/BaseAdministrationService.java | 364 +++ .../abiquo/internal/BaseCloudService.java | 171 ++ .../abiquo/internal/BaseEventService.java | 71 + .../internal/BaseMonitoringService.java | 335 +++ .../abiquo/internal/BasePricingService.java | 80 + .../abiquo/internal/BaseSearchService.java | 182 ++ .../abiquo/monitor/AsyncTaskMonitor.java | 69 + .../abiquo/monitor/ConversionMonitor.java | 71 + .../jclouds/abiquo/monitor/MonitorStatus.java | 37 + .../monitor/VirtualApplianceMonitor.java | 107 + .../abiquo/monitor/VirtualMachineMonitor.java | 144 ++ .../functions/AsyncTaskStatusMonitor.java | 75 + .../functions/ConversionStatusMonitor.java | 73 + .../VirtualApplianceDeployMonitor.java | 75 + .../VirtualApplianceUndeployMonitor.java | 82 + .../VirtualMachineDeployMonitor.java | 74 + .../functions/VirtualMachineStateMonitor.java | 71 + .../VirtualMachineUndeployMonitor.java | 85 + .../internal/BaseAsyncTaskMonitor.java | 91 + .../internal/BaseConversionMonitor.java | 92 + .../internal/BaseVirtualApplianceMonitor.java | 123 + .../internal/BaseVirtualMachineMonitor.java | 151 ++ .../abiquo/predicates/ErrorPredicates.java | 49 + .../abiquo/predicates/LinkPredicates.java | 61 + .../cloud/ConversionPredicates.java | 98 + .../cloud/VirtualAppliancePredicates.java | 50 + .../cloud/VirtualDatacenterPredicates.java | 104 + .../cloud/VirtualMachinePredicates.java | 80 + .../VirtualMachineTemplatePredicates.java | 94 + .../predicates/cloud/VolumePredicates.java | 89 + .../predicates/config/CategoryPredicates.java | 52 + .../predicates/config/CurrencyPredicates.java | 52 + .../predicates/config/LicensePredicates.java | 64 + .../config/PrivilegePredicates.java | 51 + .../config/SystemPropertyPredicates.java | 52 + .../enterprise/EnterprisePredicates.java | 50 + .../predicates/enterprise/RolePredicates.java | 50 + .../TemplateDefinitionListPredicates.java | 51 + .../predicates/enterprise/UserPredicates.java | 50 + .../infrastructure/BladePredicates.java | 70 + .../infrastructure/DatacenterPredicates.java | 78 + .../infrastructure/DatastorePredicates.java | 50 + .../infrastructure/HypervisorPredicates.java | 50 + .../infrastructure/LogicServerPredicates.java | 50 + .../infrastructure/MachinePredicates.java | 70 + .../infrastructure/ManagedRackPredicates.java | 51 + .../infrastructure/RackPredicates.java | 51 + .../RemoteServicePredicates.java | 52 + .../StorageDeviceMetadataPredicates.java | 51 + .../StorageDevicePredicates.java | 79 + .../infrastructure/StoragePoolPredicates.java | 51 + .../infrastructure/TierPredicates.java | 51 + .../predicates/network/IpPredicates.java | 90 + .../predicates/network/NetworkPredicates.java | 51 + .../predicates/network/NicPredicates.java | 64 + .../predicates/task/AsyncTaskPredicates.java | 51 + .../abiquo/reference/AbiquoConstants.java | 45 + .../abiquo/reference/AbiquoEdition.java | 30 + .../abiquo/reference/ValidationErrors.java | 37 + .../annotations/EnterpriseEdition.java | 35 + .../abiquo/reference/rest/ParentLinkName.java | 66 + .../abiquo/rest/annotations/EndpointLink.java | 41 + .../rest/internal/AbiquoHttpAsyncClient.java | 51 + .../rest/internal/AbiquoHttpClient.java | 44 + .../abiquo/rest/internal/ExtendedUtils.java | 84 + .../jclouds/abiquo/strategy/ListEntities.java | 36 + .../abiquo/strategy/ListRootEntities.java | 36 + .../abiquo/strategy/admin/ListRoles.java | 37 + .../admin/internal/ListRolesImpl.java | 70 + .../strategy/cloud/ListAttachedNics.java | 38 + .../strategy/cloud/ListVirtualAppliances.java | 37 + .../cloud/ListVirtualDatacenters.java | 47 + .../strategy/cloud/ListVirtualMachines.java | 38 + .../cloud/internal/ListAttachedNicsImpl.java | 138 ++ .../internal/ListVirtualAppliancesImpl.java | 117 + .../internal/ListVirtualDatacentersImpl.java | 132 + .../internal/ListVirtualMachinesImpl.java | 127 + .../strategy/config/ListCategories.java | 36 + .../strategy/config/ListCurrencies.java | 37 + .../abiquo/strategy/config/ListLicenses.java | 38 + .../strategy/config/ListPrivileges.java | 36 + .../strategy/config/ListProperties.java | 38 + .../config/internal/ListCategoriesImpl.java | 70 + .../config/internal/ListCurrenciesImpl.java | 70 + .../config/internal/ListLicensesImpl.java | 78 + .../config/internal/ListPrivilegesImpl.java | 70 + .../config/internal/ListPropertiesImpl.java | 78 + .../strategy/enterprise/ListEnterprises.java | 37 + .../ListVirtualMachineTemplates.java | 39 + .../internal/ListEnterprisesImpl.java | 70 + .../ListVirtualMachineTemplatesImpl.java | 114 + .../abiquo/strategy/event/ListEvents.java | 38 + .../event/internal/ListEventsImpl.java | 69 + .../infrastructure/ListDatacenters.java | 39 + .../strategy/infrastructure/ListMachines.java | 37 + .../internal/ListDatacentersImpl.java | 115 + .../internal/ListMachinesImpl.java | 133 + .../suppliers/GetCurrentEnterprise.java | 50 + .../abiquo/suppliers/GetCurrentUser.java | 57 + .../services/org.jclouds.apis.ApiMetadata | 1 + .../jclouds/abiquo/AbiquoApiMetadataTest.java | 54 + .../jclouds/abiquo/AbiquoDelegateApiTest.java | 95 + .../abiquo/binders/AppendToPathTest.java | 63 + .../BindLinkToPathAndAcceptHeaderTest.java | 61 + .../abiquo/binders/BindLinkToPathTest.java | 56 + .../abiquo/binders/BindToPathTest.java | 204 ++ .../cloud/BindHardDiskRefsToPayloadTest.java | 95 + .../binders/cloud/BindIpRefToPayloadTest.java | 78 + .../cloud/BindIpRefsToPayloadTest.java | 96 + .../cloud/BindMoveVolumeToPathTest.java | 84 + ...dNetworkConfigurationRefToPayloadTest.java | 158 ++ .../cloud/BindNetworkRefToPayloadTest.java | 74 + .../BindUnmanagedIpRefToPayloadTest.java | 79 + ...BindVirtualDatacenterRefToPayloadTest.java | 77 + .../cloud/BindVolumeRefsToPayloadTest.java | 95 + .../AppendMachineIdToPathTest.java | 68 + .../AppendRemoteServiceTypeToPathTest.java | 70 + .../BindSupportedDevicesLinkToPathTest.java | 96 + .../ucs/BindLogicServerParametersTest.java | 77 + .../ucs/BindOrganizationParametersTest.java | 77 + .../compute/AbiquoComputeServiceLiveTest.java | 140 ++ .../functions/DatacenterToLocationTest.java | 54 + .../VirtualMachineStateToNodeStateTest.java | 50 + .../VirtualMachineTemplateToHardwareTest.java | 173 ++ .../VirtualMachineTemplateToImageTest.java | 99 + .../VirtualMachineToNodeMetadataTest.java | 245 ++ .../options/AbiquoTemplateOptionsTest.java | 145 ++ .../abiquo/config/SchedulerModuleTest.java | 46 + .../domain/AbiquoVersionLiveApiTest.java | 61 + .../jclouds/abiquo/domain/AdminResources.java | 216 ++ .../jclouds/abiquo/domain/CloudResources.java | 529 ++++ .../abiquo/domain/ConfigResources.java | 182 ++ .../jclouds/abiquo/domain/DomainUtils.java | 66 + .../abiquo/domain/EnterpriseResources.java | 353 +++ .../domain/InfrastructureResources.java | 555 +++++ .../abiquo/domain/NetworkResources.java | 277 +++ .../abiquo/domain/PricingResources.java | 80 + .../abiquo/domain/TemplateResources.java | 178 ++ .../abiquo/domain/admin/RoleLiveApiTest.java | 112 + .../domain/cloud/HardDiskLiveApiTest.java | 62 + .../cloud/VirtualApplianceLiveApiTest.java | 108 + .../cloud/VirtualDatacenterLiveApiTest.java | 209 ++ .../cloud/VirtualMachineLiveApiTest.java | 142 ++ .../VirtualMachineNetworkingLiveApiTest.java | 241 ++ .../VirtualMachineStorageLiveApiTest.java | 159 ++ .../VirtualMachineTemplateLiveApiTest.java | 77 + .../domain/cloud/VolumeLiveApiTest.java | 145 ++ .../domain/config/CategoryLiveApiTest.java | 75 + .../domain/config/CurrencyLiveApiTest.java | 76 + .../domain/config/LicenseLiveApiTest.java | 55 + .../config/SystemPropertiesLiveApiTest.java | 54 + .../enterprise/EnterpriseLiveApiTest.java | 190 ++ .../EnterprisePropertiesLiveApiTest.java | 56 + .../TemplateDefinitionListLiveApiTest.java | 81 + .../domain/enterprise/UserLiveApiTest.java | 109 + .../abiquo/domain/event/EventLiveApiTest.java | 283 +++ .../infrastructure/BladeLiveUcsTest.java | 91 + .../infrastructure/DatacenterLiveApiTest.java | 90 + .../infrastructure/MachineLiveApiTest.java | 171 ++ .../ManagedRackLiveUcsTest.java | 123 + .../infrastructure/RackLiveApiTest.java | 74 + .../RemoteServiceLiveApiTest.java | 131 + .../StorageDeviceLiveApiTest.java | 85 + .../StoragePoolLiveApiTest.java | 103 + .../infrastructure/TierLiveApiTest.java | 67 + .../network/ExternalNetworkLiveApiTest.java | 186 ++ .../network/GenericNetworkLiveApiTest.java | 93 + .../network/PrivateNetworkLiveApiTest.java | 187 ++ .../network/PublicNetworkLiveApiTest.java | 178 ++ .../network/UnmanagedNetworkLiveApiTest.java | 187 ++ .../environment/CloudTestEnvironment.java | 250 ++ .../InfrastructureTestEnvironment.java | 531 ++++ .../abiquo/environment/TestEnvironment.java | 40 + .../handlers/BlockingEventHandlerTest.java | 125 + .../abiquo/features/AdminAsyncApiTest.java | 196 ++ .../features/BaseAbiquoAsyncApiTest.java | 100 + .../abiquo/features/CloudAsyncApiTest.java | 1572 ++++++++++++ .../abiquo/features/ConfigAsyncApiTest.java | 317 +++ .../features/EnterpriseAsyncApiTest.java | 807 +++++++ .../abiquo/features/EventAsyncApiTest.java | 65 + .../abiquo/features/FeatureCoverageTest.java | 121 + .../features/InfrastructureAsyncApiTest.java | 2137 +++++++++++++++++ .../abiquo/features/PricingAsyncApiTest.java | 143 ++ .../abiquo/features/TaskAsyncApiTest.java | 145 ++ .../VirtualMachineTemplateAsyncApiTest.java | 304 +++ .../AppendApiVersionToAbiquoMimeTypeTest.java | 75 + ...urnAbiquoExceptionOnNotFoundOr4xxTest.java | 86 + .../ReturnFalseIfNotAvailableTest.java | 121 + .../functions/ReturnFalseOn5xxTest.java | 111 + .../abiquo/functions/ReturnNullOn303Test.java | 110 + .../ReturnTaskReferenceOrNullTest.java | 98 + .../cloud/ReturnMovedVolumeTest.java | 106 + .../enterprise/ParseEnterpriseIdTest.java | 66 + .../infrastructure/ParseDatacenterIdTest.java | 66 + .../infrastructure/ParseMachineIdTest.java | 66 + .../ParseRemoteServiceTypeTest.java | 56 + .../AbiquoAuthenticationLiveApiTest.java | 199 ++ .../filters/AbiquoAuthenticationTest.java | 99 + .../AppendApiVersionToMediaTypeTest.java | 310 +++ .../abiquo/internal/AsyncMonitorTest.java | 523 ++++ .../internal/BaseAbiquoApiLiveApiTest.java | 105 + .../internal/BaseAbiquoLiveApiTest.java | 72 + .../BaseAdministrationServiceTest.java | 51 + .../abiquo/internal/BaseCloudServiceTest.java | 45 + .../abiquo/internal/BaseEventServiceTest.java | 42 + .../abiquo/internal/BaseInjectionTest.java | 71 + .../internal/BaseMonitoringServiceTest.java | 260 ++ .../internal/BaseSearchServiceTest.java | 42 + .../functions/AsyncTaskStatusMonitorTest.java | 118 + .../ConversionStatusMonitorTest.java | 118 + .../VirtualApplianceDeployMonitorTest.java | 121 + .../VirtualApplianceUndeployMonitorTest.java | 121 + .../VirtualMachineDeployMonitorTest.java | 121 + .../VirtualMachineStateMonitorTest.java | 120 + .../VirtualMachineUndeployMonitorTest.java | 121 + .../internal/BaseAsyncTaskMonitorTest.java | 44 + .../BaseVirtualApplianceMonitorTest.java | 45 + .../BaseVirtualMachineMonitorTest.java | 45 + .../abiquo/reference/AbiquoTestConstants.java | 31 + .../internal/AbiquoHttpAsyncClientTest.java | 71 + .../BaseAbiquoStrategyLiveApiTest.java | 34 + .../internal/ListRolesImplLiveApiTest.java | 70 + .../ListAttachedNicsImplLiveApiTest.java | 114 + .../ListVirtualAppliancesImplLiveApiTest.java | 73 + ...ListVirtualDatacentersImplLiveApiTest.java | 93 + .../ListVirtualMachinesImplLiveApiTest.java | 109 + .../ListCategoriesImplLiveApiTest.java | 87 + .../internal/ListLicensesImplLiveApiTest.java | 90 + .../ListPrivilegesImplLiveApiTest.java | 86 + .../ListPropertiesImplLiveApiTest.java | 99 + .../ListEnterprisesImplLiveApiTest.java | 72 + ...irtualMachineTemplatesImplLiveApiTest.java | 77 + .../ListDatacentersImplLiveApiTest.java | 72 + .../internal/ListMachinesImplLiveApiTest.java | 71 + .../java/org/jclouds/abiquo/util/Assert.java | 77 + .../java/org/jclouds/abiquo/util/Config.java | 79 + .../src/test/resources/api-live.properties | 20 + .../test/resources/filters/filters.properties | 26 + .../filters/filters_jenkins.properties | 26 + .../abiquo/src/test/resources/license/expired | 1 + .../src/test/resources/logback-test.xml | 94 + labs/pom.xml | 1 + 405 files changed, 57123 insertions(+) create mode 100644 labs/abiquo/NOTICE create mode 100644 labs/abiquo/README.md create mode 100644 labs/abiquo/pom.xml create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/AppendToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeader.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindRefsToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToXMLPayloadAndPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayload.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/exception/NotEnoughResourcesException.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardware.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceHelper.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Volume.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/ConversionOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualApplianceOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualDatacenterOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineTemplateOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VolumeOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Category.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/License.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Privilege.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/SystemProperty.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/IconOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/LicenseOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/PropertyOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/EnterpriseProperties.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Limits.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionList.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateState.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/options/EnterpriseOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/RemoteService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceMetadata.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/DatacenterOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/IpmiOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/MachineOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/StoragePoolOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/AbstractPublicIp.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalIp.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalNetwork.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Ip.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Nic.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateIp.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateNetwork.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicIp.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicNetwork.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedIp.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedNetwork.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/IpOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/NetworkOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/FilterOptions.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/reference/OrderBy.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncJob.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/domain/util/LinkUtils.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApi.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/EventService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeType.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ParseErrors.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xx.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailable.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseOn5xx.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnMovedResource.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnNullOn303.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNull.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMoveVolumeReference.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolume.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseId.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterId.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineId.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceType.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/handlers/AbiquoErrorHandler.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaType.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseEventService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/AsyncTaskMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/reference/annotations/EnterpriseEdition.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClient.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpClient.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/ExtendedUtils.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/ListRoles.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCategories.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCurrencies.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListLicenses.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPrivileges.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListProperties.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCurrenciesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListEnterprises.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/ListEvents.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/internal/ListEventsImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListDatacenters.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImpl.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentEnterprise.java create mode 100644 labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentUser.java create mode 100644 labs/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardwareTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/ConfigResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/DomainUtils.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/EnterpriseResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/NetworkResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/TemplateResources.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/LicenseLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/SystemPropertiesLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterpriseLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterprisePropertiesLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/AdminAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/ConfigAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/EnterpriseAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/EventAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/FeatureCoverageTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/TaskAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeTypeTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xxTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailableTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseOn5xxTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnNullOn303Test.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNullTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolumeTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseIdTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterIdTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineIdTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceTypeTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaTypeTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAdministrationServiceTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseCloudServiceTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseEventServiceTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseInjectionTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseSearchServiceTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitorTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/reference/AbiquoTestConstants.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClientTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/BaseAbiquoStrategyLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImplLiveApiTest.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/util/Assert.java create mode 100644 labs/abiquo/src/test/java/org/jclouds/abiquo/util/Config.java create mode 100644 labs/abiquo/src/test/resources/api-live.properties create mode 100644 labs/abiquo/src/test/resources/filters/filters.properties create mode 100644 labs/abiquo/src/test/resources/filters/filters_jenkins.properties create mode 100644 labs/abiquo/src/test/resources/license/expired create mode 100644 labs/abiquo/src/test/resources/logback-test.xml diff --git a/labs/abiquo/NOTICE b/labs/abiquo/NOTICE new file mode 100644 index 0000000000..7e867501e1 --- /dev/null +++ b/labs/abiquo/NOTICE @@ -0,0 +1,25 @@ +==== + Licensed to jclouds, Inc. (jclouds) under one or more + contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. jclouds licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +==== + +jclouds +Copyright 2009-2011 jclouds, Inc. + +This product includes software developed at +Abiquo Holdings S.L. (http://www.abiquo.com/). +distributed under the GNU Lesser General Public License version 3 diff --git a/labs/abiquo/README.md b/labs/abiquo/README.md new file mode 100644 index 0000000000..bb545d52b6 --- /dev/null +++ b/labs/abiquo/README.md @@ -0,0 +1,21 @@ +Jclouds Abiquo Provider +======================= + +This is the jclouds Abiquo provider. It enables compute features for the Abiquo cloud platform. + +Documentation +------------- + +Detailed information about the Abiquo REST API can be found in the +[Abiquo documentation page](http://community.abiquo.com). + +All information about building and using the **jclouds-abiquo** provider in your own project +can be found in the [Project Wiki](https://github.com/abiquo/jclouds-abiquo/wiki). + + +Issue Tracking +-------------- + +If you find any issue in the provider api, please submit it to the [Bug tracking system](http://jira.abiquo.com/browse/ABIQUOJC) +and we will do our best to fix it. + diff --git a/labs/abiquo/pom.xml b/labs/abiquo/pom.xml new file mode 100644 index 0000000000..453f52fa22 --- /dev/null +++ b/labs/abiquo/pom.xml @@ -0,0 +1,331 @@ + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + + org.jclouds.labs + abiquo + jclouds Abiquo api + jclouds components to access an implementation of Abiquo + bundle + + + 2.1-SNAPSHOT + + + + + org.jclouds.abiquo*;version="${project.version}" + org.jclouds*;version="${project.version}",* + + + + + + abiquo-repo + Abiquo Maven Repository + http://repo.community.abiquo.com/repo + + + + + + org.jclouds + jclouds-core + ${project.version} + + + org.jclouds + jclouds-compute + ${project.version} + + + + com.abiquo + api-model-transport + ${abiquo.version} + + + javax.ws.rs + jsr311-api + + + org.uncommons + reportng + + + + + com.abiquo + am-model + ${abiquo.version} + + + javax.ws.rs + jsr311-api + + + org.uncommons + reportng + + + + + + org.apache.wink + wink-common + 1.1-incubating + + + org.slf4j + slf4j-jdk14 + + + javax.ws.rs + jsr311-api + + + javax.xml.stream + stax-api + + + + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds + jclouds-compute + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-jsch + ${project.version} + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + org.slf4j + slf4j-api + 1.6.1 + test + + + ch.qos.logback + logback-core + 1.0.0 + test + + + ch.qos.logback + logback-classic + 1.0.0 + test + + + + + + + + src/test/resources + true + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + **/*LiveTest.java + **/*LiveApiTest.java + **/*LiveUcsTest.java + + + + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.abiquo.idenfity} + ${test.abiquo.credential} + ${test.abiquo.api-version} + ${test.abiquo.build-version} + + + + + + + + + + api + + + src/test/resources/filters/filters.properties + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + 1 + + none + + + **/*LiveApiTest.java + + + ${test.abiquo.identity} + ${test.abiquo.credential} + ${test.abiquo.api-version} + ${test.abiquo.build-version} + + + + + + + + + + jenkins + + + src/test/resources/filters/filters_jenkins.properties + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + 1 + + none + + + **/*Live*.java + + + ${test.abiquo.idenfity} + ${test.abiquo.credential} + ${test.abiquo.api-version} + ${test.abiquo.build-version} + + + + + + + + + + + diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java new file mode 100644 index 0000000000..356274f307 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java @@ -0,0 +1,101 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.features.AdminApi; +import org.jclouds.abiquo.features.CloudApi; +import org.jclouds.abiquo.features.ConfigApi; +import org.jclouds.abiquo.features.EnterpriseApi; +import org.jclouds.abiquo.features.EventApi; +import org.jclouds.abiquo.features.InfrastructureApi; +import org.jclouds.abiquo.features.PricingApi; +import org.jclouds.abiquo.features.TaskApi; +import org.jclouds.abiquo.features.VirtualMachineTemplateApi; +import org.jclouds.concurrent.Timeout; +import org.jclouds.rest.annotations.Delegate; + +/** + * Provides synchronous access to Abiquo. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see AbiquoAsyncApi + * @author Ignasi Barrera + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface AbiquoApi +{ + /** + * Provides synchronous access to Admin features. + */ + @Delegate + AdminApi getAdminApi(); + + /** + * Provides synchronous access to Infrastructure features. + */ + @Delegate + InfrastructureApi getInfrastructureApi(); + + /** + * Provides synchronous access to Cloud features. + */ + @Delegate + CloudApi getCloudApi(); + + /** + * Provides synchronous access to Apps library features. + */ + @Delegate + VirtualMachineTemplateApi getVirtualMachineTemplateApi(); + + /** + * Provides synchronous access to Enterprise features. + */ + @Delegate + EnterpriseApi getEnterpriseApi(); + + /** + * Provides synchronous access to configuration features. + */ + @Delegate + ConfigApi getConfigApi(); + + /** + * Provides synchronous access to task asynchronous features. + */ + @Delegate + TaskApi getTaskApi(); + + /** + * Provides synchronous access to Event features. + */ + @Delegate + EventApi getEventApi(); + + /** + * Provides synchronous access to Pricing features. + */ + @Delegate + PricingApi getPricingApi(); + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java new file mode 100644 index 0000000000..ef1c5d5087 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java @@ -0,0 +1,124 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo; + +import static org.jclouds.Constants.PROPERTY_MAX_REDIRECTS; +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.reference.AbiquoConstants.CREDENTIAL_IS_TOKEN; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.abiquo.compute.config.AbiquoComputeServiceContextModule; +import org.jclouds.abiquo.config.AbiquoRestClientModule; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.concurrent.config.ScheduledExecutorServiceModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; + +import com.google.common.base.CharMatcher; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for Abiquo API. + * + * @author Ignasi Barrera + */ +public class AbiquoApiMetadata extends BaseRestApiMetadata +{ + /** Serial UID. */ + private static final long serialVersionUID = -8355533493674898171L; + + /** The token describing the rest api context. */ + public static final TypeToken> CONTEXT_TOKEN = + new TypeToken>() + { + private static final long serialVersionUID = -5070937833892503232L; + }; + + public AbiquoApiMetadata() + { + this(new Builder()); + } + + protected AbiquoApiMetadata(final Builder builder) + { + super(builder); + } + + public static Properties defaultProperties() + { + Properties properties = BaseRestApiMetadata.defaultProperties(); + // By default redirects will be handled in the domain objects + properties.setProperty(PROPERTY_MAX_REDIRECTS, "0"); + // The default polling delay between AsyncTask monitor requests + properties.setProperty(ASYNC_TASK_MONITOR_DELAY, "5000"); + // By default the provided credential is not a token + properties.setProperty(CREDENTIAL_IS_TOKEN, "false"); + return properties; + } + + @Override + public Builder toBuilder() + { + return new Builder().fromApiMetadata(this); + } + + public static class Builder extends BaseRestApiMetadata.Builder + { + private static final String DOCUMENTATION_ROOT = "http://community.abiquo.com/display/ABI" + + CharMatcher.DIGIT.retainFrom(AbiquoAsyncApi.API_VERSION); + + protected Builder() + { + super(AbiquoApi.class, AbiquoAsyncApi.class); + id("abiquo") + .name("Abiquo API") + .identityName("API Username") + .credentialName("API Password") + .documentation(URI.create(DOCUMENTATION_ROOT + "/API+Reference")) + .defaultEndpoint("http://localhost/api") + .version(AbiquoAsyncApi.API_VERSION) + .buildVersion(AbiquoAsyncApi.BUILD_VERSION) + .view(TypeToken.of(AbiquoContext.class)) + .defaultProperties(AbiquoApiMetadata.defaultProperties()) + .defaultModules( + ImmutableSet.> of(AbiquoRestClientModule.class, + AbiquoComputeServiceContextModule.class, + ScheduledExecutorServiceModule.class)); + } + + @Override + public AbiquoApiMetadata build() + { + return new AbiquoApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(final ApiMetadata in) + { + super.fromApiMetadata(in); + return this; + } + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoAsyncApi.java new file mode 100644 index 0000000000..c46e7a0db9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoAsyncApi.java @@ -0,0 +1,108 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo; + +import org.jclouds.abiquo.features.AdminAsyncApi; +import org.jclouds.abiquo.features.CloudAsyncApi; +import org.jclouds.abiquo.features.ConfigAsyncApi; +import org.jclouds.abiquo.features.EnterpriseAsyncApi; +import org.jclouds.abiquo.features.EventAsyncApi; +import org.jclouds.abiquo.features.InfrastructureAsyncApi; +import org.jclouds.abiquo.features.PricingAsyncApi; +import org.jclouds.abiquo.features.TaskAsyncApi; +import org.jclouds.abiquo.features.VirtualMachineTemplateAsyncApi; +import org.jclouds.rest.annotations.Delegate; + +import com.abiquo.model.transport.SingleResourceTransportDto; + +/** + * Provides asynchronous access to Abiquo via their REST API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see InfrastructureAsyncApi + * @author Ignasi Barrera + */ +public interface AbiquoAsyncApi +{ + /** + * The version of the supported Abiquo API. + */ + public static final String API_VERSION = SingleResourceTransportDto.API_VERSION; + + /** + * The supported build version of the Abiquo Api. + */ + public static final String BUILD_VERSION = "7bbfe95-158721b"; + + /** + * Provides asynchronous access to Admin features. + */ + @Delegate + AdminAsyncApi getAdminApi(); + + /** + * Provides asynchronous access to Infrastructure features. + */ + @Delegate + InfrastructureAsyncApi getInfrastructureApi(); + + /** + * Provides asynchronous access to Cloud features. + */ + @Delegate + CloudAsyncApi getCloudApi(); + + /** + * Provides asynchronous access to Apps library features. + */ + @Delegate + VirtualMachineTemplateAsyncApi getVirtualMachineTemplateApi(); + + /** + * Provides asynchronous access to Enterprise features. + */ + @Delegate + EnterpriseAsyncApi getEnterpriseApi(); + + /** + * Provides asynchronous access to configuration features. + */ + @Delegate + ConfigAsyncApi getConfigApi(); + + /** + * Provides asynchronous access to task asynchronous features. + */ + @Delegate + TaskAsyncApi getTaskApi(); + + /** + * Provides asynchronous access to Event features. + */ + @Delegate + EventAsyncApi getEventApi(); + + /** + * Provides asynchronous access to Pricing features. + */ + @Delegate + PricingAsyncApi getPricingApi(); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java new file mode 100644 index 0000000000..a390a7808a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo; + +import org.jclouds.abiquo.features.services.AdministrationService; +import org.jclouds.abiquo.features.services.CloudService; +import org.jclouds.abiquo.features.services.EventService; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.features.services.PricingService; +import org.jclouds.abiquo.features.services.SearchService; +import org.jclouds.abiquo.internal.AbiquoContextImpl; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.rest.RestContext; + +import com.google.inject.ImplementedBy; + +/** + * Abiquo {@link ComputeServiceContext} implementation to expose high level Abiquo functionalities. + * + * @author Ignasi Barrera + */ +@ImplementedBy(AbiquoContextImpl.class) +public interface AbiquoContext extends ComputeServiceContext +{ + /** + * Returns the Abiquo API context, providing direct access to the Abiquo Rest API. + * + * @return The Abiquo API context. + */ + RestContext getApiContext(); + + /** + * Returns the administration service. + *

+ * This service provides an entry point to infrastructure administration tasks. + */ + AdministrationService getAdministrationService(); + + /** + * Returns the cloud service. + *

+ * This service provides an entry point to cloud management tasks. + */ + CloudService getCloudService(); + + /** + * Returns the search service. + *

+ * This service provides an entry point to listing and filtering tasks. + */ + SearchService getSearchService(); + + /** + * Returns the monitoring service. + *

+ * This service provides an entry point to asynchronous task monitoring tasks. + */ + MonitoringService getMonitoringService(); + + /** + * Returns the event service. + *

+ * This service provides an entry point to event management tasks. + */ + EventService getEventService(); + + /** + * Returns the pricing service. + *

+ * This service provides an entry point to pricing management tasks. + */ + PricingService getPricingService(); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/AppendToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/AppendToPath.java new file mode 100644 index 0000000000..06ea947390 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/AppendToPath.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +/** + * Appends the parameter value to the end of the request URI. + * + * @author Ignasi Barrera + */ +@Singleton +public class AppendToPath implements Binder +{ + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(final R request, final Object input) + { + // Append the parameter to the request URI + String valueToAppend = getValue(request, checkNotNull(input, "input")); + URI path = URI.create(request.getEndpoint().toString() + "/" + valueToAppend); + return (R) request.toBuilder().endpoint(path).build(); + } + + /** + * Get the value that will be appended to the request URI. + */ + protected String getValue(final R request, final Object input) + { + return input.toString(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPath.java new file mode 100644 index 0000000000..f432d58e68 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPath.java @@ -0,0 +1,49 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.abiquo.model.rest.RESTLink; + +/** + * Binds the given link to the uri. + * + * @author Francesc Montserrat + */ +@Singleton +public class BindLinkToPath extends BindToPath +{ + + @Override + protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof RESTLink, + "this binder is only valid for RESTLink objects"); + + return ((RESTLink) input).getHref(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeader.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeader.java new file mode 100644 index 0000000000..6479403759 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeader.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.http.HttpRequest; + +import com.abiquo.model.rest.RESTLink; +import com.google.common.annotations.VisibleForTesting; + +/** + * Binds the given link to the uri and the Accept header. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindLinkToPathAndAcceptHeader extends BindLinkToPath +{ + @Override + public R bindToRequest(final R request, final Object input) + { + R updatedRequest = super.bindToRequest(request, input); + return addHeader(updatedRequest, HttpHeaders.ACCEPT, ((RESTLink) input).getType()); + } + + @SuppressWarnings("unchecked") + @VisibleForTesting + R addHeader(final R request, final String header, final String value) + { + return (R) request.toBuilder() + .replaceHeader(HttpHeaders.ACCEPT, checkNotNull(value, "value")).build(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindRefsToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindRefsToPayload.java new file mode 100644 index 0000000000..6a782e7e8e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindRefsToPayload.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.model.transport.SingleResourceTransportDto; + +/** + * Bind multiple objects to the payload of the request as a list of links. + * + * @author Ignasi Barrera + */ +public abstract class BindRefsToPayload extends BindToXMLPayload +{ + @Inject + public BindRefsToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + protected abstract String getRelToUse(final Object input); + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof SingleResourceTransportDto[], + "this binder is only valid for SingleResourceTransportDto arrays"); + + SingleResourceTransportDto[] dtos = (SingleResourceTransportDto[]) input; + LinksDto refs = new LinksDto(); + + for (SingleResourceTransportDto dto : dtos) + { + RESTLink editLink = checkNotNull(dto.getEditLink(), "entity must have an edit link"); + + // Do not add repeated references + if (refs.searchLinkByHref(editLink.getHref()) == null) + { + refs.addLink(new RESTLink(getRelToUse(input), editLink.getHref())); + } + } + + return super.bindToRequest(request, refs); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToPath.java new file mode 100644 index 0000000000..2b2732930f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToPath.java @@ -0,0 +1,159 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import java.lang.annotation.Annotation; +import java.net.URI; +import java.util.Arrays; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; +import org.jclouds.rest.binders.BindException; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; + +/** + * Binds the given object to the path.. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindToPath implements Binder +{ + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests"); + GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; + checkState(gRequest.getArgs() != null, "args should be initialized at this point"); + + // Update the request URI with the configured link URI + String newEndpoint = getNewEndpoint(gRequest, input); + return bindToPath(request, newEndpoint); + } + + /** + * Get the new endpoint to use. + * + * @param gRequest The request. + * @param input The input parameter. + * @return The new endpoint to use. + */ + protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) + { + SingleResourceTransportDto dto = checkValidInput(input); + return getLinkToUse(gRequest, dto).getHref(); + } + + /** + * Get the link to be used to build the request URI. + * + * @param request The current request. + * @param payload The object containing the link. + * @return The link to be used to build the request URI. + */ + static RESTLink getLinkToUse(final GeneratedHttpRequest request, + final SingleResourceTransportDto payload) + { + int argIndex = request.getArgs().indexOf(payload); + Annotation[] annotations = request.getJavaMethod().getParameterAnnotations()[argIndex]; + + EndpointLink linkName = + (EndpointLink) Iterables.find(Arrays.asList(annotations), + Predicates.instanceOf(EndpointLink.class), null); + + if (linkName == null) + { + throw new BindException(request, + "Expected a EndpointLink annotation but not found in the parameter"); + } + + return checkNotNull(payload.searchLink(linkName.value()), + "No link was found in object with rel: " + linkName); + } + + /** + * Bind the given link to the request URI. + * + * @param request The request to modify. + * @param endpoint The endpoint to use as the request URI. + * @return The updated request. + */ + @SuppressWarnings("unchecked") + static R bindToPath(final R request, final String endpoint) + { + // Preserve current query and matrix parameters + String newEndpoint = endpoint + getParameterString(request); + + // Replace the URI with the edit link in the DTO + URI path = URI.create(newEndpoint); + return (R) request.toBuilder().endpoint(path).build(); + } + + protected static SingleResourceTransportDto checkValidInput(final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof SingleResourceTransportDto, + "this binder is only valid for SingleResourceTransportDto objects"); + + return (SingleResourceTransportDto) input; + } + + protected static String getParameterString(final R request) + { + String endpoint = request.getEndpoint().toString(); + + int query = endpoint.indexOf('?'); + int matrix = endpoint.indexOf(';'); + + if (query == -1 && matrix == -1) + { + // No parameters + return ""; + } + else if (query != -1 && matrix != -1) + { + // Both parameter types + return endpoint.substring(query < matrix ? query : matrix); + } + else if (query != -1) + { + // Only request parameters + return endpoint.substring(query); + } + else + { + // Only matrix parameters + return endpoint.substring(matrix); + } + + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToXMLPayloadAndPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToXMLPayloadAndPath.java new file mode 100644 index 0000000000..8e133d93f3 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/BindToXMLPayloadAndPath.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.PUT; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.transport.SingleResourceTransportDto; + +/** + * Binds teh given object to the payload and extracts the path parameters from the edit link. + *

+ * This method should be used in {@link PUT} methods to automatically extract the path parameters + * from the edit link of the updated object. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindToXMLPayloadAndPath extends BindToXMLPayload +{ + @Inject + public BindToXMLPayloadAndPath(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object payload) + { + checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests"); + GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; + checkState(gRequest.getArgs() != null, "args should be initialized at this point"); + + // Update the request URI with the configured link URI + String newEndpoint = getNewEndpoint(gRequest, payload); + R updatedRequest = BindToPath.bindToPath(request, newEndpoint); + + // Add the payload + return super.bindToRequest(updatedRequest, payload); + } + + /** + * Get the new endpoint to use. + * + * @param gRequest The request. + * @param input The input parameter. + * @return The new endpoint to use. + */ + protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) + { + SingleResourceTransportDto dto = BindToPath.checkValidInput(input); + return BindToPath.getLinkToUse(gRequest, dto).getHref(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayload.java new file mode 100644 index 0000000000..f8595ec870 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayload.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.binders.BindRefsToPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; + +/** + * Bind multiple {@link DiskManagementDto} objects to the payload of the request as a list of links. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindHardDiskRefsToPayload extends BindRefsToPayload +{ + @Inject + public BindHardDiskRefsToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + protected String getRelToUse(final Object input) + { + return "disk"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayload.java new file mode 100644 index 0000000000..1ac67b6431 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayload.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.AbstractIpDto; + +/** + * Bind the link reference to an {@link AbstractIpDto} object into the payload. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindIpRefToPayload extends BindToXMLPayload +{ + @Inject + public BindIpRefToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof AbstractIpDto, + "this binder is only valid for AbstractIpDto objects"); + + AbstractIpDto ip = (AbstractIpDto) input; + RESTLink selfLink = + checkNotNull(ip.searchLink("self"), "AbstractIpDto must have an self link"); + + LinksDto refs = new LinksDto(); + refs.addLink(new RESTLink(selfLink.getTitle(), selfLink.getHref())); + + return super.bindToRequest(request, refs); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayload.java new file mode 100644 index 0000000000..8ee5b58721 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayload.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.util.LinkUtils; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.AbstractIpDto; + +/** + * Bind the link reference to an {@link AbstractIpDto} object into the payload. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindIpRefsToPayload extends BindToXMLPayload +{ + @Inject + public BindIpRefsToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof AbstractIpDto[], + "this binder is only valid for AbstractIpDto arrays"); + + AbstractIpDto[] ips = (AbstractIpDto[]) input; + LinksDto refs = new LinksDto(); + + for (AbstractIpDto ip : ips) + { + RESTLink selfLink = + checkNotNull(LinkUtils.getSelfLink(ip), + "AbstractIpDto must have an edit or self link"); + if (refs.searchLinkByHref(selfLink.getHref()) == null) + { + RESTLink ref = new RESTLink(selfLink.getTitle(), selfLink.getHref()); + ref.setType(selfLink.getType()); + refs.addLink(ref); + } + } + + return super.bindToRequest(request, refs); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPath.java new file mode 100644 index 0000000000..b99efce8ed --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPath.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Binds the move volume action to the request endpoint. + * + * @author Ignasi Barrera + */ +public class BindMoveVolumeToPath extends BindToPath +{ + + @Override + protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof VolumeManagementDto, + "this binder is only valid for VolumeManagementDto objects"); + + VolumeManagementDto volume = (VolumeManagementDto) input; + RESTLink editLink = + checkNotNull(volume.getEditLink(), "VolumeManagementDto must have an edit link"); + + return editLink.getHref() + "/action/move"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayload.java new file mode 100644 index 0000000000..6b8ca7fa3b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayload.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; + +/** + * Bind multiple objects to the payload of the request as a list of links. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindNetworkConfigurationRefToPayload extends BindToXMLPayload +{ + @Inject + public BindNetworkConfigurationRefToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests"); + checkArgument(checkNotNull(input, "input") instanceof VLANNetworkDto, + "this binder is only valid for VLANNetworkDto"); + GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; + checkState(gRequest.getArgs() != null, "args should be initialized at this point"); + + VLANNetworkDto network = (VLANNetworkDto) input; + VirtualMachineDto vm = + (VirtualMachineDto) Iterables.find(gRequest.getArgs(), + Predicates.instanceOf(VirtualMachineDto.class)); + + RESTLink configLink = + checkNotNull(vm.searchLink("configurations"), "missing required link"); + + LinksDto dto = new LinksDto(); + dto.addLink(new RESTLink("network_configuration", configLink.getHref() + "/" + + network.getId())); + + return super.bindToRequest(request, dto); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayload.java new file mode 100644 index 0000000000..261af82f2d --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayload.java @@ -0,0 +1,83 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Bind the link reference to an {@link VLANNetworkDto} object into the payload. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindNetworkRefToPayload extends BindToXMLPayload +{ + @Inject + public BindNetworkRefToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof VLANNetworkDto, + "this binder is only valid for VLANNetworkDto objects"); + + VLANNetworkDto network = (VLANNetworkDto) input; + RESTLink editLink = + checkNotNull(network.getEditLink(), "VLANNetworkDto must have an edit link"); + + LinksDto refs = new LinksDto(); + switch (network.getType()) + { + case INTERNAL: + refs.addLink(new RESTLink("internalnetwork", editLink.getHref())); + break; + case EXTERNAL: + refs.addLink(new RESTLink("externalnetwork", editLink.getHref())); + break; + case PUBLIC: + refs.addLink(new RESTLink("publicnetwork", editLink.getHref())); + break; + case UNMANAGED: + refs.addLink(new RESTLink("unmanagednetwork", editLink.getHref())); + break; + default: + // TODO: EXTERNAL_UNMANAGED network type + throw new IllegalArgumentException("Unsupported network type"); + } + + return super.bindToRequest(request, refs); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayload.java new file mode 100644 index 0000000000..cef4c84033 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayload.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.AbstractIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Bind the link reference to an {@link AbstractIpDto} object into the payload. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindUnmanagedIpRefToPayload extends BindToXMLPayload +{ + @Inject + public BindUnmanagedIpRefToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof VLANNetworkDto, + "this binder is only valid for VLANNetworkDto objects"); + + VLANNetworkDto network = (VLANNetworkDto) input; + checkArgument(network.getType() == NetworkType.UNMANAGED, + "this binder is only valid for UNMANAGED networks"); + + RESTLink ipsLink = + checkNotNull(network.searchLink("ips"), "VLANNetworkDto must have an ips link"); + + LinksDto refs = new LinksDto(); + refs.addLink(new RESTLink("unmanagedip", ipsLink.getHref())); + + return super.bindToRequest(request, refs); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayload.java new file mode 100644 index 0000000000..c6cb64b185 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayload.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Bind multiple {@link VolumeManagementDto} objects to the payload of the request as a list of + * links. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindVirtualDatacenterRefToPayload extends BindToXMLPayload +{ + @Inject + public BindVirtualDatacenterRefToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof VirtualDatacenterDto, + "this binder is only valid for VirtualDatacenterDto objects"); + + VirtualDatacenterDto vdc = (VirtualDatacenterDto) input; + RESTLink editLink = + checkNotNull(vdc.getEditLink(), "VirtualDatacenterDto must have an edit link"); + LinksDto refs = new LinksDto(); + refs.addLink(new RESTLink("virtualdatacenter", editLink.getHref())); + + return super.bindToRequest(request, refs); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayload.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayload.java new file mode 100644 index 0000000000..d71b3c7916 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayload.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.binders.BindRefsToPayload; +import org.jclouds.xml.XMLParser; + +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Bind multiple {@link VolumeManagementDto} objects to the payload of the request as a list of + * links. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindVolumeRefsToPayload extends BindRefsToPayload +{ + @Inject + public BindVolumeRefsToPayload(final XMLParser xmlParser) + { + super(xmlParser); + } + + @Override + protected String getRelToUse(final Object input) + { + return "volume"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java new file mode 100644 index 0000000000..56d796067f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.binders.AppendToPath; +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.functions.infrastructure.ParseMachineId; +import org.jclouds.http.HttpRequest; + +/** + * Append the {@link Machine} id to the request URI. + * + * @author Ignasi Barrera + */ +@Singleton +public class AppendMachineIdToPath extends AppendToPath +{ + private ParseMachineId parser; + + @Inject + public AppendMachineIdToPath(final ParseMachineId parser) + { + super(); + this.parser = parser; + } + + @Override + protected String getValue(final R request, final Object input) + { + return parser.apply(input); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java new file mode 100644 index 0000000000..4db84bec02 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.binders.AppendToPath; +import org.jclouds.abiquo.functions.infrastructure.ParseRemoteServiceType; +import org.jclouds.http.HttpRequest; + +/** + * Append the {@link RemoteServiceType} service to the request URI. + *

+ * This method assumes that the input object is a {@link RemoteServiceType} enumeration. + * + * @author Ignasi Barrera + */ +@Singleton +public class AppendRemoteServiceTypeToPath extends AppendToPath +{ + private ParseRemoteServiceType parser; + + @Inject + public AppendRemoteServiceTypeToPath(final ParseRemoteServiceType parser) + { + super(); + this.parser = parser; + } + + @Override + protected String getValue(final R request, final Object input) + { + return parser.apply(input); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java new file mode 100644 index 0000000000..6bf6d5f86d --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java @@ -0,0 +1,42 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +/** + * Binds the given link to the uri appends the supported devices action path. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindSupportedDevicesLinkToPath extends BindToPath +{ + + @Override + protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) + { + return super.getNewEndpoint(gRequest, input) + "/action/supported"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java new file mode 100644 index 0000000000..ef2072fc40 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure.ucs; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.abiquo.server.core.infrastructure.LogicServerDto; + +/** + * Binds logic server query parameters to request. This method assumes that the input object is a + * {@link LogicServerDto}. + * + * @author Francesc Montserrat + * @author Ignasi Barrera + */ +@Singleton +public class BindLogicServerParameters implements Binder +{ + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof LogicServerDto, + "this binder is only valid for LogicServerDto objects"); + + LogicServerDto server = (LogicServerDto) input; + + return (R) request.toBuilder().addQueryParam("lsName", server.getName()).build(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java new file mode 100644 index 0000000000..ddde0cddc0 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure.ucs; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.abiquo.server.core.infrastructure.OrganizationDto; + +/** + * Binds organization query parameters to request. This method assumes that the input object is a + * {@link OrganizationDto}. + * + * @author Francesc Montserrat + * @author Ignasi Barrera + */ +@Singleton +public class BindOrganizationParameters implements Binder +{ + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(final R request, final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof OrganizationDto, + "this binder is only valid for OrganizationDto objects"); + + OrganizationDto org = (OrganizationDto) input; + + return (R) request.toBuilder().addQueryParam("org", org.getDn()).build(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java new file mode 100644 index 0000000000..fc86f99409 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java @@ -0,0 +1,83 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.config; + +import org.jclouds.abiquo.compute.functions.DatacenterToLocation; +import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToHardware; +import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage; +import org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata; +import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions; +import org.jclouds.abiquo.compute.strategy.AbiquoComputeServiceAdapter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule.LocationsFromComputeServiceAdapterModule; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.domain.Location; +import org.jclouds.location.suppliers.ImplicitLocationSupplier; +import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; + +import com.google.common.base.Function; +import com.google.inject.Scopes; +import com.google.inject.TypeLiteral; + +/** + * Abiquo Compute service configuration module. + * + * @author Ignasi Barrera + */ +public class AbiquoComputeServiceContextModule + extends + ComputeServiceAdapterContextModule +{ + + @Override + protected void configure() + { + super.configure(); + bind( + new TypeLiteral>() + { + }).to(AbiquoComputeServiceAdapter.class); + bind(new TypeLiteral>() + { + }).to(VirtualMachineToNodeMetadata.class); + bind(new TypeLiteral>() + { + }).to(VirtualMachineTemplateToImage.class); + bind(new TypeLiteral>() + { + }).to(VirtualMachineTemplateToHardware.class); + bind(new TypeLiteral>() + { + }).to(DatacenterToLocation.class); + bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON); + bind(TemplateOptions.class).to(AbiquoTemplateOptions.class); + install(new LocationsFromComputeServiceAdapterModule() + { + }); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/exception/NotEnoughResourcesException.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/exception/NotEnoughResourcesException.java new file mode 100644 index 0000000000..0ffd63534a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/exception/NotEnoughResourcesException.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.exception; + +/** + * Exception thrown when there are not enough resources in the infrastructure to deploy the desired + * template. + * + * @author Ignasi Barrera + */ +public class NotEnoughResourcesException extends RuntimeException +{ + /** Serial UID. */ + private static final long serialVersionUID = 1L; + + public NotEnoughResourcesException() + { + super(); + } + + public NotEnoughResourcesException(final String arg0, final Throwable arg1) + { + super(arg0, arg1); + } + + public NotEnoughResourcesException(final String arg0) + { + super(arg0); + } + + public NotEnoughResourcesException(final Throwable arg0) + { + super(arg0); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java new file mode 100644 index 0000000000..e0039fa80b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * Converts a {@link Datacenter} to a {@link Location} one. + * + * @author Ignasi Barrera + */ +@Singleton +public class DatacenterToLocation implements Function +{ + + @Override + public Location apply(final Datacenter datacenter) + { + LocationBuilder builder = new LocationBuilder(); + builder.id(datacenter.getId().toString()); + builder.description(datacenter.getName() + " [" + datacenter.getLocation() + "]"); + builder.metadata(ImmutableMap. of()); + builder.scope(LocationScope.ZONE); + // TODO: Convert to ISO3166 code? + builder.iso3166Codes(ImmutableSet. of()); + + builder.parent(new LocationBuilder().scope(LocationScope.PROVIDER).id("abiquo") + .description("abiquo").build()); + + return builder.build(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java new file mode 100644 index 0000000000..806c6ef616 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata.Status; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Function; + +/** + * Converts a {@link VirtualMachineState} object to a {@link Status} one. + * + * @author Ignasi Barrera + */ +@Singleton +public class VirtualMachineStateToNodeState implements Function +{ + + @Override + public Status apply(final VirtualMachineState state) + { + switch (state) + { + case ALLOCATED: + case LOCKED: + case CONFIGURED: + return Status.PENDING; + case ON: + return Status.RUNNING; + case OFF: + case PAUSED: + return Status.SUSPENDED; + case NOT_ALLOCATED: + // TODO: What about nodes created but still not deployed? + return Status.TERMINATED; + case UNKNOWN: + default: + return Status.UNRECOGNIZED; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardware.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardware.java new file mode 100644 index 0000000000..f29f4479ff --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardware.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.compute.predicates.ImagePredicates; + +import com.google.common.base.Function; + +/** + * Transforms a {@link VirtualMachineTemplate} into an {@link Hardware}. + * + * @author Ignasi Barrera + */ +@Singleton +public class VirtualMachineTemplateToHardware implements Function +{ + /** The default core speed, 2.0Ghz. */ + public static final double DEFAULT_CORE_SPEED = 2.0; + + @Override + public Hardware apply(final VirtualMachineTemplate template) + { + HardwareBuilder builder = new HardwareBuilder(); + builder.ids(template.getId().toString()); + builder.uri(template.getURI()); + + builder.name(template.getName()); + builder.processor(new Processor(template.getCpuRequired(), DEFAULT_CORE_SPEED)); + builder.ram(template.getRamRequired()); + + // Currently we consider each template as a hardware profile + builder.supportsImage(ImagePredicates.idEquals(template.getId().toString())); + + VolumeBuilder volumeBuilder = new VolumeBuilder(); + volumeBuilder.bootDevice(true); + volumeBuilder.size(toGb(template.getHdRequired())); + volumeBuilder.type(Volume.Type.LOCAL); + volumeBuilder.durable(false); + builder.volume(volumeBuilder.build()); + + return builder.build(); + } + + private static float toGb(final long bytes) + { + return bytes / 1024 / 1024 / (float) 1024; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java new file mode 100644 index 0000000000..7e45e680af --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.Image.Status; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystem; + +import com.abiquo.model.rest.RESTLink; +import com.google.common.base.Function; + +/** + * Transforms a {@link VirtualMachineTemplate} into an {@link Image}. + * + * @author Ignasi Barrera + */ +@Singleton +public class VirtualMachineTemplateToImage implements Function +{ + + @Override + public Image apply(final VirtualMachineTemplate template) + { + ImageBuilder builder = new ImageBuilder(); + builder.ids(template.getId().toString()); + builder.name(template.getName()); + builder.description(template.getDescription()); + + // Only conversions have a status + builder.status(Status.AVAILABLE); + builder.backendStatus(Status.AVAILABLE.name()); // Abiquo images do not have a status + + RESTLink downloadLink = template.unwrap().searchLink("diskfile"); + builder.uri(downloadLink == null ? null : URI.create(downloadLink.getHref())); + + // TODO: Operating system not implemented in Abiquo Templates + builder.operatingSystem(OperatingSystem.builder().description(template.getName()).build()); + // TODO: image credentials + return builder.build(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java new file mode 100644 index 0000000000..b7cbe8cd8e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java @@ -0,0 +1,156 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; + +import java.util.List; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.logging.Logger; +import org.jclouds.rest.AuthorizationException; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Function; +import com.google.common.base.Predicates; + +/** + * Links a {@link VirtualMachine} object to a {@link NodeMetadata} one. + * + * @author Ignasi Barrera + */ +@Singleton +public class VirtualMachineToNodeMetadata implements Function +{ + @Resource + protected Logger logger = Logger.NULL; + + private final VirtualMachineTemplateToImage virtualMachineTemplateToImage; + + private final VirtualMachineTemplateToHardware virtualMachineTemplateToHardware; + + private final VirtualMachineStateToNodeState virtualMachineStateToNodeState; + + private final DatacenterToLocation datacenterToLocation; + + @Inject + public VirtualMachineToNodeMetadata( + final VirtualMachineTemplateToImage virtualMachineTemplateToImage, + final VirtualMachineTemplateToHardware virtualMachineTemplateToHardware, + final VirtualMachineStateToNodeState virtualMachineStateToNodeState, + final DatacenterToLocation datacenterToLocation) + { + this.virtualMachineTemplateToImage = + checkNotNull(virtualMachineTemplateToImage, "virtualMachineTemplateToImage"); + this.virtualMachineTemplateToHardware = + checkNotNull(virtualMachineTemplateToHardware, "virtualMachineTemplateToHardware"); + this.virtualMachineStateToNodeState = + checkNotNull(virtualMachineStateToNodeState, "virtualMachineStateToNodeState"); + this.datacenterToLocation = checkNotNull(datacenterToLocation, "datacenterToLocation"); + } + + @Override + public NodeMetadata apply(final VirtualMachine vm) + { + NodeMetadataBuilder builder = new NodeMetadataBuilder(); + builder.ids(vm.getId().toString()); + builder.uri(vm.getURI()); + builder.name(vm.getNameLabel()); + builder.group(vm.getVirtualAppliance().getName()); + + // TODO: builder.credentials() (http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647) + VirtualDatacenter vdc = vm.getVirtualDatacenter(); + + // Location details + try + { + Datacenter datacenter = vdc.getDatacenter(); + builder.location(datacenterToLocation.apply(datacenter)); + } + catch (AuthorizationException ex) + { + logger.debug("User does not have permissions to see the location of the node"); + } + + // Image details + VirtualMachineTemplate template = vm.getTemplate(); + Image image = virtualMachineTemplateToImage.apply(template); + builder.imageId(image.getId().toString()); + builder.operatingSystem(image.getOperatingSystem()); + + // Hardware details + Hardware defaultHardware = virtualMachineTemplateToHardware.apply(template); + Hardware hardware = + new HardwareBuilder() // + .ids(defaultHardware.getId()) // + .uri(defaultHardware.getUri()) // + .name(defaultHardware.getName()) // + .supportsImage(defaultHardware.supportsImage()) // + .ram(vm.getRam()) // + .hypervisor(vdc.getHypervisorType().name()) // + .processor( + new Processor(vm.getCpu(), VirtualMachineTemplateToHardware.DEFAULT_CORE_SPEED)) // + .build(); + builder.hardware(hardware); + + // Networking configuration + List> nics = vm.listAttachedNics(); + builder.privateAddresses(ips(filter(nics, Predicates.instanceOf(PrivateIp.class)))); + builder.publicAddresses(ips(filter(nics, + Predicates.not(Predicates.instanceOf(PrivateIp.class))))); + + // Node state + VirtualMachineState state = vm.getState(); + builder.status(virtualMachineStateToNodeState.apply(state)); + builder.backendStatus(state.name()); + + return builder.build(); + } + + private static Iterable ips(final Iterable> nics) + { + return transform(nics, new Function, String>() + { + @Override + public String apply(final Ip< ? , ? > nic) + { + return nic.getIp(); + } + }); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java new file mode 100644 index 0000000000..e003474c14 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java @@ -0,0 +1,257 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.options; + +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.Network; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.options.TemplateOptions; + +/** + * Contains options supported by the + * {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} and + * {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} operations on the + * Abiquo provider. + * + * @author Ignasi Barrera + */ +public class AbiquoTemplateOptions extends TemplateOptions implements Cloneable +{ + public static final AbiquoTemplateOptions NONE = new AbiquoTemplateOptions(); + + private Integer overrideCores; + + private Integer overrideRam; + + private String vncPassword; + + private String virtualDatacenter; + + private Ip< ? , ? >[] ips; + + private UnmanagedNetwork[] unmanagedIps; + + private Network< ? > gatewayNetwork; + + @Override + public TemplateOptions clone() + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + copyTo(options); + return options; + } + + @Override + public void copyTo(final TemplateOptions to) + { + super.copyTo(to); + if (to instanceof AbiquoTemplateOptions) + { + AbiquoTemplateOptions options = AbiquoTemplateOptions.class.cast(to); + options.overrideCores(overrideCores); + options.overrideRam(overrideRam); + options.vncPassword(vncPassword); + options.virtualDatacenter(virtualDatacenter); + options.ips(ips); + } + } + + /** + * Override the number of cores set by the hardware profile. + * + * @return The template options with the number of cores. + */ + public AbiquoTemplateOptions overrideCores(final Integer overrideCores) + { + this.overrideCores = overrideCores; + return this; + } + + public Integer getOverrideCores() + { + return overrideCores; + } + + /** + * Override the amount of ram set by the hardware profile. + * + * @return The template options with the amount of ram. + */ + public AbiquoTemplateOptions overrideRam(final Integer overrideRam) + { + this.overrideRam = overrideRam; + return this; + } + + public Integer getOverrideRam() + { + return overrideRam; + } + + /** + * Set the VNC password to access the virtual machine. + *

+ * By default virtual machines does not have VNC access password protected. + * + * @return The template options with the VNC password. + */ + public AbiquoTemplateOptions vncPassword(final String vncPassword) + { + this.vncPassword = vncPassword; + return this; + } + + public String getVncPassword() + { + return vncPassword; + } + + /** + * Set the virtual datacenter where the virtual machine must be deployed. + * + * @return The template options with the virtual machine must be deployed. + */ + public AbiquoTemplateOptions virtualDatacenter(final String virtualDatacenter) + { + this.virtualDatacenter = virtualDatacenter; + return this; + } + + public String getVirtualDatacenter() + { + return virtualDatacenter; + } + + /** + * Set the ip addresses for the virtual machine. + * + * @return The template options with the ip addresses configuration. + */ + public AbiquoTemplateOptions ips(final Ip< ? , ? >... ips) + { + this.ips = ips; + return this; + } + + public Ip< ? , ? >[] getIps() + { + return ips; + } + + /** + * Set the ip addresses that must be selected from unmanaged networks. + * + * @return The template options with the ip addresses that must be selected from unmanaged + * networks. + */ + public AbiquoTemplateOptions unmanagedIps(final UnmanagedNetwork... unmanagedIps) + { + this.unmanagedIps = unmanagedIps; + return this; + } + + public UnmanagedNetwork[] getUnmanagedIps() + { + return unmanagedIps; + } + + /** + * Set the gateway network for the virtual machine. + * + * @return The template options with the gateway network configuration. + */ + public AbiquoTemplateOptions gatewayNetwork(final Network< ? > gatewayNetwork) + { + this.gatewayNetwork = gatewayNetwork; + return this; + } + + public Network< ? > getGatewayNetwork() + { + return gatewayNetwork; + } + + public static class Builder + { + /** + * @see AbiquoTemplateOptions#overrideCores(int) + */ + public static AbiquoTemplateOptions overrideCores(final Integer overrideCores) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.overrideCores(overrideCores); + } + + /** + * @see AbiquoTemplateOptions#overrideRam(int) + */ + public static AbiquoTemplateOptions overrideRam(final Integer overrideRam) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.overrideRam(overrideRam); + } + + /** + * @see AbiquoTemplateOptions#vncPassword(String) + */ + public static AbiquoTemplateOptions vncPassword(final String vncPassword) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.vncPassword(vncPassword); + } + + /** + * @see AbiquoTemplateOptions#virtualDatacenter(String) + */ + public static AbiquoTemplateOptions virtualDatacenter(final String virtualDatacenter) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.virtualDatacenter(virtualDatacenter); + } + + /** + * @see AbiquoTemplateOptions#ips(Ip...) + */ + public static AbiquoTemplateOptions ips(final Ip< ? , ? >... ips) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.ips(ips); + } + + /** + * @see AbiquoTemplateOptions#unmanagedIps(UnmanagedNetwork...) + */ + public AbiquoTemplateOptions unmanagedIps(final UnmanagedNetwork... unmanagedIps) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.unmanagedIps(unmanagedIps); + } + + /** + * @see AbiquoTemplateOptions#gatewayNetwork(Network) + */ + public static AbiquoTemplateOptions gatewayNetwork(final Network< ? > gatewayNetwork) + { + AbiquoTemplateOptions options = new AbiquoTemplateOptions(); + return options.gatewayNetwork(gatewayNetwork); + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java new file mode 100644 index 0000000000..b8f0e5247e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java @@ -0,0 +1,251 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.features.services.AdministrationService; +import org.jclouds.abiquo.features.services.CloudService; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.VirtualMachineMonitor; +import org.jclouds.abiquo.predicates.cloud.VirtualAppliancePredicates; +import org.jclouds.abiquo.predicates.cloud.VirtualMachineTemplatePredicates; +import org.jclouds.abiquo.predicates.infrastructure.DatacenterPredicates; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Predicate; + +/** + * Defines the connection between the {@link AbiquoApi} implementation and the jclouds + * {@link ComputeService}. + * + * @author Ignasi Barrera + */ +@Singleton +public class AbiquoComputeServiceAdapter + implements + ComputeServiceAdapter +{ + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final RestContext context; + + private final AdministrationService adminService; + + private final CloudService cloudService; + + private final MonitoringService monitoringService; + + private AbiquoComputeServiceHelper helper; + + @Inject + public AbiquoComputeServiceAdapter(final RestContext context, + final AdministrationService adminService, final CloudService cloudService, + final MonitoringService monitoringService, final AbiquoComputeServiceHelper helper) + { + super(); + this.context = checkNotNull(context, "context"); + this.adminService = checkNotNull(adminService, "adminService"); + this.cloudService = checkNotNull(cloudService, "cloudService"); + this.monitoringService = checkNotNull(monitoringService, "monitoringService"); + this.helper = checkNotNull(helper, "helper"); + } + + @Override + public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName( + final String tag, final String name, final Template template) + { + AbiquoTemplateOptions options = template.getOptions().as(AbiquoTemplateOptions.class); + + User user = adminService.getCurrentUser(); + Enterprise enterprise = adminService.getCurrentEnterprise(); + + Datacenter datacenter = + enterprise.findAllowedDatacenter(DatacenterPredicates.id(Integer.valueOf(template + .getLocation().getId()))); + + VirtualMachineTemplate virtualMachineTemplate = + enterprise.getTemplateInRepository(datacenter, + Integer.valueOf(template.getImage().getId())); + + VirtualDatacenter vdc = + helper.getOrCreateVirtualDatacenter(user, enterprise, datacenter, + virtualMachineTemplate, options); + + // Load the virtual appliance or create it + VirtualAppliance vapp = vdc.findVirtualAppliance(VirtualAppliancePredicates.name(tag)); + if (vapp == null) + { + vapp = VirtualAppliance.builder(context, vdc).name(tag).build(); + vapp.save(); + } + + Integer overrideCores = options.getOverrideCores(); + Integer overrideRam = options.getOverrideRam(); + + VirtualMachine vm = VirtualMachine.builder(context, vapp, virtualMachineTemplate) // + .nameLabel(name) // + .cpu(overrideCores != null ? overrideCores : totalCores(template.getHardware())) // + .ram(overrideRam != null ? overrideRam : template.getHardware().getRam()) // + .password(options.getVncPassword()) // Can be null + .build(); + + vm.save(); + + // Once the virtual machine is created, override the default network settings if needed + helper.configureNetwork(vm, options.getGatewayNetwork(), options.getIps() == null ? null + : Arrays.asList(options.getIps()), + options.getUnmanagedIps() == null ? null : Arrays.asList(options.getUnmanagedIps())); + + VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); + vm.deploy(); + monitor.awaitCompletionDeploy(vm); + + return new NodeAndInitialCredentials(vm, vm.getId().toString(), template + .getImage().getDefaultCredentials()); + } + + @Override + public Iterable listHardwareProfiles() + { + // Abiquo does not have the hardwre profiles concept. Users can consume CPU and RAM + // resources limited only by the Enterprise or Virtual datacenter limits. + return listImages(); + } + + @Override + public Iterable listImages() + { + Enterprise enterprise = adminService.getCurrentEnterprise(); + return enterprise.listTemplates(); + } + + @Override + public VirtualMachineTemplate getImage(final String id) + { + Enterprise enterprise = adminService.getCurrentEnterprise(); + return enterprise.findTemplate(VirtualMachineTemplatePredicates.id(Integer.valueOf(id))); + } + + @Override + public Iterable listLocations() + { + Enterprise enterprise = adminService.getCurrentEnterprise(); + return enterprise.listAllowedDatacenters(); + } + + @Override + public VirtualMachine getNode(final String id) + { + // FIXME: Try to avoid calling the cloudService.findVirtualMachine. Navigate the hierarchy + // instead. + return cloudService.findVirtualMachine(vmId(id)); + } + + @Override + public void destroyNode(final String id) + { + VirtualMachine vm = getNode(id); + vm.delete(); + } + + @Override + public void rebootNode(final String id) + { + VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); + VirtualMachine vm = getNode(id); + vm.reboot(); + monitor.awaitState(VirtualMachineState.ON, vm); + } + + @Override + public void resumeNode(final String id) + { + VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); + VirtualMachine vm = getNode(id); + vm.changeState(VirtualMachineState.ON); + monitor.awaitState(VirtualMachineState.ON, vm); + } + + @Override + public void suspendNode(final String id) + { + VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); + VirtualMachine vm = getNode(id); + vm.changeState(VirtualMachineState.PAUSED); + monitor.awaitState(VirtualMachineState.PAUSED, vm); + } + + @Override + public Iterable listNodes() + { + return cloudService.listVirtualMachines(); + } + + private static Predicate vmId(final String id) + { + return new Predicate() + { + @Override + public boolean apply(final VirtualMachine input) + { + return Integer.valueOf(id).equals(input.getId()); + } + }; + } + + private static int totalCores(final Hardware hardware) + { + double cores = 0; + for (Processor processor : hardware.getProcessors()) + { + cores += processor.getCores(); + } + return Double.valueOf(cores).intValue(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceHelper.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceHelper.java new file mode 100644 index 0000000000..289b39c9e1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceHelper.java @@ -0,0 +1,256 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.getFirst; + +import java.util.List; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.compute.exception.NotEnoughResourcesException; +import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions; +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.Network; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.abiquo.features.services.CloudService; +import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.HypervisorType; +import com.google.common.base.Predicate; + +/** + * Helper methods to perform {@link AbiquoComputeServiceAdapter} operations. + * + * @author Ignasi Barrera + */ +@Singleton +public class AbiquoComputeServiceHelper +{ + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private RestContext context; + + private CloudService cloudService; + + @Inject + public AbiquoComputeServiceHelper(final RestContext context, + final CloudService cloudService) + { + super(); + this.context = checkNotNull(context, "context"); + this.cloudService = checkNotNull(cloudService, "cloudService"); + } + + /** + * Gets a virtual datacenter where the given template can be deployed. + *

+ * If no compatible virtual datacenter is found, one will be created, if possible. + * + * @param user The current user. + * @param enterprise The enterprise of the current user. + * @param datacenter The datacenter of the template. + * @param template The template to deploy. + * @param options The template options + * @return The virtual datacenter to be used to deploy the template or null if none + * was found and a compatible one could not be created. + */ + public VirtualDatacenter getOrCreateVirtualDatacenter(final User user, + final Enterprise enterprise, final Datacenter datacenter, + final VirtualMachineTemplate template, final AbiquoTemplateOptions options) + { + Iterable compatibles = + findCompatibleVirtualDatacenters(datacenter, template); + + VirtualDatacenter vdc = + options.getVirtualDatacenter() == null ? getFirst(compatibles, null) : find( + compatibles, VirtualDatacenterPredicates.name(options.getVirtualDatacenter())); + + if (vdc == null) + { + vdc = + createCompatibleVirtualDatacenter(user, enterprise, datacenter, template, + options.getVirtualDatacenter()); + if (vdc == null) + { + throw new NotEnoughResourcesException("There are not resources to deploy the given template"); + } + } + + return vdc; + } + + /** + * Find the virtual datacenters compatible with the given template. + * + * @param datacenter The datacenter of the template. + * @param template The template to deploy. + * @return The virtual datacenters compatible with the given template. + */ + public Iterable findCompatibleVirtualDatacenters( + final Datacenter datacenter, final VirtualMachineTemplate template) + { + Iterable vdcs = + cloudService.listVirtualDatacenters(VirtualDatacenterPredicates.datacenter(datacenter)); + + return filter(vdcs, new Predicate() + { + @Override + public boolean apply(final VirtualDatacenter vdc) + { + return isTemplateCompatibleWithHypervisor(template, vdc.getHypervisorType()); + } + }); + } + + /** + * Configure networking resources for the given virtual machine. + * + * @param vm The virtual machine to configure. + * @param gatewayNetwork The network to be used as a gateway. + * @param ips The ips to attach to the virtual machine. + */ + public void configureNetwork(final VirtualMachine vm, + @Nullable final Network< ? > gatewayNetwork, + @Nullable final List>> ips, + @Nullable final List unmanagedIps) + { + if (ips != null) + { + // TODO: External ips don't have the right link + // (http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3650) + + if (gatewayNetwork == null) + { + // By default the network of the first ip will be used as a gateway + vm.setNics(ips, unmanagedIps); + } + else + { + vm.setNics(gatewayNetwork, ips, unmanagedIps); + } + } + } + + /** + * Create a new virtual datacenter compatible with the given template. + * + * @param user The current user. + * @param enterprise The enterprise of the current user. + * @param datacenter The datacenter of the template. + * @param template The template to deploy. + * @return + */ + private VirtualDatacenter createCompatibleVirtualDatacenter(final User user, + final Enterprise enterprise, final Datacenter datacenter, + final VirtualMachineTemplate template, final String name) + { + PrivateNetwork defaultNetwork = + PrivateNetwork.builder(context).name("DefaultNetwork").gateway("192.168.1.1") + .address("192.168.1.0").mask(24).build(); + + VirtualDatacenter vdc = + VirtualDatacenter.builder(context, datacenter, enterprise).network(defaultNetwork) + .build(); + + // Find the first hypervisor in the datacenter compatible with the template + for (HypervisorType type : HypervisorType.values()) + { + if (isTemplateCompatibleWithHypervisor(template, type)) + { + try + { + logger.info("Trying to create a virtual datacenter of type %s", type.name()); + vdc.setName(name != null ? name : "JC-" + type.name()); + vdc.setHypervisorType(type); + vdc.save(); + + logger.info("Virtual datacenter created"); + + return vdc; + } + catch (AbiquoException ex) + { + // Just catch the error thrown when no hypervisors of the given type are + // available in the datacenter + if (ex.hasError("VDC-1")) + { + continue; + } + else + { + throw ex; + } + } + } + } + + logger.warn("Could not create a compatible virtual datacenter for template of type %s", + template.getDiskFormatType().name()); + + return null; + } + + /** + * Check if the given template type is compatible with the given hypervisor type. + * + * @param template The template to check. + * @param type The type of the hypervisor. + * @return Boolean indicating if the given template type is compatible with the given hypervisor + * type. + */ + private static boolean isTemplateCompatibleWithHypervisor( + final VirtualMachineTemplate template, final HypervisorType type) + { + boolean compatible = type.isCompatible(template.getDiskFormatType()); + if (!compatible) + { + List compatibleConversions = + template.listConversions(type, ConversionState.FINISHED); + compatible = compatibleConversions != null && !compatibleConversions.isEmpty(); + } + return compatible; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java new file mode 100644 index 0000000000..274a55c83e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java @@ -0,0 +1,154 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.config; + +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; + +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.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.features.AdminApi; +import org.jclouds.abiquo.features.AdminAsyncApi; +import org.jclouds.abiquo.features.CloudApi; +import org.jclouds.abiquo.features.CloudAsyncApi; +import org.jclouds.abiquo.features.ConfigApi; +import org.jclouds.abiquo.features.ConfigAsyncApi; +import org.jclouds.abiquo.features.EnterpriseApi; +import org.jclouds.abiquo.features.EnterpriseAsyncApi; +import org.jclouds.abiquo.features.EventApi; +import org.jclouds.abiquo.features.EventAsyncApi; +import org.jclouds.abiquo.features.InfrastructureApi; +import org.jclouds.abiquo.features.InfrastructureAsyncApi; +import org.jclouds.abiquo.features.PricingApi; +import org.jclouds.abiquo.features.PricingAsyncApi; +import org.jclouds.abiquo.features.TaskApi; +import org.jclouds.abiquo.features.TaskAsyncApi; +import org.jclouds.abiquo.features.VirtualMachineTemplateApi; +import org.jclouds.abiquo.features.VirtualMachineTemplateAsyncApi; +import org.jclouds.abiquo.handlers.AbiquoErrorHandler; +import org.jclouds.abiquo.rest.internal.AbiquoHttpAsyncClient; +import org.jclouds.abiquo.rest.internal.AbiquoHttpClient; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.abiquo.suppliers.GetCurrentEnterprise; +import org.jclouds.abiquo.suppliers.GetCurrentUser; +import org.jclouds.collect.Memoized; +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.rest.AuthorizationException; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.Utils; +import org.jclouds.rest.config.BinderUtils; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Provides; + +/** + * Configures the Abiquo connection. + * + * @author Ignasi Barrera + */ +@ConfiguresRestClient +public class AbiquoRestClientModule extends RestClientModule +{ + public static final Map, Class< ? >> DELEGATE_MAP = ImmutableMap + ., Class< ? >> builder() // + .put(InfrastructureApi.class, InfrastructureAsyncApi.class) // + .put(EnterpriseApi.class, EnterpriseAsyncApi.class) // + .put(AdminApi.class, AdminAsyncApi.class) // + .put(ConfigApi.class, ConfigAsyncApi.class) // + .put(CloudApi.class, CloudAsyncApi.class) // + .put(VirtualMachineTemplateApi.class, VirtualMachineTemplateAsyncApi.class) // + .put(TaskApi.class, TaskAsyncApi.class) // + .put(EventApi.class, EventAsyncApi.class).put(PricingApi.class, PricingAsyncApi.class) // + .build(); + + public AbiquoRestClientModule() + { + super(DELEGATE_MAP); + } + + @Override + protected void bindAsyncClient() + { + super.bindAsyncClient(); + BinderUtils.bindAsyncClient(binder(), AbiquoHttpAsyncClient.class); + } + + @Override + protected void bindClient() + { + super.bindClient(); + BinderUtils.bindClient(binder(), AbiquoHttpClient.class, AbiquoHttpAsyncClient.class, + ImmutableMap., Class< ? >> of(AbiquoHttpClient.class, + AbiquoHttpAsyncClient.class)); + } + + @Override + protected void configure() + { + super.configure(); + bind(Utils.class).to(ExtendedUtils.class); + } + + @Override + protected void bindErrorHandlers() + { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(AbiquoErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(AbiquoErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(AbiquoErrorHandler.class); + } + + @Provides + @Singleton + @Memoized + public Supplier getCurrentUser( + final AtomicReference authException, + @Named(PROPERTY_SESSION_INTERVAL) final long seconds, final GetCurrentUser getCurrentUser) + { + return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, + getCurrentUser, seconds, TimeUnit.SECONDS); + } + + @Provides + @Singleton + @Memoized + public Supplier getCurrentEnterprise( + final AtomicReference authException, + @Named(PROPERTY_SESSION_INTERVAL) final long seconds, + final GetCurrentEnterprise getCurrentEnterprise) + { + return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, + getCurrentEnterprise, seconds, TimeUnit.SECONDS); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java new file mode 100644 index 0000000000..6983299bf1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java @@ -0,0 +1,195 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + + + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.transport.SingleResourceWithLimitsDto; + +/** + * This class is used to decorate transport objects that have limits with high level functionality. + * + * @author Ignasi Barrera + */ +public abstract class DomainWithLimitsWrapper extends + DomainWrapper +{ + + protected DomainWithLimitsWrapper(final RestContext context, final T target) + { + super(context, target); + } + + // Delegate methods + + public int getCpuCountHardLimit() + { + return target.getCpuCountHardLimit(); + } + + public int getCpuCountSoftLimit() + { + return target.getCpuCountSoftLimit(); + } + + public long getHdHardLimitInMb() + { + return target.getHdHardLimitInMb(); + } + + public long getHdSoftLimitInMb() + { + return target.getHdSoftLimitInMb(); + } + + public long getPublicIpsHard() + { + return target.getPublicIpsHard(); + } + + public long getPublicIpsSoft() + { + return target.getPublicIpsSoft(); + } + + public int getRamHardLimitInMb() + { + return target.getRamHardLimitInMb(); + } + + public int getRamSoftLimitInMb() + { + return target.getRamSoftLimitInMb(); + } + + public long getStorageHard() + { + return target.getStorageHard(); + } + + public long getStorageSoft() + { + return target.getStorageSoft(); + } + + public long getVlansHard() + { + return target.getVlansHard(); + } + + public long getVlansSoft() + { + return target.getVlansSoft(); + } + + public void setCpuCountHardLimit(final int cpuCountHardLimit) + { + target.setCpuCountHardLimit(cpuCountHardLimit); + } + + public void setCpuCountLimits(final int softLimit, final int hardLimit) + { + target.setCpuCountLimits(softLimit, hardLimit); + } + + public void setCpuCountSoftLimit(final int cpuCountSoftLimit) + { + target.setCpuCountSoftLimit(cpuCountSoftLimit); + } + + public void setHdHardLimitInMb(final long hdHardLimitInMb) + { + target.setHdHardLimitInMb(hdHardLimitInMb); + } + + public void setHdLimitsInMb(final long softLimit, final long hardLimit) + { + target.setHdLimitsInMb(softLimit, hardLimit); + } + + public void setHdSoftLimitInMb(final long hdSoftLimitInMb) + { + target.setHdSoftLimitInMb(hdSoftLimitInMb); + } + + public void setPublicIPLimits(final long softLimit, final long hardLimit) + { + target.setPublicIPLimits(softLimit, hardLimit); + } + + public void setPublicIpsHard(final long publicIpsHard) + { + target.setPublicIpsHard(publicIpsHard); + } + + public void setPublicIpsSoft(final long publicIpsSoft) + { + target.setPublicIpsSoft(publicIpsSoft); + } + + public void setRamHardLimitInMb(final int ramHardLimitInMb) + { + target.setRamHardLimitInMb(ramHardLimitInMb); + } + + public void setRamLimitsInMb(final int softLimit, final int hardLimit) + { + target.setRamLimitsInMb(softLimit, hardLimit); + } + + public void setRamSoftLimitInMb(final int ramSoftLimitInMb) + { + target.setRamSoftLimitInMb(ramSoftLimitInMb); + } + + public void setStorageHard(final long storageHard) + { + target.setStorageHard(storageHard); + } + + public void setStorageLimits(final long softLimit, final long hardLimit) + { + target.setStorageLimits(softLimit, hardLimit); + } + + public void setStorageSoft(final long storageSoft) + { + target.setStorageSoft(storageSoft); + } + + public void setVlansHard(final long vlansHard) + { + target.setVlansHard(vlansHard); + } + + public void setVlansLimits(final long softLimit, final long hardLimit) + { + target.setVlansLimits(softLimit, hardLimit); + } + + public void setVlansSoft(final long vlansSoft) + { + target.setVlansSoft(vlansSoft); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java new file mode 100644 index 0000000000..0a599e6423 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java @@ -0,0 +1,83 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static com.google.common.collect.Iterables.filter; + +import java.util.Collections; +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.abiquo.server.core.task.TaskDto; +import com.abiquo.server.core.task.TasksDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; +import com.google.common.primitives.Longs; + +/** + * This class is used to decorate transport objects that are owners of some {@link TaskDto} + * + * @author Ignasi Barrera + */ +public abstract class DomainWithTasksWrapper extends + DomainWrapper +{ + + protected DomainWithTasksWrapper(final RestContext context, + final T target) + { + super(context, target); + } + + public List listTasks() + { + TasksDto result = context.getApi().getTaskApi().listTasks(target); + List tasks = wrap(context, AsyncTask.class, result.getCollection()); + + // Return the most recent task first + Collections.sort(tasks, new Ordering() + { + @Override + public int compare(final AsyncTask left, final AsyncTask right) + { + return Longs.compare(left.getTimestamp(), right.getTimestamp()); + } + }.reverse()); + + return tasks; + } + + public List listTasks(final Predicate filter) + { + return Lists.newLinkedList(filter(listTasks(), filter)); + } + + public AsyncTask findTask(final Predicate filter) + { + return Iterables.getFirst(filter(listTasks(), filter), null); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java new file mode 100644 index 0000000000..7ae35dc626 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java @@ -0,0 +1,241 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.transform; + +import java.lang.reflect.Constructor; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.exception.WrapperException; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.domain.util.LinkUtils; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.abiquo.model.transport.WrapperDto; +import com.abiquo.server.core.task.TaskDto; +import com.google.common.base.Function; +import com.google.common.collect.Lists; + +/** + * This class is used to decorate transport objects with high level functionality. + * + * @author Francesc Montserrat + * @author Ignasi Barrera + */ +public abstract class DomainWrapper +{ + /** The rest context. */ + protected RestContext context; + + /** The wrapped object. */ + protected T target; + + protected DomainWrapper(final RestContext context, + final T target) + { + super(); + this.context = checkNotNull(context, "context"); + this.target = checkNotNull(target, "target"); + } + + /** + * Returns the URI that identifies the transport object + * + * @return The URI identifying the transport object + */ + public URI getURI() + { + RESTLink link = LinkUtils.getSelfLink(target); + return link == null ? null : URI.create(link.getHref()); + } + + /** + * Returns the wrapped object. + */ + public T unwrap() + { + return target; + } + + /** + * Read the ID of the parent resource from the given link. + * + * @param parentLinkRel The link to the parent resource. + * @return The ID of the parent resource. + */ + protected Integer getParentId(final String parentLinkRel) + { + return target.getIdFromLink(parentLinkRel); + } + + /** + * Wraps an object in the given wrapper class. + */ + public static > W wrap( + final RestContext context, final Class wrapperClass, + final T target) + { + if (target == null) + { + return null; + } + + try + { + Constructor cons = + wrapperClass.getDeclaredConstructor(RestContext.class, target.getClass()); + if (!cons.isAccessible()) + { + cons.setAccessible(true); + } + return cons.newInstance(context, target); + } + catch (Exception ex) + { + throw new WrapperException(wrapperClass, target, ex); + } + } + + /** + * Wrap a collection of objects to the given wrapper class. + */ + public static > List wrap( + final RestContext context, final Class wrapperClass, + final Iterable targets) + { + if (targets == null) + { + return null; + } + + return Lists.newLinkedList(transform(targets, new Function() + { + @Override + public W apply(final T input) + { + return wrap(context, wrapperClass, input); + } + })); + } + + /** + * Unwrap a collection of objects. + */ + public static > List unwrap( + final Iterable targets) + { + return Lists.newLinkedList(transform(targets, new Function() + { + @Override + public T apply(final W input) + { + return input.unwrap(); + } + })); + } + + /** + * Update or creates a link of "target" with the uri of a link from "source". + */ + protected void updateLink( + final T1 target, final String targetLinkRel, final T2 source, final String sourceLinkRel) + { + RESTLink parent = null; + + checkNotNull(source.searchLink(sourceLinkRel), ValidationErrors.MISSING_REQUIRED_LINK); + + // Insert + if ((parent = target.searchLink(targetLinkRel)) == null) + { + target.addLink(new RESTLink(targetLinkRel, source.searchLink(sourceLinkRel).getHref())); + } + // Replace + else + { + parent.setHref(source.searchLink(sourceLinkRel).getHref()); + } + } + + /** + * Join a collection of {@link WrapperDto} objects in a single collection with all the elements + * of each wrapper object. + */ + public static Iterable join( + final Iterable< ? extends WrapperDto> collection) + { + List dtos = Lists.newLinkedList(); + for (WrapperDto wrapper : collection) + { + dtos.addAll(wrapper.getCollection()); + } + return dtos; + } + + /** + * Utility method to get an {@link AsyncTask} given an {@link AcceptedRequestDto}. + * + * @param acceptedRequest The accepted request dto. + * @return The async task. + */ + protected AsyncTask getTask(final AcceptedRequestDto acceptedRequest) + { + RESTLink taskLink = acceptedRequest.getStatusLink(); + checkNotNull(taskLink, ValidationErrors.MISSING_REQUIRED_LINK + AsyncTask.class); + + // This will return null on untrackable tasks + TaskDto task = context.getApi().getTaskApi().getTask(taskLink); + return wrap(context, AsyncTask.class, task); + } + + /** + * Utility method to get all {@link AsyncTask} related to an {@link AcceptedRequestDto}. + * + * @param acceptedRequest The accepted request dto. + * @return The async task array. + */ + protected AsyncTask[] getTasks(final AcceptedRequestDto acceptedRequest) + { + List tasks = new ArrayList(); + + for (RESTLink link : acceptedRequest.getLinks()) + { + // This will return null on untrackable tasks + TaskDto task = context.getApi().getTaskApi().getTask(link); + if (task != null) + { + tasks.add(wrap(context, AsyncTask.class, task)); + } + } + + AsyncTask[] taskArr = new AsyncTask[tasks.size()]; + return tasks.toArray(taskArr); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java new file mode 100644 index 0000000000..a3f045d57a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java @@ -0,0 +1,104 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.builder; + +/** + * Base class for all builders that represent limits. + * + * @author Ignasi Barrera + * @param The type of the target builder. + */ +public abstract class LimitsBuilder> +{ + /** The default limits for enterprises (unlimited). */ + protected static final int DEFAULT_LIMITS = 0; + + protected Integer ramSoftLimitInMb = DEFAULT_LIMITS; + + protected Integer ramHardLimitInMb = DEFAULT_LIMITS; + + protected Integer cpuCountSoftLimit = DEFAULT_LIMITS; + + protected Integer cpuCountHardLimit = DEFAULT_LIMITS; + + protected Long hdSoftLimitInMb = Long.valueOf(DEFAULT_LIMITS); + + protected Long hdHardLimitInMb = Long.valueOf(DEFAULT_LIMITS); + + protected Long storageSoft = Long.valueOf(DEFAULT_LIMITS); + + protected Long storageHard = Long.valueOf(DEFAULT_LIMITS); + + protected Long vlansSoft = Long.valueOf(DEFAULT_LIMITS); + + protected Long vlansHard = Long.valueOf(DEFAULT_LIMITS); + + protected Long publicIpsSoft = Long.valueOf(DEFAULT_LIMITS); + + protected Long publicIpsHard = Long.valueOf(DEFAULT_LIMITS); + + @SuppressWarnings("unchecked") + public T ramLimits(final int soft, final int hard) + { + this.ramSoftLimitInMb = soft; + this.ramHardLimitInMb = hard; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T cpuCountLimits(final int soft, final int hard) + { + this.cpuCountSoftLimit = soft; + this.cpuCountHardLimit = hard; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T hdLimitsInMb(final long soft, final long hard) + { + this.hdSoftLimitInMb = soft; + this.hdHardLimitInMb = hard; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T storageLimits(final long soft, final long hard) + { + this.storageSoft = soft; + this.storageHard = hard; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T vlansLimits(final long soft, final long hard) + { + this.vlansSoft = soft; + this.vlansHard = hard; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T publicIpsLimits(final long soft, final long hard) + { + this.publicIpsSoft = soft; + this.publicIpsHard = hard; + return (T) this; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java new file mode 100644 index 0000000000..1d8fbe3a7b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java @@ -0,0 +1,163 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Date; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWithTasksWrapper; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to {@link ConversionDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Conversion+Resource + */ +public class Conversion extends DomainWithTasksWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Conversion(final RestContext context, + final ConversionDto target) + { + super(context, target); + } + + // Domain methods + + public void refresh() + { + RESTLink link = + checkNotNull(target.searchLink("edit"), ValidationErrors.MISSING_REQUIRED_LINK + "edit"); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = checkNotNull(utils.getAbiquoHttpClient().get(link), "conversion"); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(ConversionDto.class)); + + target = parser.apply(response); + } + + // Parent access + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+Resource + */ + public VirtualMachineTemplate getVirtualMachineTemplate() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.VIRTUAL_MACHINE_TEMPLATE), + ValidationErrors.MISSING_REQUIRED_LINK + " " + + ParentLinkName.VIRTUAL_MACHINE_TEMPLATE); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VirtualMachineTemplateDto.class)); + + return wrap(context, VirtualMachineTemplate.class, parser.apply(response)); + } + + /** + * Starts a new BPM task to regenerate a failed conversion. + * + * @see API: http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource- + * UpdateConversion + * @return The task reference to track its progress + */ + public AsyncTask restartFailedConversion() + { + return getVirtualMachineTemplate().requestConversion(getTargetFormat()); + } + + // Delegate methods + + public String getSourcePath() + { + return target.getSourcePath(); + } + + public ConversionState getState() + { + return target.getState(); + } + + public String getTargetPath() + { + return target.getTargetPath(); + } + + public Long getTargetSizeInBytes() + { + return target.getTargetSizeInBytes(); + } + + public DiskFormatType getSourceFormat() + { + return target.getSourceFormat(); + } + + public DiskFormatType getTargetFormat() + { + return target.getTargetFormat(); + } + + public Date getStartTimestamp() + { + return target.getStartTimestamp(); + } + + @Override + public String toString() + { + return "Conversion [sourcePath=" + getSourcePath() + ", sourceFormat=" + getSourceFormat() + + ", targetPath=" + getTargetPath() + ", targetFormat=" + getTargetFormat() + + ", targetSizeInBytes=" + getTargetSizeInBytes() + ", startTimestamp=" + + getStartTimestamp() + ", state=" + getState() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java new file mode 100644 index 0000000000..7a4af28eb5 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java @@ -0,0 +1,181 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; + +/** + * Represents a disk attached to a virtual machine. + *

+ * This disks will be created when a virtual machine is deployed, and will be destroyed when it is + * undeployed. If there is a need to use persistent storage, a persistent {@link Volume} should be + * used instead. + * + * @author Ignasi Barrera + * @see API: + * http://community.abiquo.com/display/ABI20/Hard+Disks+Resource + */ +public class HardDisk extends DomainWrapper +{ + /** The virtual datacenter where the hard disk belongs. */ + private VirtualDatacenter virtualDatacenter; + + /** + * Constructor to be used only by the builder. + */ + protected HardDisk(final RestContext context, + final DiskManagementDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Creates the hard disk in the selected virtual datacenter. + *

+ * Once the hard disk has been created it can be attached to a virtual machine of the virtual + * datacenter. + */ + public void save() + { + target = context.getApi().getCloudApi().createHardDisk(virtualDatacenter.unwrap(), target); + } + + /** + * Deletes the hard disk. + */ + public void delete() + { + context.getApi().getCloudApi().deleteHardDisk(target); + target = null; + } + + // Parent access + + /** + * Gets the virtual datacenter where the hard disk belongs to. + * + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-RetrieveaVirtualDatacenter + */ + public VirtualDatacenter getVirtualDatacenter() + { + Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER); + VirtualDatacenterDto dto = + context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); + virtualDatacenter = wrap(context, VirtualDatacenter.class, dto); + return virtualDatacenter; + } + + // Builder + + public static Builder builder(final RestContext context, + final VirtualDatacenter virtualDatacenter) + { + return new Builder(context, virtualDatacenter); + } + + public static class Builder + { + private RestContext context; + + private Long sizeInMb; + + private VirtualDatacenter virtualDatacenter; + + public Builder(final RestContext context, + final VirtualDatacenter virtualDatacenter) + { + super(); + checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + + VirtualDatacenter.class); + this.context = context; + this.virtualDatacenter = virtualDatacenter; + } + + public Builder sizeInMb(final long sizeInMb) + { + this.sizeInMb = sizeInMb; + return this; + } + + public HardDisk build() + { + DiskManagementDto dto = new DiskManagementDto(); + dto.setSizeInMb(sizeInMb); + + HardDisk hardDisk = new HardDisk(context, dto); + hardDisk.virtualDatacenter = virtualDatacenter; + + return hardDisk; + } + } + + // Delegate methods. Since a hard disk cannot be edited, setters are not visible + + /** + * Returns the id of the hard disk. + */ + public Integer getId() + { + // TODO: DiskManagementDto does not have an id field + return target.getEditLink() == null ? null : target.getIdFromLink("edit"); + } + + /** + * Returns the size of the hard disk in MB. + */ + public Long getSizeInMb() + { + return target.getSizeInMb(); + } + + /** + * Returns the sequence number of the hard disk. + *

+ * It will be computed when attaching the hard disk to a virtual machine and will determine the + * attachment order of the disk in the virtual machine. + */ + public Integer getSequence() + { + return target.getSequence(); + } + + @Override + public String toString() + { + return "HardDisk [id=" + getId() + ", sizeInMb=" + getSizeInMb() + ", sequence=" + + getSequence() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java new file mode 100644 index 0000000000..71ebcd1502 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java @@ -0,0 +1,403 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceState; +import com.abiquo.server.core.cloud.VirtualApplianceStateDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualMachineTaskDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Represents a virtual appliance. + *

+ * A virtual appliance is a logic container for virtual machines that together make an appliance. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource + */ +public class VirtualAppliance extends DomainWrapper +{ + /** The virtual datacenter where the virtual appliance belongs. */ + private VirtualDatacenter virtualDatacenter; + + /** + * Constructor to be used only by the builder. + */ + protected VirtualAppliance(final RestContext context, + final VirtualApplianceDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Deletes the virtual appliance. + */ + public void delete() + { + context.getApi().getCloudApi().deleteVirtualAppliance(target); + target = null; + } + + /** + * Creates the virtual appliance in the selected virtual datacenter. + */ + public void save() + { + target = + context.getApi().getCloudApi() + .createVirtualAppliance(virtualDatacenter.unwrap(), target); + } + + /** + * Updates the virtual appliance information when some of its properties have changed. + */ + public void update() + { + target = context.getApi().getCloudApi().updateVirtualAppliance(target); + } + + // Parent access + + /** + * Gets the virtual datacenter where the virtual appliance belongs to. + * + * @resturn The virtual datacenter where the virtual appliance belongs to. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-RetrieveaVirtualDatacenter + */ + public VirtualDatacenter getVirtualDatacenter() + { + Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER); + VirtualDatacenterDto dto = + context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); + virtualDatacenter = wrap(context, VirtualDatacenter.class, dto); + return virtualDatacenter; + } + + /** + * Gets the enterprise where the virtual appliance belongs to. + * + * @return The enterprise where the virtual appliance belongs to. + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * RetrieveaEnterprise + */ + public Enterprise getEnterprise() + { + Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); + EnterpriseDto dto = context.getApi().getEnterpriseApi().getEnterprise(enterpriseId); + return wrap(context, Enterprise.class, dto); + } + + /** + * Gets the current state of the virtual appliance. + * + * @return The current state of the virtual appliance. + */ + public VirtualApplianceState getState() + { + VirtualApplianceStateDto stateDto = + context.getApi().getCloudApi().getVirtualApplianceState(target); + return stateDto.getPower(); + } + + // Children access + + /** + * Gets the list of virtual machines in the virtual appliance. + * + * @return The list of virtual machines in the virtual appliance. + * @see API: + * http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#VirtualMachineResource + * -RetrievethelistofVirtualMachines. + */ + public List listVirtualMachines() + { + return listVirtualMachines(VirtualMachineOptions.builder().disablePagination().build()); + } + + /** + * Gets the list of virtual machines in the virtual appliance. + * + * @return The list of virtual machines in the virtual appliance. + * @see API: + * http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#VirtualMachineResource + * -RetrievethelistofVirtualMachines. + */ + public List listVirtualMachines(final VirtualMachineOptions options) + { + VirtualMachinesWithNodeExtendedDto vms = + context.getApi().getCloudApi().listVirtualMachines(target, options); + return wrap(context, VirtualMachine.class, vms.getCollection()); + } + + /** + * Gets the list of virtual machines in the virtual appliance matching the given filter. + * + * @param filter The filter to apply. + * @return The list of virtual machines in the virtual appliance matching the given filter. + */ + public List listVirtualMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualMachines(), filter)); + } + + /** + * Gets a single virtual machine in the virtual appliance matching the given filter. + * + * @param filter The filter to apply. + * @return The virtual machine or null if none matched the given filter. + */ + public VirtualMachine findVirtualMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualMachines(), filter), null); + } + + /** + * Gets a concrete virtual machine in the virtual appliance. + * + * @param id The id of the virtual machine. + * @return The requested virtual machine. + */ + public VirtualMachine getVirtualMachine(final Integer id) + { + VirtualMachineWithNodeExtendedDto vm = + context.getApi().getCloudApi().getVirtualMachine(target, id); + return wrap(context, VirtualMachine.class, vm); + } + + // Actions + + /** + * Deploys the virtual appliance. + *

+ * This method will start the deployment of all the virtual machines in the virtual appliance, + * and will return an {@link AsyncTask} reference for each deployment operation. The deployment + * will finish when all individual tasks finish. + * + * @return The list of tasks corresponding to the deploy process of each virtual machine in the + * appliance. + */ + public AsyncTask[] deploy() + { + return deploy(false); + } + + /** + * Deploys the virtual appliance. + *

+ * This method will start the deployment of all the virtual machines in the virtual appliance, + * and will return an {@link AsyncTask} reference for each deploy operation. The deployment will + * finish when all individual tasks finish. + * + * @param forceEnterpriseSoftLimits Boolean indicating if the deployment must be executed even + * if the enterprise soft limits are reached. + * @return The list of tasks corresponding to the deploy process of each virtual machine in the + * appliance. + */ + public AsyncTask[] deploy(final boolean forceEnterpriseSoftLimits) + { + VirtualMachineTaskDto force = new VirtualMachineTaskDto(); + force.setForceEnterpriseSoftLimits(forceEnterpriseSoftLimits); + + AcceptedRequestDto response = + context.getApi().getCloudApi().deployVirtualAppliance(unwrap(), force); + + return getTasks(response); + } + + /** + * Undeploys the virtual appliance. + *

+ * This method will start the undeploy of all the virtual machines in the virtual appliance, and + * will return an {@link AsyncTask} reference for each undeploy operation. The undeploy will + * finish when all individual tasks finish. + * + * @return The list of tasks corresponding to the undeploy process of each virtual machine in + * the appliance. + */ + public AsyncTask[] undeploy() + { + return undeploy(false); + } + + /** + * Undeploys the virtual appliance. + *

+ * This method will start the undeploy of all the virtual machines in the virtual appliance, and + * will return an {@link AsyncTask} reference for each undeploy operation. The undeploy will + * finish when all individual tasks finish. + * + * @param forceUndeploy Boolean flag to force the undeploy even if the virtual appliance + * contains imported virtual machines. + * @return The list of tasks corresponding to the undeploy process of each virtual machine in + * the appliance. + */ + public AsyncTask[] undeploy(final boolean forceUndeploy) + { + VirtualMachineTaskDto force = new VirtualMachineTaskDto(); + force.setForceUndeploy(forceUndeploy); + + AcceptedRequestDto response = + context.getApi().getCloudApi().undeployVirtualAppliance(unwrap(), force); + + return getTasks(response); + } + + // Builder + + public static Builder builder(final RestContext context, + final VirtualDatacenter virtualDatacenter) + { + return new Builder(context, virtualDatacenter); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private VirtualDatacenter virtualDatacenter; + + public Builder(final RestContext context, + final VirtualDatacenter virtualDatacenter) + { + super(); + checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + + VirtualDatacenter.class); + this.virtualDatacenter = virtualDatacenter; + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder virtualDatacenter(final VirtualDatacenter virtualDatacenter) + { + checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + + VirtualDatacenter.class); + this.virtualDatacenter = virtualDatacenter; + return this; + } + + public VirtualAppliance build() + { + VirtualApplianceDto dto = new VirtualApplianceDto(); + dto.setName(name); + + VirtualAppliance virtualAppliance = new VirtualAppliance(context, dto); + virtualAppliance.virtualDatacenter = virtualDatacenter; + + return virtualAppliance; + } + + public static Builder fromVirtualAppliance(final VirtualAppliance in) + { + return VirtualAppliance.builder(in.context, in.virtualDatacenter).name(in.getName()); + } + } + + // Delegate methods + + public int getError() + { + return target.getError(); + } + + public int getHighDisponibility() + { + return target.getHighDisponibility(); + } + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public int getPublicApp() + { + return target.getPublicApp(); + } + + public void setHighDisponibility(final int highDisponibility) + { + target.setHighDisponibility(highDisponibility); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setPublicApp(final int publicApp) + { + target.setPublicApp(publicApp); + } + + @Override + public String toString() + { + return "VirtualAppliance [id=" + getId() + ", name=" + getName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java new file mode 100644 index 0000000000..b95c59112c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java @@ -0,0 +1,680 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWithLimitsWrapper; +import org.jclouds.abiquo.domain.builder.LimitsBuilder; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.domain.network.ExternalNetwork; +import org.jclouds.abiquo.domain.network.Network; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.predicates.infrastructure.DatacenterPredicates; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.enumerator.StatefulInclusion; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; +import com.abiquo.server.core.infrastructure.storage.DisksManagementDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Represents a virtual datacenter. + *

+ * Virtual datacenters expose a set of compute, storage and networking resources that can be + * consumed by the tenants. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource + */ +public class VirtualDatacenter extends DomainWithLimitsWrapper +{ + /** The enterprise where the rack belongs. */ + private Enterprise enterprise; + + /** The dataceter where the virtual datacenter will be deployed. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected VirtualDatacenter(final RestContext context, + final VirtualDatacenterDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the virtual datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-DeleteanexistingVirtualDatacenter + */ + public void delete() + { + context.getApi().getCloudApi().deleteVirtualDatacenter(target); + target = null; + } + + /** + * Creates the virtual datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-CreateanewVirtualDatacenter + */ + public void save() + { + target = + context.getApi().getCloudApi() + .createVirtualDatacenter(target, datacenter.unwrap(), enterprise.unwrap()); + } + + /** + * Updates the virtual datacenter information when some of its properties have changed. + * + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-UpdatesanexistingVirtualDatacenter + */ + public void update() + { + target = context.getApi().getCloudApi().updateVirtualDatacenter(target); + } + + // Parent access + + /** + * Gets the datacenter where this virtual datacenter is assigned. + * + * @return The datacenter where this virtual datacenter is assigned. + * @see API: http://community.abiquo.com/display/ABI20/Datacenter+Resource#DatacenterResource- + * RetrieveaDatacenter + */ + public Datacenter getDatacenter() + { + Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + datacenter = getEnterprise().findAllowedDatacenter(DatacenterPredicates.id(datacenterId)); + return datacenter; + } + + /** + * Gets the enterprise that owns this virtual datacenter. + * + * @return The enterprise that owns this virtual datacenter. + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * RetrieveanEnterprise + */ + public Enterprise getEnterprise() + { + Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); + enterprise = + wrap(context, Enterprise.class, + context.getApi().getEnterpriseApi().getEnterprise(enterpriseId)); + return enterprise; + } + + // Children access + + /** + * Lists all the virtual appliances in the virtual datacenter. + * + * @return The list of virtual appliances in the virtual datacenter. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource# + * VirtualApplianceResource-RetrievethelistofVirtualAppliances + */ + public List listVirtualAppliances() + { + VirtualAppliancesDto vapps = context.getApi().getCloudApi().listVirtualAppliances(target); + return wrap(context, VirtualAppliance.class, vapps.getCollection()); + } + + /** + * Lists all the virtual appliances in the virtual datacenter that match the given filter. + * + * @param filter The filter to apply. + * @return The list of virtual appliances in the virtual datacenter that match the given filter. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource# + * VirtualApplianceResource-RetrievethelistofVirtualAppliances + */ + public List listVirtualAppliances(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualAppliances(), filter)); + } + + /** + * Gets the first virtual appliance in the virtual datacenter that match the given filter. + * + * @param filter The filter to apply. + * @return the first virtual appliance in the virtual datacenter that match the given filter or + * null if none is found. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource# + * VirtualApplianceResource-RetrievethelistofVirtualAppliances + */ + public VirtualAppliance findVirtualAppliance(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualAppliances(), filter), null); + } + + /** + * Gets the virtual appliance with the given id in the current virtual datacenter. + * + * @param id The id of the virtual appliance to get. + * @return The virtual appliance. + */ + public VirtualAppliance getVirtualAppliance(final Integer id) + { + VirtualApplianceDto vapp = context.getApi().getCloudApi().getVirtualAppliance(target, id); + return wrap(context, VirtualAppliance.class, vapp); + } + + /** + * Lists the storage tiers that are available to the virtual datacenter. + * + * @return The list of storage tiers that are available to the virtual datacenter. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-Retrieveenabledtiers + */ + public List listStorageTiers() + { + TiersDto tiers = context.getApi().getCloudApi().listStorageTiers(target); + return wrap(context, Tier.class, tiers.getCollection()); + } + + /** + * Lists the storage tiers that are available to the virtual datacenter and match the given + * filter. + * + * @param filter The filter to apply. + * @return The list of storage tiers that are available to the virtual datacenter and match the + * given filter. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-Retrieveenabledtiers + */ + public List listStorageTiers(final Predicate filter) + { + return Lists.newLinkedList(filter(listStorageTiers(), filter)); + } + + /** + * Finds the first the storage tier that is available to the virtual datacenter and matches the + * given filter. + * + * @param filter The filter to apply. + * @return The first the storage tier that is available to the virtual datacenter and matches + * the given filter. + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-Retrieveenabledtiers + */ + public Tier findStorageTier(final Predicate filter) + { + return Iterables.getFirst(filter(listStorageTiers(), filter), null); + } + + /** + * Gets the storage tier with the given id from the current virtual datacenter. + * + * @param id The id of the storage tier. + * @return The sotrage tier. + */ + public Tier getStorageTier(final Integer id) + { + TierDto tier = context.getApi().getCloudApi().getStorageTier(target, id); + return wrap(context, Tier.class, tier); + } + + /** + * Lists all persistent volumes in the virtual datacenter. + * + * @return The list of all persistent volumes in the virtual datacenter. + * @see API: http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource- + * Retrievethelistofvolumes + */ + public List listVolumes() + { + VolumesManagementDto volumes = context.getApi().getCloudApi().listVolumes(target); + return wrap(context, Volume.class, volumes.getCollection()); + } + + /** + * Lists all persistent volumes in the virtual datacenter that match the given filter. + * + * @param filter The filter to apply. + * @return The list of all persistent volumes in the virtual datacenter that match the given + * filter. + * @see API: http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource- + * Retrievethelistofvolumes + */ + public List listVolumes(final Predicate filter) + { + return Lists.newLinkedList(filter(listVolumes(), filter)); + } + + /** + * Finds the first persistent volume in the virtual datacenter that matches the given filter. + * + * @param filter The filter to apply. + * @return The first persistent volumes in the virtual datacenter that matches the given filter. + * @see API: http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource- + * Retrievethelistofvolumes + */ + public Volume findVolume(final Predicate filter) + { + return Iterables.getFirst(filter(listVolumes(), filter), null); + } + + public Volume getVolume(final Integer id) + { + VolumeManagementDto volume = context.getApi().getCloudApi().getVolume(target, id); + return wrap(context, Volume.class, volume); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Hard+Disks+Resource#HardDisksResource- + * GetthelistofHardDisksofaVirtualDatacenter + */ + public List listHardDisks() + { + DisksManagementDto hardDisks = context.getApi().getCloudApi().listHardDisks(target); + return wrap(context, HardDisk.class, hardDisks.getCollection()); + } + + public List listHardDisks(final Predicate filter) + { + return Lists.newLinkedList(filter(listHardDisks(), filter)); + } + + public HardDisk findHardDisk(final Predicate filter) + { + return Iterables.getFirst(filter(listHardDisks(), filter), null); + } + + public HardDisk getHardDisk(final Integer id) + { + DiskManagementDto hardDisk = context.getApi().getCloudApi().getHardDisk(target, id); + return wrap(context, HardDisk.class, hardDisk); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-GetdefaultVLANusedbydefaultinVirtualDatacenter + */ + public Network< ? > getDefaultNetwork() + { + VLANNetworkDto network = context.getApi().getCloudApi().getDefaultNetwork(target); + return wrap(context, network.getType() == NetworkType.INTERNAL ? PrivateNetwork.class + : ExternalNetwork.class, network); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource + * -RetrievealistofPrivateNetworks + */ + public List listPrivateNetworks() + { + VLANNetworksDto networks = context.getApi().getCloudApi().listPrivateNetworks(target); + return wrap(context, PrivateNetwork.class, networks.getCollection()); + } + + public List listPrivateNetworks(final Predicate> filter) + { + return Lists.newLinkedList(filter(listPrivateNetworks(), filter)); + } + + public PrivateNetwork findPrivateNetwork(final Predicate> filter) + { + return Iterables.getFirst(filter(listPrivateNetworks(), filter), null); + } + + public PrivateNetwork getPrivateNetwork(final Integer id) + { + VLANNetworkDto network = context.getApi().getCloudApi().getPrivateNetwork(target, id); + return wrap(context, PrivateNetwork.class, network); + } + + /** + * TODO needs to be in the wiki + */ + public List listAvailableTemplates() + { + VirtualMachineTemplatesDto templates = + context.getApi().getCloudApi().listAvailableTemplates(target); + + return wrap(context, VirtualMachineTemplate.class, templates.getCollection()); + } + + public List listAvailableTemplates( + final VirtualMachineTemplateOptions options) + { + VirtualMachineTemplatesDto templates = + context.getApi().getCloudApi().listAvailableTemplates(target, options); + + return wrap(context, VirtualMachineTemplate.class, templates.getCollection()); + } + + public List listAvailableTempaltes( + final Predicate filter) + { + return Lists.newLinkedList(filter(listAvailableTemplates(), filter)); + } + + public VirtualMachineTemplate findAvailableTemplate( + final Predicate filter) + { + return Iterables.getFirst(filter(listAvailableTemplates(), filter), null); + } + + public VirtualMachineTemplate getAvailableTemplate(final Integer id) + { + VirtualMachineTemplatesDto templates = + context + .getApi() + .getCloudApi() + .listAvailableTemplates(target, + VirtualMachineTemplateOptions.builder().idTemplate(id).build()); + + return templates.getCollection().isEmpty() ? null : // + wrap(context, VirtualMachineTemplate.class, templates.getCollection().get(0)); + } + + public VirtualMachineTemplate getAvailablePersistentTemplate(final Integer id) + { + VirtualMachineTemplatesDto templates = + context + .getApi() + .getCloudApi() + .listAvailableTemplates( + target, + VirtualMachineTemplateOptions.builder().idTemplate(id) + .persistent(StatefulInclusion.ALL).build()); + + return templates.getCollection().isEmpty() ? null : // + wrap(context, VirtualMachineTemplate.class, templates.getCollection().get(0)); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-ListofPublicIPstopurchasebyVirtualDatacenter + */ + public List listAvailablePublicIps() + { + IpOptions options = IpOptions.builder().build(); + + PublicIpsDto ips = context.getApi().getCloudApi().listAvailablePublicIps(target, options); + + return wrap(context, PublicIp.class, ips.getCollection()); + } + + public List listAvailablePublicIps(final Predicate filter) + { + return Lists.newLinkedList(filter(listAvailablePublicIps(), filter)); + } + + public PublicIp findAvailablePublicIp(final Predicate filter) + { + return Iterables.getFirst(filter(listAvailablePublicIps(), filter), null); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-ListofpurchasedPublicIPsbyVirtualDatacenter + */ + public List listPurchasedPublicIps() + { + IpOptions options = IpOptions.builder().build(); + + PublicIpsDto ips = context.getApi().getCloudApi().listPurchasedPublicIps(target, options); + + return wrap(context, PublicIp.class, ips.getCollection()); + } + + public List listPurchasedPublicIps(final Predicate filter) + { + return Lists.newLinkedList(filter(listPurchasedPublicIps(), filter)); + } + + public PublicIp findPurchasedPublicIp(final Predicate filter) + { + return Iterables.getFirst(filter(listPurchasedPublicIps(), filter), null); + } + + public void purchasePublicIp(final PublicIp ip) + { + checkNotNull(ip.unwrap().searchLink("purchase"), ValidationErrors.MISSING_REQUIRED_LINK); + context.getApi().getCloudApi().purchasePublicIp(ip.unwrap()); + } + + public void releaseePublicIp(final PublicIp ip) + { + checkNotNull(ip.unwrap().searchLink("release"), ValidationErrors.MISSING_REQUIRED_LINK); + context.getApi().getCloudApi().releasePublicIp(ip.unwrap()); + } + + // Actions + + public void setDefaultNetwork(final Network< ? > network) + { + context.getApi().getCloudApi().setDefaultNetwork(target, network.unwrap()); + } + + // Builder + + public static Builder builder(final RestContext context, + final Datacenter datacenter, final Enterprise enterprise) + { + return new Builder(context, datacenter, enterprise); + } + + public static class Builder extends LimitsBuilder + { + private RestContext context; + + private String name; + + private HypervisorType hypervisorType; + + private Enterprise enterprise; + + private Datacenter datacenter; + + private PrivateNetwork network; + + public Builder(final RestContext context, + final Datacenter datacenter, final Enterprise enterprise) + { + super(); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + this.enterprise = enterprise; + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder hypervisorType(final HypervisorType hypervisorType) + { + this.hypervisorType = hypervisorType; + return this; + } + + public Builder datacenter(final Datacenter datacenter) + { + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + return this; + } + + public Builder enterprise(final Enterprise enterprise) + { + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + this.enterprise = enterprise; + return this; + } + + public Builder network(final PrivateNetwork network) + { + checkNotNull(network, ValidationErrors.NULL_RESOURCE + PrivateNetwork.class); + this.network = network; + return this; + } + + public VirtualDatacenter build() + { + VirtualDatacenterDto dto = new VirtualDatacenterDto(); + dto.setName(name); + dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb); + dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit); + dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb); + dto.setStorageLimits(storageSoft, storageHard); + dto.setVlansLimits(vlansSoft, vlansHard); + dto.setPublicIPLimits(publicIpsSoft, publicIpsHard); + dto.setName(name); + dto.setHypervisorType(hypervisorType); + dto.setVlan(network.unwrap()); + + VirtualDatacenter virtualDatacenter = new VirtualDatacenter(context, dto); + virtualDatacenter.datacenter = datacenter; + virtualDatacenter.enterprise = enterprise; + + return virtualDatacenter; + } + + public static Builder fromVirtualDatacenter(final VirtualDatacenter in) + { + return VirtualDatacenter.builder(in.context, in.datacenter, in.enterprise) + .name(in.getName()).ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb()) + .cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit()) + .hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb()) + .storageLimits(in.getStorageSoft(), in.getStorageHard()) + .vlansLimits(in.getVlansSoft(), in.getVlansHard()) + .publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard()) + .hypervisorType(in.getHypervisorType()); + } + } + + // Delegate methods + + public HypervisorType getHypervisorType() + { + return target.getHypervisorType(); + } + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public void setHypervisorType(final HypervisorType hypervisorType) + { + target.setHypervisorType(hypervisorType); + } + + public void setName(final String name) + { + target.setName(name); + } + + @Override + public String toString() + { + return "VirtualDatacenter [id=" + getId() + ", type=" + getHypervisorType() + ", name=" + + getName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java new file mode 100644 index 0000000000..e45d817f79 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java @@ -0,0 +1,1014 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.Arrays; +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWithTasksWrapper; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.Network; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.domain.util.LinkUtils; +import org.jclouds.abiquo.predicates.LinkPredicates; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.abiquo.strategy.cloud.ListAttachedNics; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.abiquo.server.core.cloud.VirtualMachineStateDto; +import com.abiquo.server.core.cloud.VirtualMachineTaskDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; +import com.abiquo.server.core.infrastructure.storage.DisksManagementDto; +import com.abiquo.server.core.infrastructure.storage.DvdManagementDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to {@link VirtualMachineWithNodeExtendedDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/VirtualMachineResource + */ +public class VirtualMachine extends DomainWithTasksWrapper +{ + /** The virtual appliance where the virtual machine belongs. */ + private VirtualAppliance virtualAppliance; + + /** The virtual machine template of the virtual machine. */ + private VirtualMachineTemplate template; + + /** + * Constructor to be used only by the builder. + */ + protected VirtualMachine(final RestContext context, + final VirtualMachineWithNodeExtendedDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the virtual machine. + * + * @see API: + * http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource + * -Deleteavirtualmachine + */ + public void delete() + { + context.getApi().getCloudApi().deleteVirtualMachine(target); + target = null; + } + + /** + * Create a new virtual machine in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineResource# + * VirtualMachineResource-Createavirtualmachine + */ + public void save() + { + checkNotNull(template, ValidationErrors.NULL_RESOURCE + VirtualMachineTemplate.class); + checkNotNull(template.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + VirtualMachineTemplate.class); + + this.updateLink(target, ParentLinkName.VIRTUAL_MACHINE_TEMPLATE, template.unwrap(), "edit"); + + target = + context.getApi().getCloudApi().createVirtualMachine(virtualAppliance.unwrap(), target); + } + + /** + * Update virtual machine information in the server with the data from this virtual machine. + * This is an asynchronous call. This method returns a + * {@link org.jclouds.abiquo.domain.task.AsyncTask} object that keeps track of the task + * completion. Please refer to the documentation for details. + * + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineResource# + * VirtualMachineResource-Modifyavirtualmachine + * @see github: + * https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example + * @return The task reference or null if the operation completed synchronously. + */ + public AsyncTask update() + { + AcceptedRequestDto taskRef = + context.getApi().getCloudApi().updateVirtualMachine(target); + return taskRef == null ? null : getTask(taskRef); + } + + /** + * Update virtual machine information in the server with the data from this virtual machine. + * This is an asynchronous call. This method returns a + * {@link org.jclouds.abiquo.domain.task.AsyncTask} object that keeps track of the task + * completion. Please refer to the documentation for details. + * + * @param force Force update. + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineResource# + * VirtualMachineResource-Modifyavirtualmachine + * @see github: + * https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example + * @return The task reference or null if the operation completed synchronously. + */ + public AsyncTask update(final boolean force) + { + AcceptedRequestDto taskRef = + context.getApi().getCloudApi() + .updateVirtualMachine(target, VirtualMachineOptions.builder().force(force).build()); + return taskRef == null ? null : getTask(taskRef); + } + + /** + * Change the state of the virtual machine. This is an asynchronous call. This method returns a + * {@link org.jclouds.abiquo.domain.task.AsyncTask} object that keeps track of the task + * completion. Please refer to the documentation for details. + * + * @param state The new state of the virtual machine. + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineResource# + * VirtualMachineResource-Changethestateofavirtualmachine + * @see github: + * https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example + * @return The task reference or null if the operation completed synchronously. + */ + public AsyncTask changeState(final VirtualMachineState state) + { + VirtualMachineStateDto dto = new VirtualMachineStateDto(); + dto.setState(state); + + AcceptedRequestDto taskRef = + context.getApi().getCloudApi().changeVirtualMachineState(target, dto); + + return getTask(taskRef); + } + + /** + * Retrieve the state of the virtual machine. + * + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineResource# + * VirtualMachineResource-Retrievethestateofthevirtualmachine + * @return Current state of the virtual machine. + */ + public VirtualMachineState getState() + { + VirtualMachineStateDto stateDto = + context.getApi().getCloudApi().getVirtualMachineState(target); + VirtualMachineState state = stateDto.getState(); + target.setState(state); + target.setIdState(state.id()); + return state; + } + + public void refresh() + { + RESTLink link = + checkNotNull(target.getEditLink(), ValidationErrors.MISSING_REQUIRED_LINK + " edit"); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VirtualMachineWithNodeExtendedDto.class)); + + target = parser.apply(response); + } + + // Parent access + + /** + * Retrieve the virtual appliance where this virtual machine is. + * + * @see API: http://community.abiquo.com/display/ABI20/VirtualApplianceResource# + * VirtualApplianceResource-Retrieveavirtualappliance + * @return The virtual appliance where this virtual machine is. + */ + public VirtualAppliance getVirtualAppliance() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.VIRTUAL_APPLIANCE), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.VIRTUAL_APPLIANCE); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VirtualApplianceDto.class)); + + return wrap(context, VirtualAppliance.class, parser.apply(response)); + } + + /** + * Retrieve the virtual datacenter where this virtual machine is. + * + * @see API: http://community.abiquo.com/display/ABI20/VirtualDatacenterResource# + * VirtualDatacenterResource-Retireveavirtualdatacenter + * @return The virtual datacenter where this virtual machine is. + */ + public VirtualDatacenter getVirtualDatacenter() + { + Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER); + VirtualDatacenterDto dto = + context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); + return wrap(context, VirtualDatacenter.class, dto); + } + + /** + * Retrieve the enterprise of this virtual machine. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrieveanEnterprise + * @return Enterprise of this virtual machine. + */ + public Enterprise getEnterprise() + { + Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); + EnterpriseDto dto = context.getApi().getEnterpriseApi().getEnterprise(enterpriseId); + return wrap(context, Enterprise.class, dto); + } + + /** + * Retrieve the template of this virtual machine. + * + * @return Template of this virtual machine. + */ + public VirtualMachineTemplate getTemplate() + { + VirtualMachineTemplateDto dto = + context.getApi().getCloudApi().getVirtualMachineTemplate(target); + return wrap(context, VirtualMachineTemplate.class, dto); + } + + // Children access + + public List listAttachedHardDisks() + { + refresh(); + DisksManagementDto hardDisks = context.getApi().getCloudApi().listAttachedHardDisks(target); + return wrap(context, HardDisk.class, hardDisks.getCollection()); + } + + public List listAttachedHardDisks(final Predicate filter) + { + return Lists.newLinkedList(filter(listAttachedHardDisks(), filter)); + } + + public HardDisk findAttachedHardDisk(final Predicate filter) + { + return Iterables.getFirst(filter(listAttachedHardDisks(), filter), null); + } + + public List listAttachedVolumes() + { + refresh(); + VolumesManagementDto volumes = context.getApi().getCloudApi().listAttachedVolumes(target); + return wrap(context, Volume.class, volumes.getCollection()); + } + + public List listAttachedVolumes(final Predicate filter) + { + return Lists.newLinkedList(filter(listAttachedVolumes(), filter)); + } + + public Volume findAttachedVolume(final Predicate filter) + { + return Iterables.getFirst(filter(listAttachedVolumes(), filter), null); + } + + public List> listAttachedNics() + { + // The strategy will refresh the vm. There is no need to do it here + ListAttachedNics strategy = + context.getUtils().getInjector().getInstance(ListAttachedNics.class); + return Lists.newLinkedList(strategy.execute(this)); + } + + public List> listAttachedNics(final Predicate> filter) + { + return Lists.newLinkedList(filter(listAttachedNics(), filter)); + } + + public Ip< ? , ? > findAttachedNic(final Predicate> filter) + { + return Iterables.getFirst(filter(listAttachedNics(), filter), null); + } + + // Actions + + public AsyncTask deploy() + { + return deploy(false); + } + + public AsyncTask deploy(final boolean forceEnterpriseSoftLimits) + { + VirtualMachineTaskDto force = new VirtualMachineTaskDto(); + force.setForceEnterpriseSoftLimits(forceEnterpriseSoftLimits); + + AcceptedRequestDto response = + context.getApi().getCloudApi().deployVirtualMachine(unwrap(), force); + + return getTask(response); + } + + public AsyncTask undeploy() + { + return undeploy(false); + } + + public AsyncTask undeploy(final boolean forceUndeploy) + { + VirtualMachineTaskDto force = new VirtualMachineTaskDto(); + force.setForceUndeploy(forceUndeploy); + + AcceptedRequestDto response = + context.getApi().getCloudApi().undeployVirtualMachine(unwrap(), force); + + return getTask(response); + } + + /** + * Reboot a virtual machine. This is an asynchronous call. This method returns a + * {@link org.jclouds.abiquo.domain.task.AsyncTask} object that keeps track of the task + * completion. Please refer to the documentation for details. + * + * @see API: http://community.abiquo.com/display/ABI20/Rack+Resource#/VirtualMachineResource# + * VirtualMachineResource-Resetavirtualmachine + * @see github: + * https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example + * @return The task reference or null if the operation completed synchronously. + */ + public AsyncTask reboot() + { + AcceptedRequestDto response = + context.getApi().getCloudApi().rebootVirtualMachine(unwrap()); + + return getTask(response); + } + + public AsyncTask attachHardDisks(final HardDisk... hardDisks) + { + List expected = listAttachedHardDisks(); + expected.addAll(Arrays.asList(hardDisks)); + + HardDisk[] disks = new HardDisk[expected.size()]; + return setHardDisks(expected.toArray(disks)); + } + + public AsyncTask detachAllHardDisks() + { + AcceptedRequestDto taskRef = + context.getApi().getCloudApi().detachAllHardDisks(target); + return taskRef == null ? null : getTask(taskRef); + } + + public AsyncTask detachHardDisks(final HardDisk... hardDisks) + { + List expected = listAttachedHardDisks(); + Iterables.removeIf(expected, hardDiskIdIn(hardDisks)); + + HardDisk[] disks = new HardDisk[expected.size()]; + return setHardDisks(expected.toArray(disks)); + } + + public AsyncTask setHardDisks(final HardDisk... hardDisks) + { + AcceptedRequestDto taskRef = + context.getApi().getCloudApi().replaceHardDisks(target, toHardDiskDto(hardDisks)); + return taskRef == null ? null : getTask(taskRef); + } + + public AsyncTask attachVolumes(final Volume... volumes) + { + List expected = listAttachedVolumes(); + expected.addAll(Arrays.asList(volumes)); + + Volume[] vols = new Volume[expected.size()]; + return setVolumes(true, expected.toArray(vols)); + } + + public AsyncTask detachAllVolumes() + { + AcceptedRequestDto taskRef = + context.getApi().getCloudApi().detachAllVolumes(target); + return taskRef == null ? null : getTask(taskRef); + } + + public AsyncTask detachVolumes(final Volume... volumes) + { + List expected = listAttachedVolumes(); + Iterables.removeIf(expected, volumeIdIn(volumes)); + + Volume[] vols = new Volume[expected.size()]; + return setVolumes(true, expected.toArray(vols)); + } + + public AsyncTask setVolumes(final Boolean forceSoftLimits, final Volume... volumes) + { + AcceptedRequestDto taskRef = + context + .getApi() + .getCloudApi() + .replaceVolumes(target, + VirtualMachineOptions.builder().force(forceSoftLimits).build(), + toVolumeDto(volumes)); + + return taskRef == null ? null : getTask(taskRef); + } + + public AsyncTask setVolumes(final Volume... volumes) + { + return setVolumes(true, volumes); + } + + public AsyncTask setNics(final List> ips) + { + // By default the network of the first ip will be used as a gateway + return setNics(ips != null && !ips.isEmpty() ? ips.get(0).getNetwork() : null, ips, null); + } + + public AsyncTask setNics(final List> ips, + final List unmanagetNetworks) + { + // By default the network of the first ip will be used as a gateway + Network< ? > gateway = null; + if (ips != null && !ips.isEmpty()) + { + gateway = ips.get(0).getNetwork(); + } + else if (unmanagetNetworks != null && !unmanagetNetworks.isEmpty()) + { + gateway = unmanagetNetworks.get(0); + } + + return setNics(gateway, ips, unmanagetNetworks); + } + + public AsyncTask setNics(final Network< ? > gatewayNetwork, final List> ips) + { + return setNics(gatewayNetwork, ips, null); + } + + public AsyncTask setNics(final Network< ? > gatewayNetwork, final List> ips, + final List unmanagetNetworks) + { + RESTLink configLink = + checkNotNull(target.searchLink(ParentLinkName.NETWORK_CONFIGURATIONS), + ValidationErrors.MISSING_REQUIRED_LINK + ParentLinkName.NETWORK_CONFIGURATIONS); + + // Remove the gateway configuration and the current nics + Iterables.removeIf( + target.getLinks(), + Predicates.or(LinkPredicates.isNic(), + LinkPredicates.rel(ParentLinkName.NETWORK_GATEWAY))); + + // Add the given nics in the appropriate order + int i = 0; + if (ips != null) + { + for (i = 0; i < ips.size(); i++) + { + RESTLink source = LinkUtils.getSelfLink(ips.get(i).unwrap()); + RESTLink link = new RESTLink("nic" + i, source.getHref()); + link.setType(ips.get(i).unwrap().getBaseMediaType()); + target.addLink(link); + } + } + + // Add unmanaged network references, if given + if (unmanagetNetworks != null) + { + for (UnmanagedNetwork unmanaged : unmanagetNetworks) + { + RESTLink source = + checkNotNull(unmanaged.unwrap().searchLink("ips"), + ValidationErrors.MISSING_REQUIRED_LINK + "ips"); + + RESTLink link = new RESTLink("nic" + i, source.getHref()); + link.setType(UnmanagedIpDto.BASE_MEDIA_TYPE); + target.addLink(link); + i++; + } + } + + // Set the new network configuration + if (gatewayNetwork != null) + { + target.addLink(new RESTLink(ParentLinkName.NETWORK_GATEWAY, configLink.getHref() + "/" + + gatewayNetwork.getId())); + } + + return update(true); + } + + // TODO: Get current gateway network + + public void setGatewayNetwork(final Network< ? > network) + { + context.getApi().getCloudApi().setGatewayNetwork(target, network.unwrap()); + refresh(); // First refresh the target and its links + } + + /** + * Checks if the virtual machine is persistent. + *

+ * Persistent virtual machines have the system disc in an external volume. This way, when the + * virtual machine is undeployed, the contents of the system disk remain in the storage device + * and the user can deploy the virtual machine again without losing the data in the system disk. + * + * @return Boolean indicating if the virtual machine is persistent. + */ + public boolean isPersistent() + { + return getTemplate().unwrap().searchLink("volume") != null; + } + + public boolean hasDvd() + { + return target.getDvd() != null; + } + + public void attachDvd() + { + DvdManagementDto dvd = new DvdManagementDto(); + RESTLink link = new RESTLink("image", ""); + dvd.addLink(link); + target.setDvd(dvd); + } + + public void detachDvd() + { + target.setDvd(null); + } + + // Builder + + public static Builder builder(final RestContext context, + final VirtualAppliance virtualAppliance, final VirtualMachineTemplate template) + { + return new Builder(context, virtualAppliance, template); + } + + public static class Builder + { + private final RestContext context; + + private VirtualAppliance virtualAppliance; + + private final VirtualMachineTemplate template; + + private String nameLabel; + + private String internalName; + + private String description; + + private Integer ram; + + private Integer cpu; + + private Integer vncPort; + + private String vncAddress; + + private Integer idState; + + private Integer idType; + + private String password; + + private String keymap; + + private String uuid; + + private boolean dvd; + + public Builder(final RestContext context, + final VirtualAppliance virtualAppliance, final VirtualMachineTemplate template) + { + super(); + checkNotNull(virtualAppliance, ValidationErrors.NULL_RESOURCE + VirtualAppliance.class); + this.virtualAppliance = virtualAppliance; + this.template = template; + this.context = context; + } + + public Builder nameLabel(final String nameLabel) + { + this.nameLabel = nameLabel; + return this; + } + + public Builder description(final String description) + { + this.description = description; + return this; + } + + public Builder ram(final int ram) + { + this.ram = ram; + return this; + } + + public Builder cpu(final int cpu) + { + this.cpu = cpu; + return this; + } + + public Builder password(final String password) + { + this.password = password; + return this; + } + + public Builder keymap(final String keymap) + { + this.keymap = keymap; + return this; + } + + public Builder dvd(final boolean dvd) + { + this.dvd = dvd; + return this; + } + + // This methods are used only to build a builder from an existing VirtualMachine but should + // never be used by the user. This fields are set automatically by Abiquo + + private Builder vncPort(final int vdrpPort) + { + this.vncPort = vdrpPort; + return this; + } + + private Builder vncAddress(final String vdrpIP) + { + this.vncAddress = vdrpIP; + return this; + } + + private Builder idState(final int idState) + { + this.idState = idState; + return this; + } + + private Builder idType(final int idType) + { + this.idType = idType; + return this; + } + + private Builder internalName(final String internalName) + { + this.internalName = internalName; + return this; + } + + public Builder virtualAppliance(final VirtualAppliance virtualAppliance) + { + checkNotNull(virtualAppliance, ValidationErrors.NULL_RESOURCE + VirtualAppliance.class); + this.virtualAppliance = virtualAppliance; + return this; + } + + public VirtualMachine build() + { + VirtualMachineWithNodeExtendedDto dto = new VirtualMachineWithNodeExtendedDto(); + dto.setNodeName(nameLabel); + dto.setDescription(description); + dto.setHdInBytes(template.getHdRequired()); + dto.setVdrpIP(vncAddress); + + if (cpu != null) + { + dto.setCpu(cpu); + } + + if (ram != null) + { + dto.setRam(ram); + } + + if (vncPort != null) + { + dto.setVdrpPort(vncPort); + } + + if (idState != null) + { + dto.setIdState(idState); + } + + if (idType != null) + { + dto.setIdType(idType); + } + + if (internalName != null) + { + dto.setName(internalName); + } + + dto.setPassword(password); + dto.setKeymap(keymap); + dto.setUuid(uuid); + + // DVD + if (dvd) + { + DvdManagementDto dvd = new DvdManagementDto(); + RESTLink link = new RESTLink("image", ""); + dvd.addLink(link); + dto.setDvd(dvd); + } + + VirtualMachine virtualMachine = new VirtualMachine(context, dto); + virtualMachine.virtualAppliance = virtualAppliance; + virtualMachine.template = template; + + return virtualMachine; + } + + public static Builder fromVirtualMachine(final VirtualMachine in) + { + return VirtualMachine.builder(in.context, in.virtualAppliance, in.template) + .internalName(in.getInternalName()).nameLabel(in.getNameLabel()) + .description(in.getDescription()).ram(in.getRam()).cpu(in.getCpu()) + .vncAddress(in.getVncAddress()).vncPort(in.getVncPort()).idState(in.getIdState()) + .idType(in.getIdType()).password(in.getPassword()).keymap(in.getKeymap()) + .dvd(in.hasDvd()); + } + } + + // Delegate methods + + public int getCpu() + { + return target.getCpu(); + } + + public String getDescription() + { + return target.getDescription(); + } + + // Read-only field. This value is computed from the size of the Template + public long getHdInBytes() + { + return target.getHdInBytes(); + } + + public Integer getId() + { + return target.getId(); + } + + public int getIdState() + { + return target.getIdState(); + } + + public int getIdType() + { + return target.getIdType(); + } + + public String getNameLabel() + { + return target.getNodeName(); + } + + public String getOwnerName() + { + return target.getUserName() + " " + target.getUserSurname(); + } + + public String getInternalName() + { + return target.getName(); + } + + public String getPassword() + { + return target.getPassword(); + } + + public int getRam() + { + return target.getRam(); + } + + public String getUuid() + { + return target.getUuid(); + } + + public String getVncAddress() + { + return target.getVdrpIP(); + } + + public int getVncPort() + { + return target.getVdrpPort(); + } + + public String getKeymap() + { + return target.getKeymap(); + } + + public void setCpu(final int cpu) + { + target.setCpu(cpu); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + public void setNameLabel(final String nameLabel) + { + target.setNodeName(nameLabel); + } + + public void setPassword(final String password) + { + target.setPassword(password); + } + + public void setRam(final int ram) + { + target.setRam(ram); + } + + public void setKeymap(final String keymap) + { + target.setKeymap(keymap); + } + + private static VolumeManagementDto[] toVolumeDto(final Volume... volumes) + { + checkNotNull(volumes, "must provide at least one volume"); + + VolumeManagementDto[] dtos = new VolumeManagementDto[volumes.length]; + for (int i = 0; i < volumes.length; i++) + { + dtos[i] = volumes[i].unwrap(); + } + + return dtos; + } + + private static DiskManagementDto[] toHardDiskDto(final HardDisk... hardDisks) + { + checkNotNull(hardDisks, "must provide at least one hard disk"); + + DiskManagementDto[] dtos = new DiskManagementDto[hardDisks.length]; + for (int i = 0; i < hardDisks.length; i++) + { + dtos[i] = hardDisks[i].unwrap(); + } + + return dtos; + } + + private static Predicate volumeIdIn(final Volume... volumes) + { + return new Predicate() + { + List ids = volumeIds(Arrays.asList(volumes)); + + @Override + public boolean apply(final Volume input) + { + return ids.contains(input.getId()); + } + }; + } + + private static Predicate hardDiskIdIn(final HardDisk... hardDisks) + { + return new Predicate() + { + List ids = hardDisksIds(Arrays.asList(hardDisks)); + + @Override + public boolean apply(final HardDisk input) + { + return ids.contains(input.getId()); + } + }; + } + + private static List volumeIds(final List volumes) + { + return Lists.transform(volumes, new Function() + { + @Override + public Integer apply(final Volume input) + { + return input.getId(); + } + }); + } + + private static List hardDisksIds(final List HardDisk) + { + return Lists.transform(HardDisk, new Function() + { + @Override + public Integer apply(final HardDisk input) + { + return input.getId(); + } + }); + } + + @Override + public String toString() + { + return "VirtualMachine [id=" + getId() + ", state=" + target.getState().name() + ", cpu=" + + getCpu() + ", description=" + getDescription() + ", hdInBytes=" + getHdInBytes() + + ", idType=" + getIdType() + ", nameLabel=" + getNameLabel() + ", internalName=" + + getInternalName() + ", password=" + getPassword() + ", ram=" + getRam() + ", uuid=" + + getUuid() + ", vncAddress=" + getVncAddress() + ", vncPort=" + getVncPort() + + ", keymap=" + getKeymap() + ", dvd=" + hasDvd() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java new file mode 100644 index 0000000000..d7df2d7043 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java @@ -0,0 +1,407 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.options.ConversionOptions; +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.appslibrary.CategoryDto; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.abiquo.server.core.appslibrary.ConversionsDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to {@link VirtualMachineTemplateDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+Resource + */ +public class VirtualMachineTemplate extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected VirtualMachineTemplate(final RestContext context, + final VirtualMachineTemplateDto target) + { + super(context, target); + } + + // Domain operations + + public void delete() + { + context.getApi().getVirtualMachineTemplateApi().deleteVirtualMachineTemplate(target); + target = null; + } + + public void update() + { + target = + context.getApi().getVirtualMachineTemplateApi().updateVirtualMachineTemplate(target); + } + + /** + * TODO + * + * @param vdc + * @param volume + * @param persistentTemplateName + * @param persistentVolumeName + * @return + */ + public AsyncTask makePersistent(final VirtualDatacenter vdc, final Volume volume, + final String persistentTemplateName) + { + RESTLink storageLink = volume.unwrap().getEditLink(); + storageLink.setRel("volume"); + return makePeristent(vdc, storageLink, persistentTemplateName, null); + } + + public AsyncTask makePersistent(final VirtualDatacenter vdc, final Tier tier, + final String persistentTemplateName, final String persistentVolumeName) + { + // infrastructure + RESTLink storageLink = tier.unwrap().getEditLink(); + if (storageLink == null) + { + // cloud + storageLink = tier.unwrap().searchLink("self"); + } + storageLink.setRel(ParentLinkName.TIER); + return makePeristent(vdc, storageLink, persistentTemplateName, persistentVolumeName); + } + + private AsyncTask makePeristent(final VirtualDatacenter vdc, final RESTLink storageLink, + final String persistentTemplateName, final String persistentVolumeName) + { + VirtualMachineTemplatePersistentDto persistentData = + new VirtualMachineTemplatePersistentDto(); + persistentData.setPersistentTemplateName(persistentTemplateName); + persistentData.setPersistentVolumeName(persistentVolumeName); + RESTLink vdcLink = + new RESTLink(ParentLinkName.VIRTUAL_DATACENTER, vdc.unwrap().getEditLink().getHref()); + RESTLink templateLink = + new RESTLink(ParentLinkName.VIRTUAL_MACHINE_TEMPLATE, target.getEditLink().getHref()); + + persistentData.addLink(vdcLink); + persistentData.addLink(storageLink); + persistentData.addLink(templateLink); + + // SCG: + // A simple user should not have permissions to obtain a datacenter repository, but at this + // point we have the datacenter repository and enterprise ids in the own target uri. So we + // can obtain the path where do the POST + // Assumption that to create a new object a user needs to get the parent object cannot be + // applied in this case + String editUri = getURI().getPath(); + Pattern p = Pattern.compile("\\d+"); + Matcher m = p.matcher(editUri); + m.find(); + Integer idEnt = new Integer(m.group()); + m.find(); + Integer idDcRepo = new Integer(m.group()); + + AcceptedRequestDto response = + context.getApi().getVirtualMachineTemplateApi() + .createPersistentVirtualMachineTemplate(idEnt, idDcRepo, persistentData); + + return getTask(response); + } + + // Children access + + /** + * @see API: http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource- + * Retrieveacategory + */ + public Category getCategory() + { + Integer categoryId = target.getIdFromLink(ParentLinkName.CATEGORY); + CategoryDto category = context.getApi().getConfigApi().getCategory(categoryId); + return wrap(context, Category.class, category); + } + + /** + * @see API: http://community.abiquo.com/display/Abiquo/Volume+Resource#VolumeResource- + * Retrieveavolume + */ + public Volume getVolume() + { + if (this.isPersistent()) + { + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse rp = + checkNotNull(utils.getAbiquoHttpClient().get(target.searchLink("volume")), "volume"); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VolumeManagementDto.class)); + + VolumeManagementDto dto = parser.apply(rp); + return new Volume(context, dto); + } + return null; + } + + public boolean isPersistent() + { + return target.searchLink("volume") != null; + } + + // Parent access + + /** + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * RetrieveanEnterprise + */ + public Enterprise getEnterprise() + { + Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); + return wrap(context, Enterprise.class, + context.getApi().getEnterpriseApi().getEnterprise(enterpriseId)); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Datacenter+Resource#DatacenterResource- + * RetrieveaDatacenter + */ + public Datacenter getDatacenter() + { + Integer repositoryId = target.getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY); + return wrap(context, Datacenter.class, context.getApi().getInfrastructureApi() + .getDatacenter(repositoryId)); + } + + /** + * List all the conversions for the virtual machine template. + * + * @see API: http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource- + * ListConversions + * @return all the conversions of the virtual machine template + */ + public List listConversions() + { + ConversionsDto convs = + context.getApi().getVirtualMachineTemplateApi().listConversions(target); + return wrap(context, Conversion.class, convs.getCollection()); + } + + /** + * List all the conversions for the virtual machine template matching the given filter. + * + * @param filter The filter to apply. + * @return The list all the conversions for the virtual machine template matching the given + * filter. + */ + public List listConversions(final Predicate filter) + { + return Lists.newLinkedList(filter(listConversions(), filter)); + } + + /** + * Gets a single conversion in the virtual machine template matching the given filter. + * + * @param filter The filter to apply. + * @return The conversion or null if none matched the given filter. + */ + public Conversion findConversion(final Predicate filter) + { + return Iterables.getFirst(filter(listConversions(), filter), null); + } + + /** + * List conversions for a virtual machine template. + * + * @see API: http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource- + * ListConversions + * @param hypervisor, Optionally filter conversions compatible with the provided hypervisor + * @param state, Optionally filter conversions with the desired state + * @return all the conversions of the virtual machine template applying the constrains + */ + public List listConversions(final HypervisorType hypervisor, + final ConversionState state) + { + ConversionsDto convs = + context + .getApi() + .getVirtualMachineTemplateApi() + .listConversions( + target, + ConversionOptions.builder().hypervisorType(hypervisor).conversionState(state) + .build()); + return wrap(context, Conversion.class, convs.getCollection()); + } + + /** + * Starts a new conversion for a virtual machine template. + * + * @see API: http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource- + * RequestConversion + * @param diskFormat, desired target format for the request template + * @return The task reference to track its progress + */ + public AsyncTask requestConversion(final DiskFormatType diskFormat) + { + ConversionDto request = new ConversionDto(); + request.setTargetFormat(diskFormat); + + AcceptedRequestDto taskRef = + context.getApi().getVirtualMachineTemplateApi() + .requestConversion(target, diskFormat, request); + + return taskRef == null ? null : getTask(taskRef); + } + + // Delegate methods + public int getCpuRequired() + { + return target.getCpuRequired(); + } + + public Date getCreationDate() + { + return target.getCreationDate(); + } + + public String getCreationUser() + { + return target.getCreationUser(); + } + + public String getDescription() + { + return target.getDescription(); + } + + public long getDiskFileSize() + { + return target.getDiskFileSize(); + } + + public DiskFormatType getDiskFormatType() + { + return DiskFormatType.valueOf(target.getDiskFormatType()); + } + + public long getHdRequired() + { + return target.getHdRequired(); + } + + public String getName() + { + return target.getName(); + } + + public String getPath() + { + return target.getPath(); + } + + public int getRamRequired() + { + return target.getRamRequired(); + } + + public boolean isChefEnabled() + { + return target.isChefEnabled(); + } + + public void setChefEnabled(final boolean chefEnabled) + { + target.setChefEnabled(chefEnabled); + } + + public void setName(final String name) + { + target.setName(name); + } + + public Integer getId() + { + return target.getId(); + } + + public String getIconUrl() + { + return target.getIconUrl(); + } + + @Override + public String toString() + { + return "VirtualMachineTemplate [id=" + getId() + ", cpuRequired=" + getCpuRequired() + + ", creationDate=" + getCreationDate() + ", creationUser=" + getCreationUser() + + ", description=" + getDescription() + ", diskFileSize=" + getDiskFileSize() + + ", diskFormatType=" + getDiskFormatType() + ", hdRequired=" + getHdRequired() + + ", name=" + getName() + ", path=" + getPath() + ", ramRequired=" + getRamRequired() + + ", chefEnabled=" + isChefEnabled() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Volume.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Volume.java new file mode 100644 index 0000000000..a8d4f4d1fe --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Volume.java @@ -0,0 +1,250 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.VolumeState; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Adds high level functionality to {@link VolumeManagementDto}. + * + * @author Ignasi Barrera + * @see API: + * http://community.abiquo.com/display/ABI20/Volume+Resource + */ +@EnterpriseEdition +public class Volume extends DomainWrapper +{ + /** The default state for folumes. */ + public static final VolumeState DEFAULT_STATE = VolumeState.DETACHED; + + /** The virtual datacenter where the volume belongs. */ + private VirtualDatacenter virtualDatacenter; + + /** The tier where the volume belongs. */ + private Tier tier; + + /** + * Constructor to be used only by the builder. + */ + protected Volume(final RestContext context, final VolumeManagementDto target) + { + super(context, target); + } + + // Domain operations + + public void delete() + { + context.getApi().getCloudApi().deleteVolume(target); + target = null; + } + + public void save() + { + target = context.getApi().getCloudApi().createVolume(virtualDatacenter.unwrap(), target); + } + + public AsyncTask update() + { + AcceptedRequestDto taskRef = context.getApi().getCloudApi().updateVolume(target); + return taskRef == null ? null : getTask(taskRef); + } + + // Parent access + + /** + * @see API: http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource# + * VirtualDatacenterResource-RetrieveaVirtualDatacenter + */ + public VirtualDatacenter getVirtualDatacenter() + { + Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER); + VirtualDatacenterDto dto = + context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); + virtualDatacenter = wrap(context, VirtualDatacenter.class, dto); + return virtualDatacenter; + } + + /** + * TODO javadoc link + */ + public Tier getTier() + { + Integer tierId = target.getIdFromLink(ParentLinkName.TIER); + TierDto dto = + context.getApi().getCloudApi().getStorageTier(virtualDatacenter.unwrap(), tierId); + tier = wrap(context, Tier.class, dto); + return tier; + } + + // Actions + + /** + * Move the volume to the given virtual datacenter. + * + * @param newVirtualDatacenter The destination virtual datacenter. + */ + public void moveTo(final VirtualDatacenter newVirtualDatacenter) + { + target = + context.getApi().getCloudApi().moveVolume(unwrap(), newVirtualDatacenter.unwrap()); + } + + // Builder + + public static Builder builder(final RestContext context, + final VirtualDatacenter virtualDatacenter, final Tier tier) + { + return new Builder(context, virtualDatacenter, tier); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private String description; + + private Long sizeInMb; + + private VirtualDatacenter virtualDatacenter; + + private Tier tier; + + public Builder(final RestContext context, final VirtualDatacenter virtualDatacenter, + final Tier tier) + { + super(); + checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + + VirtualDatacenter.class); + checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Tier.class); + this.context = context; + this.virtualDatacenter = virtualDatacenter; + this.tier = tier; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder description(final String description) + { + this.description = description; + return this; + } + + public Builder sizeInMb(final long sizeInMb) + { + this.sizeInMb = sizeInMb; + return this; + } + + public Volume build() + { + VolumeManagementDto dto = new VolumeManagementDto(); + dto.setName(name); + dto.setDescription(description); + dto.setSizeInMB(sizeInMb); + dto.setState(DEFAULT_STATE.name()); + + RESTLink link = tier.unwrap().searchLink("self"); + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + dto.addLink(new RESTLink("tier", link.getHref())); + + Volume volume = new Volume(context, dto); + volume.virtualDatacenter = virtualDatacenter; + volume.tier = tier; + + return volume; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getState() + { + return target.getState(); + } + + public String getName() + { + return target.getName(); + } + + public void setName(final String name) + { + target.setName(name); + } + + public long getSizeInMB() + { + return target.getSizeInMB(); + } + + public void setSizeInMB(final long sizeInMB) + { + target.setSizeInMB(sizeInMB); + } + + public String getDescription() + { + return target.getDescription(); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + @Override + public String toString() + { + return "Volume [id=" + getId() + ", state=" + getState() + ", name=" + getName() + + ", sizeInMB=" + getSizeInMB() + ", description=" + getDescription() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/ConversionOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/ConversionOptions.java new file mode 100644 index 0000000000..1d97f03333 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/ConversionOptions.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.HypervisorType; + +/** + * Available options to filter virtual machine template conversions + */ +public class ConversionOptions extends BaseHttpRequestOptions +{ + + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + ConversionOptions options = new ConversionOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private HypervisorType hypervisorType; + + private ConversionState conversionState; + + /** Only conversions compatible with this hypervisor */ + public Builder hypervisorType(final HypervisorType hypervisorType) + { + this.hypervisorType = hypervisorType; + return this; + } + + /** Only conversions with the provided state */ + public Builder conversionState(final ConversionState conversionState) + { + this.conversionState = conversionState; + return this; + } + + public ConversionOptions build() + { + ConversionOptions options = new ConversionOptions(); + + if (hypervisorType != null) + { + options.queryParameters.put("hypervisor", hypervisorType.name()); + } + if (conversionState != null) + { + options.queryParameters.put("state", conversionState.name()); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualApplianceOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualApplianceOptions.java new file mode 100644 index 0000000000..50420618ee --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualApplianceOptions.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query virtual appliances. + * + * @author Francesc Montserrat + * @author Ignasi Barrera + */ +public class VirtualApplianceOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + VirtualApplianceOptions options = new VirtualApplianceOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + + private Boolean available; + + public Builder available(final boolean available) + { + this.available = available; + return this; + } + + public VirtualApplianceOptions build() + { + VirtualApplianceOptions options = new VirtualApplianceOptions(); + + if (available != null) + { + options.queryParameters.put("available", String.valueOf(available)); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualDatacenterOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualDatacenterOptions.java new file mode 100644 index 0000000000..783478fe87 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualDatacenterOptions.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query virtual datacenters. + * + * @author Francesc Montserrat + */ +public class VirtualDatacenterOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + VirtualDatacenterOptions options = new VirtualDatacenterOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private Integer datacenterId; + + private Integer enterpriseId; + + /** + * Set the optional datacenter. + */ + public Builder datacenterId(final int datacenterId) + { + this.datacenterId = datacenterId; + return this; + } + + /** + * Set the optional enterprise. + */ + public Builder enterpriseId(final int enterpriseId) + { + this.enterpriseId = enterpriseId; + return this; + } + + public VirtualDatacenterOptions build() + { + VirtualDatacenterOptions options = new VirtualDatacenterOptions(); + + if (datacenterId != null) + { + options.queryParameters.put("datacenter", datacenterId.toString()); + } + + if (enterpriseId != null) + { + options.queryParameters.put("enterprise", enterpriseId.toString()); + } + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineOptions.java new file mode 100644 index 0000000000..86758418f8 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineOptions.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud.options; + +import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query virtual machine. + * + * @author Alessia Prete + */ +public class VirtualMachineOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + VirtualMachineOptions options = new VirtualMachineOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder extends BaseFilterOptionsBuilder + { + private Boolean force; + + public Builder force(final Boolean force) + { + this.force = force; + return this; + } + + public VirtualMachineOptions build() + { + VirtualMachineOptions options = new VirtualMachineOptions(); + + if (force != null) + { + options.queryParameters.put("force", String.valueOf(force)); + } + + return addFilterOptions(options); + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineTemplateOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineTemplateOptions.java new file mode 100644 index 0000000000..6b6d2f1f08 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VirtualMachineTemplateOptions.java @@ -0,0 +1,120 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud.options; + +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.StatefulInclusion; + +/** + * Available options to query virtual machine templates. + * + * @author Ignasi Barrera + */ +public class VirtualMachineTemplateOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + VirtualMachineTemplateOptions options = new VirtualMachineTemplateOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private StatefulInclusion persistent; + + private HypervisorType hypervisorType; + + private Category category; + + private String categoryName; + + private Integer idTemplate; + + public Builder persistent(final StatefulInclusion persistent) + { + this.persistent = persistent; + return this; + } + + public Builder hypervisorType(final HypervisorType hypervisorType) + { + this.hypervisorType = hypervisorType; + return this; + } + + public Builder category(final Category category) + { + this.category = category; + return this; + } + + public Builder categoryName(final String categoryName) + { + this.categoryName = categoryName; + return this; + } + + public Builder idTemplate(final Integer idTemplate) + { + this.idTemplate = idTemplate; + return this; + } + + public VirtualMachineTemplateOptions build() + { + VirtualMachineTemplateOptions options = new VirtualMachineTemplateOptions(); + + if (persistent != null) + { + options.queryParameters.put("stateful", persistent.name()); + } + if (hypervisorType != null) + { + options.queryParameters.put("hypervisorTypeName", hypervisorType.name()); + } + if (category != null) + { + options.queryParameters.put("categoryName", category.getName()); + } + + if (category == null && categoryName != null) + { + options.queryParameters.put("categoryName", categoryName); + } + + if (idTemplate != null) + { + options.queryParameters.put("idTemplate", String.valueOf(idTemplate)); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VolumeOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VolumeOptions.java new file mode 100644 index 0000000000..66bc390956 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/options/VolumeOptions.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud.options; + +import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query volumes. + * + * @author Ignasi Barrera + */ +@EnterpriseEdition +public class VolumeOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + VolumeOptions options = new VolumeOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder extends BaseFilterOptionsBuilder + { + private Boolean onlyAvailable; + + public Builder onlyAvailable(final boolean onlyAvailable) + { + this.onlyAvailable = onlyAvailable; + return this; + } + + public VolumeOptions build() + { + VolumeOptions options = new VolumeOptions(); + + if (onlyAvailable != null) + { + options.queryParameters.put("available", String.valueOf(onlyAvailable)); + } + + return addFilterOptions(options); + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Category.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Category.java new file mode 100644 index 0000000000..25ef1b2d55 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Category.java @@ -0,0 +1,186 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.appslibrary.CategoryDto; + +/** + * Adds high level functionality to {@link CategoryDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Category+Resource + */ + +public class Category extends DomainWrapper +{ + /** The default value for the default category flag. */ + private static final boolean DEFAULT_DEFAULT_CATEGORY = false; + + /** The default value for the erasable flag. */ + private static final boolean DEFAULT_ERASABLE = true; + + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private Category(final RestContext context, final CategoryDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Deleteacategory + */ + public void delete() + { + context.getApi().getConfigApi().deleteCategory(target); + target = null; + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Createacategory + */ + public void save() + { + target = context.getApi().getConfigApi().createCategory(target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Updateanexistingcategory + */ + public void update() + { + target = context.getApi().getConfigApi().updateCategory(target); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private Boolean erasable = DEFAULT_ERASABLE; + + private Boolean defaultCategory = DEFAULT_DEFAULT_CATEGORY; + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder defaultCategory(final boolean defaultCategory) + { + this.defaultCategory = defaultCategory; + return this; + } + + public Builder erasable(final boolean erasable) + { + this.erasable = erasable; + return this; + } + + public Category build() + { + CategoryDto dto = new CategoryDto(); + dto.setErasable(erasable); + dto.setDefaultCategory(defaultCategory); + dto.setName(name); + Category category = new Category(context, dto); + + return category; + } + + public static Builder fromCategory(final Category in) + { + Builder builder = + Category.builder(in.context).name(in.getName()).erasable(in.isErasable()) + .defaultCategory(in.isDefaultCategory()); + + return builder; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public boolean isDefaultCategory() + { + return target.isDefaultCategory(); + } + + public boolean isErasable() + { + return target.isErasable(); + } + + public void setDefaultCategory(final boolean defaultCategory) + { + target.setDefaultCategory(defaultCategory); + } + + public void setErasable(final boolean erasable) + { + target.setErasable(erasable); + } + + public void setName(final String name) + { + target.setName(name); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java new file mode 100644 index 0000000000..d1fdb9835b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java @@ -0,0 +1,191 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.pricing.CurrencyDto; + +/** + * Adds high level functionality to {@link CurrencyDto}. + * + * @author Ignasi Barrera + * @author Susana Acedo + * @see API: + * http://community.abiquo.com/display/ABI20/Currency+Resource + */ + +public class Currency extends DomainWrapper +{ + + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private Currency(final RestContext context, final CurrencyDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource- + * Deleteacurrency + */ + public void delete() + { + context.getApi().getPricingApi().deleteCurrency(target); + target = null; + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource- + * Createacurrency + */ + public void save() + { + target = context.getApi().getPricingApi().createCurrency(target); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource- + * Updateanexistingcurrency + */ + public void update() + { + target = context.getApi().getPricingApi().updateCurrency(target); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private String symbol; + + private int digits; + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder symbol(final String symbol) + { + this.symbol = symbol; + return this; + } + + public Builder digits(final int digits) + { + this.digits = digits; + return this; + } + + public Currency build() + { + CurrencyDto dto = new CurrencyDto(); + dto.setName(name); + dto.setSymbol(symbol); + dto.setDigits(digits); + Currency currency = new Currency(context, dto); + + return currency; + } + + public static Builder fromCurrency(final Currency in) + { + Builder builder = + Currency.builder(in.context).name(in.getName()).symbol(in.getSymbol()) + .digits(in.getDigits()); + + return builder; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public void setName(final String name) + { + target.setName(name); + } + + public String getSymbol() + { + return target.getSymbol(); + } + + public void setSymbol(final String symbol) + { + target.setSymbol(symbol); + } + + public int getDigits() + { + return target.getDigits(); + } + + public void setDigits(final int digits) + { + target.setDigits(digits); + } + + @Override + public String toString() + { + return "Currency [id=" + getId() + ", name=" + getName() + ", symbol=" + getSymbol() + + ", digits=" + getDigits() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/License.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/License.java new file mode 100644 index 0000000000..f1c9d84b64 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/License.java @@ -0,0 +1,142 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.config.LicenseDto; + +/** + * Adds high level functionality to {@link LicenseDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@EnterpriseEdition +public class License extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected License(final RestContext context, final LicenseDto target) + { + super(context, target); + } + + // Domain operations + + public void remove() + { + context.getApi().getConfigApi().removeLicense(target); + target = null; + } + + public void add() + { + target = context.getApi().getConfigApi().addLicense(target); + } + + // Builder + + public static Builder builder(final RestContext context, final String code) + { + return new Builder(context, code); + } + + public static class Builder + { + private RestContext context; + + private String code; + + public Builder(final RestContext context, final String code) + { + super(); + this.context = context; + this.code = code; + } + + public Builder code(final String code) + { + this.code = code; + return this; + } + + public License build() + { + LicenseDto dto = new LicenseDto(); + dto.setCode(code); + + License license = new License(context, dto); + return license; + } + + public static Builder fromLicense(final License in) + { + return License.builder(in.context, in.getCode()); + } + } + + // Delegate methods + + public String getCode() + { + return target.getCode(); + } + + public String getCustomerId() + { + return target.getCustomerid(); + } + + public String getEnabledIp() + { + return target.getEnabledip(); + } + + public String getExpiration() + { + return target.getExpiration(); + } + + public Integer getId() + { + return target.getId(); + } + + public Integer getNumCores() + { + return target.getNumcores(); + } + + @Override + public String toString() + { + return "License [id=" + getId() + ", code=" + getCode() + ", customerId=" + getCustomerId() + + ", enabledIp=" + getEnabledIp() + ", expiration=" + getExpiration() + ", numCores=" + + getNumCores() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Privilege.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Privilege.java new file mode 100644 index 0000000000..a35e4ee1bf --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Privilege.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.PrivilegeDto; + +/** + * Adds high level functionality to {@link PrivilegeDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@EnterpriseEdition +public class Privilege extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private Privilege(final RestContext context, final PrivilegeDto target) + { + super(context, target); + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + @Override + public String toString() + { + return "Privilege [id=" + getId() + ", name=" + getName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/SystemProperty.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/SystemProperty.java new file mode 100644 index 0000000000..51c88c4cc9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/SystemProperty.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.config.SystemPropertyDto; + +/** + * Adds high level functionality to {@link SystemPropertyDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/System+Property+resource + */ + +public class SystemProperty extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private SystemProperty(final RestContext context, final SystemPropertyDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/System+Property+resource#SystemPropertyresource-ModifyanexistingSystemProperty + */ + public void update() + { + target = context.getApi().getConfigApi().updateSystemProperty(target); + } + + // Delegate methods + + public String getName() + { + return target.getName(); + } + + public String getValue() + { + return target.getValue(); + } + + public void setValue(final String value) + { + target.setValue(value); + } + + @Override + public String toString() + { + return "SystemPorperty [getName()=" + getName() + ", getValue()=" + getValue() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/IconOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/IconOptions.java new file mode 100644 index 0000000000..5c975815b7 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/IconOptions.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query icons. + * + * @author Francesc Montserrat + */ +public class IconOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + IconOptions options = new IconOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private String path; + + public Builder path(final String path) + { + this.path = path; + return this; + } + + public IconOptions build() + { + IconOptions options = new IconOptions(); + if (path != null) + { + options.queryParameters.put("path", path); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/LicenseOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/LicenseOptions.java new file mode 100644 index 0000000000..7234fc2686 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/LicenseOptions.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config.options; + +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query licenses. + * + * @author Francesc Montserrat + */ +@EnterpriseEdition +public class LicenseOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + LicenseOptions options = new LicenseOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private Boolean active; + + /** + * Search active licenses + */ + public Builder active(final boolean active) + { + this.active = active; + return this; + } + + /** + * Search inaactive licenses + */ + public Builder inactive(final boolean inactive) + { + this.active = !inactive; + return this; + } + + public LicenseOptions build() + { + LicenseOptions options = new LicenseOptions(); + if (active != null) + { + options.queryParameters.put("active", active.toString()); + } + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/PropertyOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/PropertyOptions.java new file mode 100644 index 0000000000..1f8a3876d4 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/config/options/PropertyOptions.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query system properties. + * + * @author Francesc Montserrat + */ +public class PropertyOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + PropertyOptions options = new PropertyOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private String component; + + private String name; + + public Builder component(final String component) + { + this.component = component; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public PropertyOptions build() + { + PropertyOptions options = new PropertyOptions(); + if (component != null) + { + options.queryParameters.put("component", component.toString()); + } + + if (name != null) + { + options.queryParameters.put("name", name.toString()); + } + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java new file mode 100644 index 0000000000..f62ee8b90a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java @@ -0,0 +1,1000 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWithLimitsWrapper; +import org.jclouds.abiquo.domain.builder.LimitsBuilder; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.domain.network.ExternalIp; +import org.jclouds.abiquo.domain.network.ExternalNetwork; +import org.jclouds.abiquo.domain.network.Network; +import org.jclouds.abiquo.domain.network.UnmanagedIp; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.abiquo.strategy.enterprise.ListVirtualMachineTemplates; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListsDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; +import com.abiquo.server.core.enterprise.RolesDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.abiquo.server.core.enterprise.UsersDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to {@link EnterpriseDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/EnterpriseResource + */ +public class Enterprise extends DomainWithLimitsWrapper +{ + /** The default value for the reservation restricted flag. */ + private static final boolean DEFAULT_RESERVATION_RESTRICTED = false; + + /** + * Constructor to be used only by the builder. + */ + protected Enterprise(final RestContext context, + final EnterpriseDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * DeleteanexistingEnterprise + */ + public void delete() + { + context.getApi().getEnterpriseApi().deleteEnterprise(target); + target = null; + } + + /** + * Create a new enterprise in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * CreatesanewEnterprise + */ + public void save() + { + target = context.getApi().getEnterpriseApi().createEnterprise(target); + } + + /** + * Update emterprise information in the server with the data from this enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * Updateanexistingenterprise + */ + public void update() + { + target = context.getApi().getEnterpriseApi().updateEnterprise(target); + } + + // Children access + + /** + * Retrieve the list of virtual datacenters by this enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievealistofvitualdatacentersbyanEnterprise + * @return List of virtual datacenters in this enterprise. + */ + public List listVirtualDatacenters() + { + VirtualDatacentersDto dto = + context.getApi().getEnterpriseApi().listVirtualDatacenters(target); + return wrap(context, VirtualDatacenter.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of virtual datacenters by this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievealistofvitualdatacentersbyanEnterprise + * @return Filtered list of virtual datacenters in this enterprise. + */ + public List listVirtualDatacenters(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualDatacenters(), filter)); + } + + /** + * Retrieve a the first virtual datacenter matching the filter within the list of virtual + * datacenters by this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievealistofvitualdatacentersbyanEnterprise + * @return First virtual datacenter matching the filter or null if the is none. + */ + public VirtualDatacenter findVirtualDatacenter(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualDatacenters(), filter), null); + } + + /** + * Retrieve the list of template definition lists of the enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Retrievealltemplatedefinitionlists + * @return List of template definition lists of the enterprise. + */ + public List listTemplateDefinitionLists() + { + TemplateDefinitionListsDto dto = + context.getApi().getEnterpriseApi().listTemplateDefinitionLists(target); + return wrap(context, TemplateDefinitionList.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of template definition lists from this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Retrievealltemplatedefinitionlists + * @return Filtered list of template definition lists of the enterprise. + */ + public List listTemplateDefinitionLists( + final Predicate filter) + { + return Lists.newLinkedList(filter(listTemplateDefinitionLists(), filter)); + } + + /** + * Retrieve the first template definition list matching the filter within the list. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Retrievealltemplatedefinitionlists + * @return First template definition list matching the filter or null if the is + * none. + */ + public TemplateDefinitionList findTemplateDefinitionList( + final Predicate filter) + { + return Iterables.getFirst(filter(listTemplateDefinitionLists(), filter), null); + } + + /** + * Retrieve a single template definition list. + * + * @param id Unique ID of the template definition list for this enterprise. + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Retrieveatemplatedefinitionlist + * @return Template definition with the given id or null if it does not exist. + */ + public TemplateDefinitionList getTemplateDefinitionList(final Integer id) + { + TemplateDefinitionListDto templateList = + context.getApi().getEnterpriseApi().getTemplateDefinitionList(target, id); + return wrap(context, TemplateDefinitionList.class, templateList); + } + + /** + * Retrieve the list of datacenter limits by enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterLimitsResource# + * DatacenterLimitsResource-Retrievelimitsbyenterprise + * @return List of datacenter limits by enterprise. + */ + public List listLimits() + { + DatacentersLimitsDto dto = context.getApi().getEnterpriseApi().listLimits(this.unwrap()); + return wrap(context, Limits.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of datacenter limits by enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterLimitsResource# + * DatacenterLimitsResource-Retrievelimitsbyenterprise + * @return Filtered list of datacenter limits by enterprise. + */ + public List listLimits(final Predicate filter) + { + return Lists.newLinkedList(filter(listLimits(), filter)); + } + + /** + * Retrieve the first datacenter limits matching the filter within the list of datacenter limits + * by enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterLimitsResource# + * DatacenterLimitsResource-Retrievelimitsbyenterprise + * @return First datacenter limits matching the filter or null if there is none. + */ + public Limits findLimits(final Predicate filter) + { + return Iterables.getFirst(filter(listLimits(), filter), null); + } + + /** + * Retrieve the defined properties of the given enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterprisePropertiesResource# + * EnterprisePropertiesResource-Retrievethepropertiesforanenterprise + * @return The defined properties of the given enterprise. + */ + public EnterpriseProperties getEnterpriseProperties() + { + EnterprisePropertiesDto dto = + context.getApi().getEnterpriseApi().getEnterpriseProperties(this.unwrap()); + return wrap(context, EnterpriseProperties.class, dto); + } + + /** + * Retrieve the list of users of this enterprise. + * + * @see API: + * http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrievealistofusers + * + * @return List of users of this enterprise. + */ + public List listUsers() + { + UsersDto dto = context.getApi().getEnterpriseApi().listUsers(this.unwrap()); + return wrap(context, User.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of users of this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: + * http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrievealistofusers + * + * @return Filtered list of users of this enterprise. + */ + public List listUsers(final Predicate filter) + { + return Lists.newLinkedList(filter(listUsers(), filter)); + } + + /** + * Retrieve the first user matching the filter within the list of users of this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: + * http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrievealistofusers + * + * @return First user matching the filter or null if there is none. + */ + public User findUser(final Predicate filter) + { + return Iterables.getFirst(filter(listUsers(), filter), null); + } + + /** + * Retrieve a single user. + * + * @param id Unique ID of the user in this enterprise. + * @see API: + * http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrieveauser + * @return User with the given id or null if it does not exist. + */ + public User getUser(final Integer id) + { + UserDto user = context.getApi().getEnterpriseApi().getUser(target, id); + return wrap(context, User.class, user); + } + + /** + * Retrieve the list of roles defined by this enterprise. + * + * @return List of roles by this enterprise. + */ + public List listRoles() + { + RolesDto dto = context.getApi().getAdminApi().listRoles(target); + return wrap(context, Role.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of roles defined by this enterprise. + * + * @param filter Filter to be applied to the list. + * @return Filtered list of roles by this enterprise. + */ + public List listRoles(final Predicate filter) + { + return Lists.newLinkedList(filter(listRoles(), filter)); + } + + /** + * Retrieve the first role matching the filter within the list of roles defined by this + * enterprise. + * + * @param filter Filter to be applied to the list. + * @return First role matching the filter or null if there is none. + */ + public Role findRole(final Predicate filter) + { + return Iterables.getFirst(filter(listRoles(), filter), null); + } + + public List listTemplatesInRepository(final Datacenter datacenter) + { + VirtualMachineTemplatesDto dto = + context.getApi().getVirtualMachineTemplateApi() + .listVirtualMachineTemplates(target.getId(), datacenter.getId()); + return wrap(context, VirtualMachineTemplate.class, dto.getCollection()); + } + + public List listTemplatesInRepository(final Datacenter datacenter, + final Predicate filter) + { + return Lists.newLinkedList(filter(listTemplatesInRepository(datacenter), filter)); + } + + public VirtualMachineTemplate findTemplateInRepository(final Datacenter datacenter, + final Predicate filter) + { + return Iterables.getFirst(filter(listTemplatesInRepository(datacenter), filter), null); + } + + public VirtualMachineTemplate getTemplateInRepository(final Datacenter datacenter, + final Integer id) + { + VirtualMachineTemplateDto template = + context.getApi().getVirtualMachineTemplateApi() + .getVirtualMachineTemplate(target.getId(), datacenter.getId(), id); + return wrap(context, VirtualMachineTemplate.class, template); + } + + public List listTemplates() + { + ListVirtualMachineTemplates strategy = + context.getUtils().getInjector().getInstance(ListVirtualMachineTemplates.class); + return Lists.newLinkedList(strategy.execute(this)); + } + + public List listTemplates(final Predicate filter) + { + ListVirtualMachineTemplates strategy = + context.getUtils().getInjector().getInstance(ListVirtualMachineTemplates.class); + return Lists.newLinkedList(strategy.execute(this, filter)); + } + + public VirtualMachineTemplate findTemplate(final Predicate filter) + { + ListVirtualMachineTemplates strategy = + context.getUtils().getInjector().getInstance(ListVirtualMachineTemplates.class); + return Iterables.getFirst(strategy.execute(this, filter), null); + } + + public List listAllowedDatacenters() + { + DatacentersDto datacenters = + context.getApi().getEnterpriseApi().listAllowedDatacenters(target.getId()); + return wrap(context, Datacenter.class, datacenters.getCollection()); + } + + public List listAllowedDatacenters(final Predicate filter) + { + return Lists.newLinkedList(filter(listAllowedDatacenters(), filter)); + } + + public Datacenter findAllowedDatacenter(final Predicate filter) + { + return Iterables.getFirst(filter(listAllowedDatacenters(), filter), null); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * Getthelistofexternalnetworks + */ + @EnterpriseEdition + public List listExternalNetworks(final Datacenter datacenter) + { + DatacenterLimitsDto limitForDatacenter = getLimits(datacenter); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = + utils.getAbiquoHttpClient().get(limitForDatacenter.searchLink("externalnetworks")); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VLANNetworksDto.class)); + + return wrap(context, ExternalNetwork.class, parser.apply(response).getCollection()); + } + + @EnterpriseEdition + public List listExternalNetworks(final Datacenter datacenter, + final Predicate> filter) + { + return Lists.newLinkedList(filter(listExternalNetworks(datacenter), filter)); + } + + @EnterpriseEdition + public ExternalNetwork findExternalNetwork(final Datacenter datacenter, + final Predicate> filter) + { + return Iterables.getFirst(filter(listExternalNetworks(datacenter), filter), null); + } + + @EnterpriseEdition + public List listUnmanagedNetworks(final Datacenter datacenter) + { + DatacenterLimitsDto limitForDatacenter = getLimits(datacenter); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + // The "rel" for the unmanaged networks is the same than teh one used for external networks + HttpResponse response = + utils.getAbiquoHttpClient().get(limitForDatacenter.searchLink("externalnetworks")); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VLANNetworksDto.class)); + + return wrap(context, UnmanagedNetwork.class, parser.apply(response).getCollection()); + } + + @EnterpriseEdition + public List listUnmanagedNetworks(final Datacenter datacenter, + final Predicate> filter) + { + return Lists.newLinkedList(filter(listUnmanagedNetworks(datacenter), filter)); + } + + @EnterpriseEdition + public UnmanagedNetwork findUnmanagedNetwork(final Datacenter datacenter, + final Predicate> filter) + { + return Iterables.getFirst(filter(listUnmanagedNetworks(datacenter), filter), null); + } + + /** + * Retrieve the list of virtual appliances by this enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievethelistofvirtualappliancesbyanEnterprise + * @return List of virtual appliances by this enterprise. + */ + public List listVirtualAppliances() + { + VirtualAppliancesDto virtualAppliances = + context.getApi().getEnterpriseApi().listVirtualAppliances(target); + return wrap(context, VirtualAppliance.class, virtualAppliances.getCollection()); + } + + /** + * Retrieve a filtered list of virtual appliances by this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievethelistofvirtualappliancesbyanEnterprise + * @return Filtered list of virtual appliances by this enterprise. + */ + public List listVirtualAppliances(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualAppliances(), filter)); + } + + /** + * Retrieve the first virtual appliance matching the filter within the list of virtual + * appliances in this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievethelistofvirtualappliancesbyanEnterprise + * @return First virtual machine matching the filter or null if the is none. + */ + public VirtualAppliance findVirtualAppliance(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualAppliances(), filter), null); + } + + /** + * Retrieve the list of virtual machines by this enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievealistofvirtualmachinesbyanEnterprise + * @return List of virtual machines by this enterprise. + */ + public List listVirtualMachines() + { + VirtualMachinesWithNodeExtendedDto machines = + context.getApi().getEnterpriseApi().listVirtualMachines(target); + return wrap(context, VirtualMachine.class, machines.getCollection()); + } + + /** + * Retrieve a filtered list of virtual machines by this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievealistofvirtualmachinesbyanEnterprise + * @return Filtered list of virtual machines by this enterprise. + */ + public List listVirtualMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualMachines(), filter)); + } + + /** + * Retrieve the first virtual machine matching the filter within the list of virtual machines in + * this enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource- + * RetrievealistofvirtualmachinesbyanEnterprise + * @return First virtual machine matching the filter or null if the is none. + */ + public VirtualMachine findVirtualMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualMachines(), filter), null); + } + + public List listReservedMachines() + { + MachinesDto machines = context.getApi().getEnterpriseApi().listReservedMachines(target); + return wrap(context, Machine.class, machines.getCollection()); + } + + public List listReservedMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualMachines(), filter)); + } + + public VirtualMachine findReservedMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualMachines(), filter), null); + } + + // Actions + + /** + * @see API: http://community.abiquo.com/display/ABI20/Datacenter+Repository+Resource# + * DatacenterRepositoryResource-SynchronizetheDatacenterRepositorywiththerepository + */ + public void refreshTemplateRepository(final Datacenter datacenter) + { + context.getApi().getEnterpriseApi() + .refreshTemplateRepository(target.getId(), datacenter.getId()); + } + + /** + * Allows the given datacenter to be used by this enterprise. Creates a {@link Limits} object if + * not exists. + * + * @param datacenter The datacenter. + * @return Default datacenter limits of the enterprise for the given datacenter. + * @see API: http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource# + * DatacenterLimitsResource-CreateanewLimitforanenterpriseinadatacenter + */ + public Limits allowDatacenter(final Datacenter datacenter) + { + DatacenterLimitsDto dto; + + try + { + // Create new limits + Limits limits = Limits.builder(context).build(); + + // Save new limits + dto = + context.getApi().getEnterpriseApi() + .createLimits(target, datacenter.unwrap(), limits.unwrap()); + } + catch (AbiquoException ex) + { + // Controlled error to allow duplicated authorizations + if (ex.hasError("LIMIT-7")) + { + DatacentersLimitsDto limits = + context.getApi().getEnterpriseApi().getLimits(target, datacenter.unwrap()); + // Should be only one limit + dto = limits.getCollection().get(0); + } + else + { + throw ex; + } + } + + return wrap(context, Limits.class, dto); + } + + /** + * Prohibe the given datacenter to be used by this enterprise. Deletes a {@link Limits} object. + * + * @param datacenter The datacenter. + * @return Default datacenter limits of the enterprise for the given datacenter. + * @see API: http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource# + * DatacenterLimitsResource-Deleteanexistinglimitforanenterpriseinadatacenter + */ + public void prohibitDatacenter(final Datacenter datacenter) + { + // Get limits + DatacentersLimitsDto dto = + context.getApi().getEnterpriseApi().getLimits(target, datacenter.unwrap()); + + // Delete limits (if any) + if (dto != null && !dto.isEmpty()) + { + // Should be only one limit + context.getApi().getEnterpriseApi().deleteLimits(dto.getCollection().get(0)); + } + } + + /** + * Disables chef in the enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * DisableChefinanexistingEnterprise + */ + public void disableChef() + { + target.setChefClient(null); + target.setChefClientCertificate(null); + target.setChefURL(null); + target.setChefValidator(null); + target.setChefValidatorCertificate(null); + update(); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder extends LimitsBuilder + { + private RestContext context; + + private String name; + + protected Long repositorySoft = Long.valueOf(DEFAULT_LIMITS); + + protected Long repositoryHard = Long.valueOf(DEFAULT_LIMITS); + + private Boolean isReservationRestricted = DEFAULT_RESERVATION_RESTRICTED; + + private String chefURL; + + private String chefClient; + + private String chefValidator; + + private String chefApiCertificate; + + private String chefValidatorCertificate; + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder isReservationRestricted(final boolean isReservationRestricted) + { + this.isReservationRestricted = isReservationRestricted; + return this; + } + + public Builder chefURL(final String chefURL) + { + this.chefURL = chefURL; + return this; + } + + public Builder chefClient(final String chefClient) + { + this.chefClient = chefClient; + return this; + } + + public Builder chefApiCertificate(final String chefApiCertificate) + { + this.chefApiCertificate = chefApiCertificate; + return this; + } + + public Builder chefValidator(final String chefValidator) + { + this.chefValidator = chefValidator; + return this; + } + + public Builder chefValidatorCertificate(final String chefValidatorCertificate) + { + this.chefValidatorCertificate = chefValidatorCertificate; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder repositoryLimits(final long soft, final long hard) + { + this.repositorySoft = soft; + this.repositoryHard = hard; + return this; + } + + public Enterprise build() + { + EnterpriseDto dto = new EnterpriseDto(); + dto.setName(name); + dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb); + dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit); + dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb); + dto.setStorageLimits(storageSoft, storageHard); + dto.setVlansLimits(vlansSoft, vlansHard); + dto.setPublicIPLimits(publicIpsSoft, publicIpsHard); + dto.setRepositoryLimits(repositorySoft, repositoryHard); + dto.setIsReservationRestricted(isReservationRestricted); + dto.setChefClient(chefClient); + dto.setChefClientCertificate(chefApiCertificate); + dto.setChefURL(chefURL); + dto.setChefValidator(chefValidator); + dto.setChefValidatorCertificate(chefValidatorCertificate); + + return new Enterprise(context, dto); + } + + public static Builder fromEnterprise(final Enterprise in) + { + return Enterprise.builder(in.context).name(in.getName()) + .ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb()) + .cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit()) + .hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb()) + .storageLimits(in.getStorageSoft(), in.getStorageHard()) + .vlansLimits(in.getVlansSoft(), in.getVlansHard()) + .publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard()) + .repositoryLimits(in.getRepositorySoft(), in.getRepositoryHard()) + .isReservationRestricted(in.getIsReservationRestricted()) + .chefClient(in.getChefClient()).chefApiCertificate(in.getChefApiCertificate()) + .chefURL(in.getChefURL()).chefValidator(in.getChefValidator()) + .chefValidatorCertificate(in.getChefValidatorCertificate()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public boolean getIsReservationRestricted() + { + return target.getIsReservationRestricted(); + } + + public String getName() + { + return target.getName(); + } + + public long getRepositoryHard() + { + return target.getRepositoryHard(); + } + + public long getRepositorySoft() + { + return target.getRepositorySoft(); + } + + public void setIsReservationRestricted(final boolean isReservationRestricted) + { + target.setIsReservationRestricted(isReservationRestricted); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setRepositoryHard(final long repositoryHard) + { + target.setRepositoryHard(repositoryHard); + } + + public void setRepositoryLimits(final long soft, final long hard) + { + target.setRepositoryLimits(soft, hard); + } + + public void setRepositorySoft(final long repositorySoft) + { + target.setRepositorySoft(repositorySoft); + } + + public String getChefClient() + { + return target.getChefClient(); + } + + public String getChefApiCertificate() + { + return target.getChefClientCertificate(); + } + + public String getChefURL() + { + return target.getChefURL(); + } + + public String getChefValidator() + { + return target.getChefValidator(); + } + + public String getChefValidatorCertificate() + { + return target.getChefValidatorCertificate(); + } + + public void setChefClient(final String chefClient) + { + target.setChefClient(chefClient); + } + + public void setChefClientCertificate(final String chefClientCertificate) + { + target.setChefClientCertificate(chefClientCertificate); + } + + public void setChefURL(final String chefURL) + { + target.setChefURL(chefURL); + } + + public void setChefValidator(final String chefValidator) + { + target.setChefValidator(chefValidator); + } + + public void setChefValidatorCertificate(final String chefValidatorCertificate) + { + target.setChefValidatorCertificate(chefValidatorCertificate); + } + + @Override + public String toString() + { + return "Enterprise [id=" + getId() + ", isReservationRestricted=" + + getIsReservationRestricted() + ", name=" + getName() + "]"; + } + + private DatacenterLimitsDto getLimits(final Datacenter datacenter) + { + DatacentersLimitsDto limits = context.getApi().getEnterpriseApi().listLimits(target); + + return Iterables.find(limits.getCollection(), new Predicate() + { + @Override + public boolean apply(final DatacenterLimitsDto input) + { + RESTLink datacenterLink = input.searchLink("datacenter"); + return datacenterLink != null + && datacenterLink.getHref().equals(datacenter.unwrap().getEditLink().getHref()); + } + }); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/EnterpriseProperties.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/EnterpriseProperties.java new file mode 100644 index 0000000000..dba92be840 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/EnterpriseProperties.java @@ -0,0 +1,88 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import java.util.Map; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; + +/** + * Adds high level functionality to {@link EnterprisePropertiesDto}. + * + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Enterprise+Properties+Resource + */ +@EnterpriseEdition +public class EnterpriseProperties extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected EnterpriseProperties(final RestContext context, + final EnterprisePropertiesDto target) + { + super(context, target); + } + + // Domain operations + /** + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Properties+Resource# + * EnterprisePropertiesResource-UpdatesthepropertiesforanEnterprise + */ + public void update() + { + target = context.getApi().getEnterpriseApi().updateEnterpriseProperties(target); + } + + // Parent access + /** + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * RetrieveaEnterprise + */ + public Enterprise getEnterprise() + { + Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); + return wrap(context, Enterprise.class, context.getApi().getEnterpriseApi() + .getEnterprise(enterpriseId)); + } + + // Delegate methods + public Map getProperties() + { + return target.getProperties(); + } + + public void setProperties(final Map properties) + { + target.setProperties(properties); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Limits.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Limits.java new file mode 100644 index 0000000000..3e31eb0f55 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Limits.java @@ -0,0 +1,165 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWithLimitsWrapper; +import org.jclouds.abiquo.domain.builder.LimitsBuilder; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; + +/** + * Adds high level functionality to {@link DatacenterLimitsDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource + */ +public class Limits extends DomainWithLimitsWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Limits(final RestContext context, final DatacenterLimitsDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource#DatacenterLimitsResource-UpdatesanexistingLimitforanenterpriseinadatacenter + */ + public void update() + { + target = context.getApi().getEnterpriseApi().updateLimits(target); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder extends LimitsBuilder + { + private RestContext context; + + protected Long repositorySoft = Long.valueOf(DEFAULT_LIMITS); + + protected Long repositoryHard = Long.valueOf(DEFAULT_LIMITS); + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder repositoryLimits(final long soft, final long hard) + { + this.repositorySoft = soft; + this.repositoryHard = hard; + return this; + } + + public Limits build() + { + DatacenterLimitsDto dto = new DatacenterLimitsDto(); + dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb); + dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit); + dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb); + dto.setStorageLimits(storageSoft, storageHard); + dto.setVlansLimits(vlansSoft, vlansHard); + dto.setPublicIPLimits(publicIpsSoft, publicIpsHard); + dto.setRepositoryHardLimitsInMb(repositoryHard); + dto.setRepositorySoftLimitsInMb(repositorySoft); + + Limits limits = new Limits(context, dto); + + return limits; + } + + public static Builder fromEnterprise(final Limits in) + { + return Limits.builder(in.context) + .ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb()) + .cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit()) + .hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb()) + .storageLimits(in.getStorageSoft(), in.getStorageHard()) + .vlansLimits(in.getVlansSoft(), in.getVlansHard()) + .publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard()) + .repositoryLimits(in.getRepositorySoft(), in.getRepositoryHard()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public long getRepositoryHard() + { + return target.getRepositoryHardLimitsInMb(); + } + + public long getRepositorySoft() + { + return target.getRepositorySoftLimitsInMb(); + } + + public void setRepositoryHard(final long repositoryHard) + { + target.setRepositoryHardLimitsInMb(repositoryHard); + } + + public void setRepositoryLimits(final long soft, final long hard) + { + target.setRepositoryHardLimitsInMb(hard); + target.setRepositorySoftLimitsInMb(soft); + } + + public void setRepositorySoft(final long repositorySoft) + { + target.setRepositorySoftLimitsInMb(repositorySoft); + } + + @Override + public String toString() + { + return "Limits [id=" + getId() + ", repositoryHard=" + getRepositoryHard() + + ", repositorySoft=" + getRepositorySoft() + ", cpuCounthard=" + + getCpuCountHardLimit() + ", cpuCountSoft=" + getCpuCountSoftLimit() + ", hdHardInMB=" + + getHdHardLimitInMb() + ", hdSoftInMB=" + getHdSoftLimitInMb() + ", publicIPsHard=" + + getPublicIpsHard() + ", publicIpsSoft=" + getPublicIpsSoft() + ", ramHardInMB=" + + getRamHardLimitInMb() + ", ramSoftInMB=" + getRamSoftLimitInMb() + ", storageHard=" + + getStorageHard() + ", storageSoft=" + getStorageSoft() + ", vlansHard=" + + getVlansHard() + ", vlansSoft=" + getVlansSoft() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java new file mode 100644 index 0000000000..b12b62214a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java @@ -0,0 +1,250 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link RoleDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Roles+Resource + */ +public class Role extends DomainWrapper +{ + /** Default active value of the user */ + private static final boolean DEFAULT_BLOCKED = false; + + /** + * Constructor to be used only by the builder. + */ + protected Role(final RestContext context, final RoleDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-DeleteanexistingRole + * + */ + public void delete() + { + context.getApi().getAdminApi().deleteRole(target); + target = null; + } + + /** + * @see API: + * http + * ://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-CreateanewRole + */ + public void save() + { + target = context.getApi().getAdminApi().createRole(target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-UpdateanexistingRole + * + */ + public void update() + { + target = context.getApi().getAdminApi().updateRole(target); + } + + public void setEnterprise(final Enterprise enterprise) + { + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + Enterprise.class); + + RESTLink link = enterprise.unwrap().searchLink("edit"); + + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + + target.addLink(new RESTLink("enterprise", link.getHref())); + } + + @EnterpriseEdition + public void setPrivileges(final List privileges) + { + for (Privilege privilege : privileges) + { + addPrivilege(privilege); + } + } + + @EnterpriseEdition + private void addPrivilege(final Privilege privilege) + { + checkNotNull(privilege, ValidationErrors.NULL_RESOURCE + Privilege.class); + checkNotNull(privilege.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + Privilege.class); + + RESTLink link = privilege.unwrap().searchLink("self"); + + // rel would be "privilege" if the object is coming from a privilege list. + if (link == null) + { + link = privilege.unwrap().searchLink("privilege"); + } + + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + + target.addLink(new RESTLink("privilege" + privilege.getId(), link.getHref())); + } + + // Children access + + /** + * @see API: http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource- + * RetrievealistofprivilegesfromaRole + */ + public List listPrivileges() + { + PrivilegesDto dto = context.getApi().getAdminApi().listPrivileges(target); + + return wrap(context, Privilege.class, dto.getCollection()); + } + + public List listPrivileges(final Predicate filter) + { + return Lists.newLinkedList(filter(listPrivileges(), filter)); + } + + public Privilege findPrivileges(final Predicate filter) + { + return Iterables.getFirst(filter(listPrivileges(), filter), null); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private boolean blocked = DEFAULT_BLOCKED; + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder blocked(final boolean blocked) + { + this.blocked = blocked; + return this; + } + + public Role build() + { + RoleDto dto = new RoleDto(); + dto.setName(name); + dto.setBlocked(blocked); + Role role = new Role(context, dto); + + return role; + } + + public static Builder fromRole(final Role in) + { + return Role.builder(in.context).blocked(in.isBlocked()).name(in.getName()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public boolean isBlocked() + { + return target.isBlocked(); + } + + public void setBlocked(final boolean blocked) + { + target.setBlocked(blocked); + } + + public void setName(final String name) + { + target.setName(name); + } + + @Override + public String toString() + { + return "Role [id=" + getId() + ", name=" + getName() + ", blocked=" + isBlocked() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionList.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionList.java new file mode 100644 index 0000000000..f4e9b1380b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionList.java @@ -0,0 +1,236 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.rest.RestContext; + +import com.abiquo.am.model.TemplatesStateDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link TemplateDefinitionListDto}. A Template Definition List + * provides a way to organize multiple Template Definitions. A single Template Definition can be + * shared by many lists. Its compatible with ovfindex.xml format. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class TemplateDefinitionList extends DomainWrapper +{ + /** The enterprise where the list belongs. */ + private Enterprise enterprise; + + /** + * Constructor to be used only by the builder. + */ + protected TemplateDefinitionList(final RestContext context, + final TemplateDefinitionListDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the template definition list. Deleting the list doesn't delete the containing Template + * Definitions. + * + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Deleteatemplatedefinitionlist + */ + public void delete() + { + context.getApi().getEnterpriseApi().deleteTemplateDefinitionList(target); + target = null; + } + + /** + * Create a template definition list. All the contained Template Definitions will also be + * created. + * + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Createatemplatedefinitionlistr + */ + public void save() + { + target = + context.getApi().getEnterpriseApi() + .createTemplateDefinitionList(enterprise.unwrap(), target); + } + + /** + * Update a template definition list with the data from this template definition list. + * + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Modifyatemplatedefinitionlist + */ + public void update() + { + target = context.getApi().getEnterpriseApi().updateTemplateDefinitionList(target); + } + + // Children access + + /** + * Retrieve the list of states of the templates in the template definition list in the + * repository of the given datacenter. Template Definition are available sources, but in order + * to create a Virtual Machine the Definition should be downloaded into the Datacenter + * Repository (NFS filesystem). + * + * @param The datacenter in which repository search. + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Retrievealistofthestatusofalltemplatestatuslist + */ + public List listStatus(final Datacenter datacenter) + { + TemplatesStateDto states = + context.getApi().getEnterpriseApi() + .listTemplateListStatus(target, datacenter.unwrap()); + return wrap(context, TemplateState.class, states.getCollection()); + } + + /** + * Retrieve a filtered list of states of the templates in the template definition list in the + * repository of the given datacenter. Template Definition are available sources, but in order + * to create a Virtual Machine the Definition should be downloaded into the Datacenter + * Repository (NFS filesystem). + * + * @param filter Filter to be applied to the list. + * @param The datacenter in which repository search. + * @see API: http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource# + * TemplateDefinitionListResource-Retrievealistofthestatusofalltemplatestatuslist + */ + public List listStatus(final Predicate filter, + final Datacenter datacenter) + { + return Lists.newLinkedList(filter(listStatus(datacenter), filter)); + } + + // Builder + + public static Builder builder(final RestContext context, + final Enterprise enterprise) + { + return new Builder(context, enterprise); + } + + public static class Builder + { + private RestContext context; + + private Enterprise enterprise; + + private String name; + + private String url; + + public Builder(final RestContext context, + final Enterprise enterprise) + { + super(); + this.context = context; + this.enterprise = enterprise; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder url(final String url) + { + this.url = url; + return this; + } + + public TemplateDefinitionList build() + { + TemplateDefinitionListDto dto = new TemplateDefinitionListDto(); + dto.setName(name); + dto.setUrl(url); + + TemplateDefinitionList templateList = new TemplateDefinitionList(context, dto); + templateList.enterprise = enterprise; + return templateList; + + } + + public static Builder fromTemplateDefinitionList(final TemplateDefinitionList in) + { + return TemplateDefinitionList.builder(in.context, in.enterprise).name(in.getName()) + .url(in.getUrl()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public String getUrl() + { + return target.getUrl(); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setUrl(final String url) + { + target.setUrl(url); + } + + @Override + public String toString() + { + return "TemplateDefinitionList [getId()=" + getId() + ", getName()=" + getName() + + ", getUrl()=" + getUrl() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateState.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateState.java new file mode 100644 index 0000000000..c0773b8952 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/TemplateState.java @@ -0,0 +1,81 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.am.model.TemplateStateDto; +import com.abiquo.am.model.TemplateStatusEnumType; + +/** + * Adds high level functionality to {@link TemplateStateDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class TemplateState extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected TemplateState(final RestContext context, + final TemplateStateDto target) + { + super(context, target); + } + + // Domain operations + + public Double getDownloadingProgress() + { + return target.getDownloadingProgress(); + } + + public String getErrorCause() + { + return target.getErrorCause(); + } + + public String getMasterOvf() + { + return target.getMasterOvf(); + } + + public String getOvfId() + { + return target.getOvfId(); + } + + public TemplateStatusEnumType getStatus() + { + return target.getStatus(); + } + + @Override + public String toString() + { + return "TemplateState [getDownloadingProgress()=" + getDownloadingProgress() + + ", getErrorCause()=" + getErrorCause() + ", getMasterOvf()=" + getMasterOvf() + + ", getOvfId()=" + getOvfId() + ", getStatus()=" + getStatus() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java new file mode 100644 index 0000000000..bfb1b6c86c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java @@ -0,0 +1,509 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link UserDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Users+Resource + */ +public class User extends DomainWrapper +{ + /** Default active value of the user */ + private static final boolean DEFAULT_ACTIVE = true; + + /** The default authentication type. */ + private static final String DEFAULT_AUTH_TYPE = "ABIQUO"; + + /** The default locale for the user. */ + private static final String DEFAULT_LOCALE = "en_US"; + + /** The enterprise where the user belongs. */ + private Enterprise enterprise; + + /** Role of the user. */ + private Role role; + + /** + * Constructor to be used only by the builder. + */ + protected User(final RestContext context, final UserDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/User+resource#Userresource-Deleteanexistinguser + * + */ + public void delete() + { + context.getApi().getEnterpriseApi().deleteUser(target); + target = null; + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/User+resource#Userresource-Createanewuser + */ + public void save() + { + // set role link + target.addLink(new RESTLink("role", role.unwrap().getEditLink().getHref())); + target = context.getApi().getEnterpriseApi().createUser(enterprise.unwrap(), target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/User+resource#Userresource-Updatesanexistinguser + * + */ + public void update() + { + // update role link (if exists) + if (role != null) + { + target.searchLink("role").setHref(role.unwrap().getEditLink().getHref()); + } + + target = context.getApi().getEnterpriseApi().updateUser(target); + } + + public List listPermitedVirtualDatacenters() + { + List ids = extractAvailableDatacenters(); + + // null value means all virtual datacenters all allowed + if (ids.size() == 0) + { + return this.getEnterprise().listVirtualDatacenters(); + } + + ListVirtualDatacenters listVirtualDatacenters = + context.getUtils().getInjector().getInstance(ListVirtualDatacenters.class); + return Lists.newArrayList(listVirtualDatacenters.execute(ids)); + } + + public List listPermitedVirtualDatacenters( + final Predicate filter) + { + return Lists.newLinkedList(filter(listPermitedVirtualDatacenters(), filter)); + } + + public VirtualDatacenter findPermitedVirtualDatacenter(final Predicate filter) + { + return Iterables.getFirst(filter(listPermitedVirtualDatacenters(), filter), null); + } + + /** + * Give access to all virtualdatacenters in the enterprise (requires update). + */ + public void permitAllVirtualDatacenters() + { + setAvailableVirtualDatacenters(null); + } + + /** + * Limits user access ONLY to the virtual datacenters in the list. If the list is empty, user + * will get access to all virtual datacenters. + * + * @param vdc List of virtual datancers from the user's enterprise. + */ + public void setPermitedVirtualDatacenters(final List vdcs) + { + List ids = new ArrayList(); + + for (VirtualDatacenter vdc : vdcs) + { + checkNotNull(vdc.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + VirtualDatacenter.class); + ids.add(vdc.getId()); + } + + setAvailableVirtualDatacenters(ids); + } + + // Parent access + /** + * @see API: http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource- + * RetrieveaEnterprise + */ + public Enterprise getEnterprise() + { + Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); + return wrap(context, Enterprise.class, context.getApi().getEnterpriseApi() + .getEnterprise(enterpriseId)); + } + + // Children access + + public Role getRole() + { + RoleDto role = context.getApi().getAdminApi().getRole(target); + return wrap(context, Role.class, role); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/User+resource#Userresource- + * Retrievethelistofvirtualmachinesbyuser + */ + public List listMachines() + { + VirtualMachinesWithNodeExtendedDto machines = + context.getApi().getEnterpriseApi().listVirtualMachines(target); + return wrap(context, VirtualMachine.class, machines.getCollection()); + } + + public List listMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listMachines(), filter)); + } + + public VirtualMachine findMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listMachines(), filter), null); + } + + // Builder + + public static Builder builder(final RestContext context, + final Enterprise enterprise, final Role role) + { + return new Builder(context, enterprise, role); + } + + public static class Builder + { + private RestContext context; + + private Enterprise enterprise; + + private Role role; + + private String name; + + private String nick; + + private String locale = DEFAULT_LOCALE; + + private String password; + + private String surname; + + private boolean active = DEFAULT_ACTIVE; + + private String email; + + private String description; + + private String authType = DEFAULT_AUTH_TYPE; + + public Builder(final RestContext context, + final Enterprise enterprise, final Role role) + { + super(); + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + checkNotNull(role, ValidationErrors.NULL_RESOURCE + Role.class); + this.context = context; + this.enterprise = enterprise; + this.role = role; + } + + public Builder enterprise(final Enterprise enterprise) + { + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + this.enterprise = enterprise; + return this; + } + + public Builder role(final Role role) + { + this.role = role; + return this; + } + + public Builder name(final String name, final String surname) + { + this.name = name; + this.surname = surname; + return this; + } + + public Builder nick(final String nick) + { + this.nick = nick; + return this; + } + + public Builder locale(final String locale) + { + this.locale = locale; + return this; + } + + public Builder password(final String password) + { + this.password = password; + return this; + } + + public Builder active(final boolean active) + { + this.active = active; + return this; + } + + public Builder email(final String email) + { + this.email = email; + return this; + } + + public Builder description(final String description) + { + this.description = description; + return this; + } + + public Builder authType(final String authType) + { + this.authType = authType; + return this; + } + + public User build() + { + UserDto dto = new UserDto(); + dto.setActive(active); + dto.setAuthType(authType); + dto.setDescription(description); + dto.setEmail(email); + dto.setLocale(locale); + dto.setName(name); + dto.setNick(nick); + dto.setPassword(password); + dto.setSurname(surname); + User user = new User(context, dto); + user.enterprise = enterprise; + user.role = role; + + return user; + } + + public static Builder fromUser(final User in) + { + return User.builder(in.context, in.enterprise, in.role).active(in.isActive()) + .authType(in.getAuthType()).description(in.getDescription()).email(in.getEmail()) + .locale(in.getLocale()).name(in.getName(), in.getSurname()).nick(in.getNick()) + .password(in.getPassword()); + } + } + + // Delegate methods + + public String getAuthType() + { + return target.getAuthType(); + } + + public String getDescription() + { + return target.getDescription(); + } + + public String getEmail() + { + return target.getEmail(); + } + + public Integer getId() + { + return target.getId(); + } + + public String getLocale() + { + return target.getLocale(); + } + + public String getName() + { + return target.getName(); + } + + public String getNick() + { + return target.getNick(); + } + + public String getPassword() + { + return target.getPassword(); + } + + public String getSurname() + { + return target.getSurname(); + } + + public boolean isActive() + { + return target.isActive(); + } + + public void setActive(final boolean active) + { + target.setActive(active); + } + + public void setAuthType(final String authType) + { + target.setAuthType(authType); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + public void setEmail(final String email) + { + target.setEmail(email); + } + + public void setLocale(final String locale) + { + target.setLocale(locale); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setNick(final String nick) + { + target.setNick(nick); + } + + public void setPassword(final String password) + { + target.setPassword(password); + } + + public void setSurname(final String surname) + { + target.setSurname(surname); + } + + public void setRole(final Role role) + { + this.role = role; + } + + // Aux operations + + /** + * Converts the tokenized String of available virtual datacenters provided in the userDto to a + * list of ids. + */ + private List extractAvailableDatacenters() + { + List ids = Lists.newArrayList(); + + if (target.getAvailableVirtualDatacenters() != null) + { + + StringTokenizer st = new StringTokenizer(target.getAvailableVirtualDatacenters(), ","); + + while (st.hasMoreTokens()) + { + ids.add(Integer.parseInt(st.nextToken())); + } + } + + return ids; + } + + private void setAvailableVirtualDatacenters(final List ids) + { + if (ids == null || ids.size() == 0) + { + target.setAvailableVirtualDatacenters(""); + } + else + { + Joiner joiner = Joiner.on(",").skipNulls(); + target.setAvailableVirtualDatacenters(joiner.join(ids)); + } + } + + @Override + public String toString() + { + return "User [id=" + getId() + ", role=" + getRole() + ", authType=" + getAuthType() + + ", description=" + getDescription() + ", email=" + getEmail() + ", locale=" + + getLocale() + ", name=" + getName() + ", nick=" + getNick() + ", password=" + + getPassword() + ", surname=" + getSurname() + ", active=" + isActive() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/options/EnterpriseOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/options/EnterpriseOptions.java new file mode 100644 index 0000000000..fb5bfdbbbe --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/options/EnterpriseOptions.java @@ -0,0 +1,132 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise.options; + +import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query enterprises. + * + * @author Francesc Montserrat + */ +public class EnterpriseOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + EnterpriseOptions options = new EnterpriseOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder extends BaseFilterOptionsBuilder + { + private String idPricingTemplate; + + private Boolean included; + + private String filter; + + private Integer page; + + private Integer results; + + private Boolean network; + + public Builder pricingTemplate(final String idPricingTemplate) + { + this.idPricingTemplate = idPricingTemplate; + return this; + } + + public Builder included(final boolean included) + { + this.included = included; + return this; + } + + public Builder filter(final String filter) + { + this.filter = filter; + return this; + } + + public Builder network(final boolean network) + { + this.network = network; + return this; + } + + public Builder page(final int page) + { + this.page = page; + return this; + } + + public Builder results(final int results) + { + this.results = results; + return this; + } + + public EnterpriseOptions build() + { + EnterpriseOptions options = new EnterpriseOptions(); + + if (idPricingTemplate != null) + { + options.queryParameters.put("idPricingTemplate", String.valueOf(idPricingTemplate)); + } + + if (included != null) + { + options.queryParameters.put("included", String.valueOf(included)); + } + + if (filter != null) + { + options.queryParameters.put("filter", String.valueOf(filter)); + } + + if (page != null) + { + options.queryParameters.put("page", String.valueOf(page)); + } + + if (results != null) + { + options.queryParameters.put("numResults", String.valueOf(results)); + } + + if (network != null) + { + options.queryParameters.put("network", String.valueOf(network)); + } + + return addFilterOptions(options); + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java new file mode 100644 index 0000000000..5bb0791cc0 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java @@ -0,0 +1,393 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.event; + +import java.util.Date; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.SeverityType; +import com.abiquo.server.core.event.EventDto; + +/** + * @author Vivien Mahé + */ +public class Event extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Event(final RestContext context, + final EventDto target) + { + super(context, target); + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getUser() + { + return target.getUser(); + } + + public void setUser(final String user) + { + target.setUser(user); + } + + public String getStacktrace() + { + return target.getStacktrace(); + } + + public void setStacktrace(final String stacktrace) + { + target.setStacktrace(stacktrace); + } + + public String getComponent() + { + return target.getComponent(); + } + + public void setComponent(final String component) + { + target.setComponent(component); + } + + public String getPerformedBy() + { + return target.getPerformedBy(); + } + + public void setPerformedBy(final String performedBy) + { + target.setPerformedBy(performedBy); + } + + public Integer getIdNetwork() + { + return target.getIdNetwork(); + } + + public void setIdNetwork(final Integer idNetwork) + { + target.setIdNetwork(idNetwork); + } + + public String getIdVolume() + { + return target.getIdVolume(); + } + + public void setIdVolume(final String idVolume) + { + target.setIdVolume(idVolume); + } + + public String getStoragePool() + { + return target.getStoragePool(); + } + + public void setStoragePool(final String storagePool) + { + target.setStoragePool(storagePool); + } + + public Date getTimestamp() + { + return target.getTimestamp(); + } + + public void setTimestamp(final Date timestamp) + { + target.setTimestamp(timestamp); + } + + public String getVirtualApp() + { + return target.getVirtualApp(); + } + + public void setVirtualApp(final String virtualApp) + { + target.setVirtualApp(virtualApp); + } + + public String getDatacenter() + { + return target.getDatacenter(); + } + + public void setDatacenter(final String datacenter) + { + target.setDatacenter(datacenter); + } + + public String getActionPerformed() + { + return target.getActionPerformed(); + } + + public void setActionPerformed(final String actionPerformed) + { + target.setActionPerformed(actionPerformed); + } + + public Integer getIdVirtualMachine() + { + return target.getIdVirtualMachine(); + } + + public void setIdVirtualMachine(final Integer idVirtualMachine) + { + target.setIdVirtualMachine(idVirtualMachine); + } + + public String getVirtualDatacenter() + { + return target.getVirtualDatacenter(); + } + + public void setVirtualDatacenter(final String virtualDatacenter) + { + target.setVirtualDatacenter(virtualDatacenter); + } + + public String getEnterprise() + { + return target.getEnterprise(); + } + + public void setEnterprise(final String enterprise) + { + target.setEnterprise(enterprise); + } + + public String getStorageSystem() + { + return target.getStorageSystem(); + } + + public void setStorageSystem(final String storageSystem) + { + target.setStorageSystem(storageSystem); + } + + public Integer getIdPhysicalMachine() + { + return target.getIdPhysicalMachine(); + } + + public void setIdPhysicalMachine(final Integer idPhysicalMachine) + { + target.setIdPhysicalMachine(idPhysicalMachine); + } + + public SeverityType getSeverity() + { + return target.getSeverity(); + } + + public void setSeverity(final SeverityType severity) + { + target.setSeverity(severity); + } + + public Integer getIdStorageSystem() + { + return target.getIdStorageSystem(); + } + + public void setIdStorageSystem(final Integer idStorageSystem) + { + target.setIdStorageSystem(idStorageSystem); + } + + public Integer getIdDatacenter() + { + return target.getIdDatacenter(); + } + + public void setIdDatacenter(final Integer idDatacenter) + { + target.setIdDatacenter(idDatacenter); + } + + public String getNetwork() + { + return target.getNetwork(); + } + + public void setNetwork(final String network) + { + target.setNetwork(network); + } + + public String getPhysicalMachine() + { + return target.getPhysicalMachine(); + } + + public void setPhysicalMachine(final String physicalMachine) + { + target.setPhysicalMachine(physicalMachine); + } + + public String getRack() + { + return target.getRack(); + } + + public void setRack(final String rack) + { + target.setRack(rack); + } + + public Integer getIdVirtualDatacenter() + { + return target.getIdVirtualDatacenter(); + } + + public void setIdVirtualDatacenter(final Integer idVirtualDatacenter) + { + target.setIdVirtualDatacenter(idVirtualDatacenter); + } + + public Integer getIdSubnet() + { + return target.getIdSubnet(); + } + + public void setIdSubnet(final Integer idSubnet) + { + target.setIdSubnet(idSubnet); + } + + public String getVolume() + { + return target.getVolume(); + } + + public void setVolume(final String volume) + { + target.setVolume(volume); + } + + public String getSubnet() + { + return target.getSubnet(); + } + + public void setSubnet(final String subnet) + { + target.setSubnet(subnet); + } + + public Integer getIdUser() + { + return target.getIdUser(); + } + + public void setIdUser(final Integer idUser) + { + target.setIdUser(idUser); + } + + public String getIdStoragePool() + { + return target.getIdStoragePool(); + } + + public void setIdStoragePool(final String idStoragePool) + { + target.setIdStoragePool(idStoragePool); + } + + public Integer getIdRack() + { + return target.getIdRack(); + } + + public void setIdRack(final Integer idRack) + { + target.setIdRack(idRack); + } + + public String getVirtualMachine() + { + return target.getVirtualMachine(); + } + + public void setVirtualMachine(final String virtualMachine) + { + target.setVirtualMachine(virtualMachine); + } + + public Integer getIdVirtualApp() + { + return target.getIdVirtualApp(); + } + + public void setIdVirtualApp(final Integer idVirtualApp) + { + target.setIdVirtualApp(idVirtualApp); + } + + public Integer getIdEnterprise() + { + return target.getIdEnterprise(); + } + + public void setIdEnterprise(final Integer idEnterprise) + { + target.setIdEnterprise(idEnterprise); + } + + @Override + public String toString() + { + return "Event [id=" + getId() + ", idUser=" + getIdUser() + ", user=" + getUser() + + ", idEnterprise=" + getIdEnterprise() + ", enterprise=" + getEnterprise() + + ", actionPerformed=" + getActionPerformed() + ", component=" + getComponent() + + ", idDatacenter=" + getIdDatacenter() + ", datacenter=" + getDatacenter() + + ", idStoragePool=" + getIdStoragePool() + ", storagePool=" + getStoragePool() + + ", idVolume=" + getIdVolume() + ", volume=" + getVolume() + ", idNetwork=" + + getIdNetwork() + ", network=" + getNetwork() + ", idPhysicalMachine=" + + getIdPhysicalMachine() + ", physicalMachine=" + getPhysicalMachine() + ", idRack=" + + getIdRack() + ", rack=" + getRack() + ", idStorageSystem=" + getIdStorageSystem() + + ", storageSystem=" + getStorageSystem() + ", idSubnet=" + getIdSubnet() + ", subnet=" + + getSubnet() + ", idVirtualApp=" + getIdVirtualApp() + ", virtualApp=" + + getVirtualApp() + ", idVirtualDatacenter=" + getIdVirtualDatacenter() + + ", virtualDatacenter=" + getVirtualDatacenter() + ", idVirtualMachine=" + + getIdVirtualMachine() + ", virtualMachine=" + getVirtualMachine() + ", stackstrace=" + + getStacktrace() + ", performedBy=" + getPerformedBy() + ", severity=" + getSeverity() + + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java new file mode 100644 index 0000000000..1a606d9ad1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java @@ -0,0 +1,196 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.event.options; + +import java.util.Date; +import java.util.Map; +import java.util.Map.Entry; + +import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.abiquo.model.enumerator.ComponentType; +import com.abiquo.model.enumerator.EventType; +import com.abiquo.model.enumerator.SeverityType; +import com.google.common.collect.Maps; + +/** + * Available options to query events. + * + * @author Vivien Mahé + */ +public class EventOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + EventOptions options = new EventOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder extends BaseFilterOptionsBuilder + { + private Map filters = Maps.newHashMap(); + + public Builder filters(final Map filters) + { + this.filters = filters; + return this; + } + + public Builder severity(final SeverityType severity) + { + this.filters.put("severity", severity.name()); + return this; + } + + public Builder component(final ComponentType component) + { + this.filters.put("component", component.name()); + return this; + } + + public Builder actionPerformed(final EventType action) + { + this.filters.put("actionperformed", action.name()); + return this; + } + + public Builder datacenterName(final String dc) + { + this.filters.put("datacenter", dc); + return this; + } + + public Builder rackName(final String rack) + { + this.filters.put("rack", rack); + return this; + } + + public Builder physicalMachineName(final String pm) + { + this.filters.put("physicalmachine", pm); + return this; + } + + public Builder storageSystemName(final String ss) + { + this.filters.put("storagesystem", ss); + return this; + } + + public Builder storagePoolName(final String sp) + { + this.filters.put("storagepool", sp); + return this; + } + + public Builder volumeName(final String volume) + { + this.filters.put("volume", volume); + return this; + } + + public Builder networkName(final String network) + { + this.filters.put("network", network); + return this; + } + + public Builder subnetName(final String subnet) + { + this.filters.put("subnet", subnet); + return this; + } + + public Builder enterpriseName(final String ent) + { + this.filters.put("enterprise", ent); + return this; + } + + public Builder userName(final String user) + { + this.filters.put("user", user); + return this; + } + + public Builder virtualDatacenterName(final String vdc) + { + this.filters.put("virtualdatacenter", vdc); + return this; + } + + public Builder virtualAppName(final String vapp) + { + this.filters.put("virtualapp", vapp); + return this; + } + + public Builder virtualMachineName(final String vm) + { + this.filters.put("virtualMachine", vm); + return this; + } + + public Builder performedBy(final String pb) + { + this.filters.put("performedBy", pb); + return this; + } + + public Builder description(final String description) + { + this.filters.put("stacktrace", description); + return this; + } + + public Builder dateFrom(final Date date) + { + this.filters.put("datefrom", String.valueOf(date.getTime())); + return this; + } + + public Builder dateTo(final Date date) + { + this.filters.put("dateTo", String.valueOf(date.getTime())); + return this; + } + + public EventOptions build() + { + EventOptions options = new EventOptions(); + + for (Entry filter : filters.entrySet()) + { + options.queryParameters.put(filter.getKey(), filter.getValue()); + } + + return addFilterOptions(options); + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java new file mode 100644 index 0000000000..1a8ddf58d9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java @@ -0,0 +1,128 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.exception; + +import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +import static org.jclouds.abiquo.predicates.ErrorPredicates.code; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import com.abiquo.model.transport.error.ErrorDto; +import com.abiquo.model.transport.error.ErrorsDto; +import com.google.common.collect.Lists; + +/** + * Abiquo API exception. + * + * @author Francesc Montserrat + * @author Ignasi Barrera + */ +public class AbiquoException extends RuntimeException +{ + /** Serial UID. */ + private static final long serialVersionUID = 1L; + + /** The HTTP statuc. */ + private Status httpStatus; + + /** The errors. */ + private ErrorsDto errors; + + public AbiquoException(final Status httpStatus, final ErrorsDto errors) + { + super(); + this.httpStatus = httpStatus; + this.errors = errors; + } + + /** + * Check if there is an error with the given code. + */ + public boolean hasError(final String code) + { + return any(errors.getCollection(), code(code)); + } + + /** + * Find the first error with the given code. + */ + public ErrorDto findError(final String code) + { + return find(errors.getCollection(), code(code), null); + } + + /** + * Find all errors with the given code. + */ + public List findErrors(final String code) + { + return Lists.newLinkedList(filter(errors.getCollection(), code(code))); + } + + /** + * Get the number of errors. + */ + public int numErrors() + { + return errors.getCollection().size(); + } + + /** + * Get the list of all errors. + */ + public List getErrors() + { + return errors.getCollection(); + } + + /** + * Get the HTTP status code. + */ + public int getHttpStatusCode() + { + return httpStatus.getStatusCode(); + } + + /** + * Get the HTTP status name. + */ + public String getHttpStatusName() + { + return httpStatus.getReasonPhrase(); + } + + /** + * Get the HTTP status. + */ + public Status getHttpStatus() + { + return httpStatus; + } + + @Override + public String getMessage() + { + return errors.toString(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java new file mode 100644 index 0000000000..850bb21b77 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.exception; + +/** + * Exception thrown during domain object building. + * + * @author Ignasi Barrera + */ +public class BuilderException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + /** + * Creates a {@link BuilderException} with the given message. + * + * @param message The message. + */ + public BuilderException(String message) + { + super(message); + } + + /** + * Creates a {@link BuilderException} with the given cause. + * + * @param cause The cause. + */ + public BuilderException(Throwable cause) + { + super(cause); + } + + /** + * Creates a {@link BuilderException} with the given message and cause. + * + * @param message The message. + * @param cause The cause. + */ + public BuilderException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java new file mode 100644 index 0000000000..40f9e8e0ad --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.exception; + +import org.jclouds.abiquo.domain.DomainWrapper; + +import com.abiquo.model.transport.SingleResourceTransportDto; + +/** + * Exception thrown during the wrapping process. + * + * @author Ignasi Barrera + */ +public class WrapperException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + private Class< ? extends DomainWrapper< ? >> wrapperClass; + + private SingleResourceTransportDto target; + + public WrapperException(final Class< ? extends DomainWrapper< ? >> wrapperClass, + final SingleResourceTransportDto target, Throwable cause) + { + super(cause); + this.wrapperClass = wrapperClass; + this.target = target; + } + + @Override + public String getMessage() + { + String msg = + "Could not wrap object [" + target + "] in class " + wrapperClass.getName() + ": "; + return msg + super.getMessage(); + } + + public Class< ? extends DomainWrapper< ? >> getWrapperClass() + { + return wrapperClass; + } + + public void setWrapperClass(Class< ? extends DomainWrapper< ? >> wrapperClass) + { + this.wrapperClass = wrapperClass; + } + + public SingleResourceTransportDto getTarget() + { + return target; + } + + public void setTarget(SingleResourceTransportDto target) + { + this.target = target; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java new file mode 100644 index 0000000000..6ec6c47ce6 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java @@ -0,0 +1,356 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.collect.Iterables.find; + +import java.util.List; +import java.util.StringTokenizer; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.predicates.infrastructure.DatastorePredicates; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.MachineIpmiState; +import com.abiquo.model.enumerator.MachineState; +import com.abiquo.server.core.infrastructure.DatastoresDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; +import com.abiquo.server.core.infrastructure.MachineStateDto; +import com.google.common.base.Predicates; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link MachineDto}. This class defines common methods for + * unmanaged {@link Machine} and managed {@link Blade} physical machines. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/MachineResource + */ +public abstract class AbstractPhysicalMachine extends DomainWrapper +{ + /** The default virtual ram used in MB. */ + protected static final int DEFAULT_VRAM_USED = 1; + + /** The default virtual cpu used in MB. */ + protected static final int DEFAULT_VCPU_USED = 1; + + /** List of available virtual switches provided by discover operation **/ + protected List virtualSwitches; + + /** + * Constructor to be used only by the builder. + */ + protected AbstractPhysicalMachine(final RestContext context, + final MachineDto target) + { + super(context, target); + extractVirtualSwitches(); + } + + public void delete() + { + context.getApi().getInfrastructureApi().deleteMachine(target); + target = null; + } + + public void update() + { + target = context.getApi().getInfrastructureApi().updateMachine(target); + } + + public MachineState check() + { + MachineStateDto dto = + context.getApi().getInfrastructureApi().checkMachineState(target, true); + MachineState state = dto.getState(); + target.setState(state); + return state; + } + + public MachineIpmiState checkIpmi() + { + MachineIpmiStateDto dto = + context.getApi().getInfrastructureApi().checkMachineIpmiState(target); + return dto.getState(); + } + + // Children access + + public List getDatastores() + { + return wrap(context, Datastore.class, target.getDatastores().getCollection()); + } + + public Datastore findDatastore(final String name) + { + return find(getDatastores(), DatastorePredicates.name(name), null); + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getIp() + { + return target.getIp(); + } + + public String getIpmiIp() + { + return target.getIpmiIP(); + } + + public String getIpmiPassword() + { + return target.getIpmiPassword(); + } + + public Integer getIpmiPort() + { + return target.getIpmiPort(); + } + + public String getIpmiUser() + { + return target.getIpmiUser(); + } + + public String getIpService() + { + return target.getIpService(); + } + + public String getName() + { + return target.getName(); + } + + public String getPassword() + { + return target.getPassword(); + } + + public Integer getPort() + { + return target.getPort(); + } + + public MachineState getState() + { + return target.getState(); + } + + public HypervisorType getType() + { + return target.getType(); + } + + public String getUser() + { + return target.getUser(); + } + + public Integer getVirtualCpuCores() + { + return target.getVirtualCpuCores(); + } + + public Integer getVirtualCpusUsed() + { + return target.getVirtualCpusUsed(); + } + + public Integer getVirtualRamInMb() + { + return target.getVirtualRamInMb(); + } + + public Integer getVirtualRamUsedInMb() + { + return target.getVirtualRamUsedInMb(); + } + + public String getVirtualSwitch() + { + return target.getVirtualSwitch(); + } + + public void setDatastores(final List datastores) + { + DatastoresDto datastoresDto = new DatastoresDto(); + datastoresDto.getCollection().addAll(DomainWrapper.unwrap(datastores)); + target.setDatastores(datastoresDto); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + public void setIp(final String ip) + { + target.setIp(ip); + } + + public void setIpmiIp(final String ipmiIp) + { + target.setIpmiIP(ipmiIp); + } + + public void setIpmiPassword(final String ipmiPassword) + { + target.setIpmiPassword(ipmiPassword); + } + + public void setIpmiPort(final Integer ipmiPort) + { + target.setIpmiPort(ipmiPort); + } + + public void setIpmiUser(final String ipmiUser) + { + target.setIpmiUser(ipmiUser); + } + + public void setIpService(final String ipService) + { + target.setIpService(ipService); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setPassword(final String password) + { + target.setPassword(password); + } + + public void setPort(final Integer port) + { + target.setPort(port); + } + + public void setState(final MachineState state) + { + target.setState(state); + } + + public void setType(final HypervisorType type) + { + target.setType(type); + } + + public void setUser(final String user) + { + target.setUser(user); + } + + public void setVirtualCpuCores(final Integer virtualCpuCores) + { + target.setVirtualCpuCores(virtualCpuCores); + } + + public void setVirtualCpusUsed(final Integer virtualCpusUsed) + { + target.setVirtualCpusUsed(virtualCpusUsed); + } + + public void setVirtualRamInMb(final Integer virtualRamInMb) + { + target.setVirtualRamInMb(virtualRamInMb); + } + + public void setVirtualRamUsedInMb(final Integer virtualRamUsedInMb) + { + target.setVirtualRamUsedInMb(virtualRamUsedInMb); + } + + public void setVirtualSwitch(final String virtualSwitch) + { + target.setVirtualSwitch(virtualSwitch); + } + + public String getDescription() + { + return target.getDescription(); + } + + // Aux operations + + /** + * Converts the tokenized String provided by the node collector API to a list of Strings and + * stores it at the attribute switches. + */ + protected void extractVirtualSwitches() + { + StringTokenizer st = new StringTokenizer(getVirtualSwitch(), "/"); + this.virtualSwitches = Lists.newArrayList(); + + while (st.hasMoreTokens()) + { + this.virtualSwitches.add(st.nextToken()); + } + + if (virtualSwitches.size() > 0) + { + this.setVirtualSwitch(virtualSwitches.get(0)); + } + } + + /** + * Returns the virtual switches available. One of them needs to be selected. + */ + public List getAvailableVirtualSwitches() + { + return virtualSwitches; + } + + public String findAvailableVirtualSwitch(final String vswitch) + { + return find(virtualSwitches, Predicates.equalTo(vswitch)); + } + + @Override + public String toString() + { + return "Machine [id=" + getId() + ", ip=" + getIp() + ", ipmiIp=" + getIpmiIp() + + ", ipmiPassword=" + getIpmiPassword() + ", ipmiPort=" + getIpmiPort() + ", ipmiUser=" + + getIpmiUser() + ", ipService=" + getIpService() + ", name=" + getName() + + ", password=" + getPassword() + ", port=" + getPort() + ", state=" + getState() + + ", type=" + getType() + ", user=" + getUser() + ", virtualCpuCores=" + + getVirtualCpuCores() + ", virtualCpusUsed=" + getVirtualCpusUsed() + + ", getVirtualRamInMb()=" + getVirtualRamInMb() + ", virtualRamUsedInMb=" + + getVirtualRamUsedInMb() + ", virtualSwitch=" + getVirtualSwitch() + ", description=" + + getDescription() + ", availableVirtualSwitches=" + getAvailableVirtualSwitches() + + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java new file mode 100644 index 0000000000..db2ca35b64 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java @@ -0,0 +1,176 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.BladeLocatorLedDto; +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to a {@link MachineDto} managed in a UCS rack. This resource allows + * you to access blades in managed racks in the cloud infrastructure. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/MachineResource + */ +public class Blade extends AbstractPhysicalMachine +{ + /** The rack where the machine belongs. */ + protected UcsRackDto rack; + + /** + * Constructor to be used only by the builder. + */ + protected Blade(final RestContext context, final MachineDto target) + { + super(context, target); + } + + // Parent access + + /** + * Retrieve the UCS rack where the blade is. + * + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaUCSRack + */ + public ManagedRack getRack() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.RACK), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.RACK); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), TypeLiteral.get(UcsRackDto.class)); + + return wrap(context, ManagedRack.class, parser.apply(response)); + } + + /** + * Retrieve the logic server associated with this machine in the Cisco UCS rack. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrieveslogicserverassociatedwithamachineinaCiscoUCS + */ + public LogicServer getLogicServer() + { + LogicServerDto server = context.getApi().getInfrastructureApi().getLogicServer(target); + + return wrap(context, LogicServer.class, server); + } + + // Actions + + /** + * Turn the blade associated to the provided logic server off. The blade must belong to a Logic + * Server. This action sets the state of a given machine to STOPPED. Also sends a stop request + * to Cisco UCS to shut down the machine. The given machine must be a Physical Machine inside a + * Cisco UCS. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * PoweroffanexistingmachineinCiscoUCS + */ + public void powerOff() + { + context.getApi().getInfrastructureApi().powerOff(target); + } + + /** + * Turn the blade associated to the provided logic server on. The machine must belong to an UCS + * Rack. The blade must belong to a Logic Server. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * PoweronanexistingmachineinCiscoUCS + */ + public void powerOn() + { + context.getApi().getInfrastructureApi().powerOn(target); + } + + /** + * Turn blade led on. The machine must belong to an UCS Rack. The blade must belong to a Logic + * Server. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * LightoffthelocatorledofanexistingmachineinaCiscoUCS + */ + public void ledOn() + { + context.getApi().getInfrastructureApi().ledOn(target); + } + + /** + * Turn blade led off. The machine must belong to an UCS Rack. The blade must belong to a Logic + * Server. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource- + * LightoffthelocatorledofanexistingmachineinaCiscoUCS + */ + public void ledOff() + { + context.getApi().getInfrastructureApi().ledOff(target); + } + + /** + * Retrieve the led locator information as a {@link BladeLocatorLed}. + * + * @return Blade locator led representation. + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * Retrievethelocatorledoftheblade + */ + public BladeLocatorLed getLocatorLed() + { + BladeLocatorLedDto led = context.getApi().getInfrastructureApi().getLocatorLed(target); + + return wrap(context, BladeLocatorLed.class, led); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java new file mode 100644 index 0000000000..cd74bd64e6 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java @@ -0,0 +1,81 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.BladeLocatorLedDto; + +/** + * Adds high level functionality to {@link BladeLocatorLedDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * Retrievethelocatorledoftheblade + */ +@EnterpriseEdition +public class BladeLocatorLed extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected BladeLocatorLed(final RestContext context, final BladeLocatorLedDto target) + { + super(context, target); + } + + // Delegate Methods + + public String getAdminStatus() + { + return target.getAdminStatus(); + } + + public String getBladeDn() + { + return target.getBladeDn(); + } + + public String getColor() + { + return target.getColor(); + } + + public String getDn() + { + return target.getDn(); + } + + @Override + public String toString() + { + return "BladeLocatorLed [Dn=" + getDn() + ", BladeDn=" + getBladeDn() + ", Color=" + + getColor() + ", AdminStatus=" + getAdminStatus() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java new file mode 100644 index 0000000000..0894ba2840 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java @@ -0,0 +1,1174 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.Limits; +import org.jclouds.abiquo.domain.infrastructure.options.DatacenterOptions; +import org.jclouds.abiquo.domain.infrastructure.options.IpmiOptions; +import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; +import org.jclouds.abiquo.domain.network.Network; +import org.jclouds.abiquo.domain.network.options.NetworkOptions; +import org.jclouds.abiquo.reference.AbiquoEdition; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.MachineIpmiState; +import com.abiquo.model.enumerator.MachineState; +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.model.enumerator.VlanTagAvailabilityType; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.abiquo.server.core.cloud.HypervisorTypeDto; +import com.abiquo.server.core.cloud.HypervisorTypesDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; +import com.abiquo.server.core.infrastructure.MachineStateDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.RacksDto; +import com.abiquo.server.core.infrastructure.RemoteServicesDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.abiquo.server.core.infrastructure.UcsRacksDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VlanTagAvailabilityDto; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesMetadataDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link DatacenterDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/DatacenterResource + */ +public class Datacenter extends DomainWrapper +{ + /** + * IP address of the datacenter (used to create all remote services with the same ip). + */ + private String ip; + + /** + * Indicates the Abiquo edition to create the available remote services. + * + * @see API: + * http://community.abiquo.com/display/ABI20/Introduction+-+The+Abiquo+Platform + */ + private AbiquoEdition edition; + + /** + * Constructor to be used only by the builder. + */ + protected Datacenter(final RestContext context, + final DatacenterDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * DeleteanexistingDatacenter + */ + public void delete() + { + context.getApi().getInfrastructureApi().deleteDatacenter(target); + target = null; + } + + /** + * Create a datacenter in Abiquo. This method will perform several calls to the API if remote + * services have been defined in the builder. Different remote services will be created + * depending on the {@link AbiquoEdition}. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * CreateanewDatacenter + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * CreateaRemoteService + */ + public void save() + { + // Datacenter must be persisted first, so links get populated in the target object + target = context.getApi().getInfrastructureApi().createDatacenter(target); + + // If remote services data is set, create remote services. + if (ip != null && edition != null) + { + createRemoteServices(); + } + } + + /** + * Update datacenter information in the server with the data from this datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Updateanexistingdatacenter + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateDatacenter(target); + } + + /** + * The cloud administrator will find it useful to know if a VLAN Tag is already assigned before + * creating a new Public or External Network. This method provides this functionality: Check if + * a tag is available inside the Datacenter. Please refer link for more information. + * + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Checkthetagavailability + * @return Availability state of the tag. + */ + public VlanTagAvailabilityType checkTagAvailability(final int tag) + { + VlanTagAvailabilityDto availability = + context.getApi().getInfrastructureApi().checkTagAvailability(target, tag); + + return availability.getAvailable(); + } + + // Children access + + /** + * Retrieve the list of unmanaged racks in this datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofRacks + * @return List of unmanaged racks in this datacenter. + */ + public List listRacks() + { + RacksDto racks = context.getApi().getInfrastructureApi().listRacks(target); + return wrap(context, Rack.class, racks.getCollection()); + } + + /** + * Retrieve a filtered list of unmanaged racks in this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofRacks + * @return Filtered list of unmanaged racks in this datacenter. + */ + public List listRacks(final Predicate filter) + { + return Lists.newLinkedList(filter(listRacks(), filter)); + } + + /** + * Retrieve the first unmanaged rack matching the filter within the list of racks in this + * datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofRacks + * @return First unmanaged rack matching the filter or null if the is none. + */ + public Rack findRack(final Predicate filter) + { + return Iterables.getFirst(filter(listRacks(), filter), null); + } + + /** + * Retrieve a single unmanaged rack. + * + * @param id Unique ID of the rack in this datacenter. + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaRack + * @return Unmanaged rack with the given id or null if it does not exist. + */ + public Rack getRack(final Integer id) + { + RackDto rack = context.getApi().getInfrastructureApi().getRack(target, id); + return wrap(context, Rack.class, rack); + } + + /** + * Retrieve the list of managed racks in this datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofUCSracks + * @return List of managed racks in this datacenter. + */ + @EnterpriseEdition + public List listManagedRacks() + { + UcsRacksDto racks = context.getApi().getInfrastructureApi().listManagedRacks(target); + return wrap(context, ManagedRack.class, racks.getCollection()); + } + + /** + * Retrieve a filtered list of managed racks in this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofUCSracks + * @return Filtered list of managed racks in this datacenter. + */ + @EnterpriseEdition + public List listManagedRacks(final Predicate filter) + { + return Lists.newLinkedList(filter(listManagedRacks(), filter)); + } + + /** + * Retrieve the first managed rack matching the filter within the list of racks in this + * datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofUCSracks + * @return First managed rack matching the filter or null if there is none. + */ + @EnterpriseEdition + public ManagedRack findManagedRack(final Predicate filter) + { + return Iterables.getFirst(filter(listManagedRacks(), filter), null); + } + + /** + * Retrieve a single managed rack. + * + * @param id Unique ID of the rack in this datacenter. + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaUCSRack + * @return Unmanaged rack with the given id or null if it does not exist. + */ + @EnterpriseEdition + public ManagedRack getManagedRack(final Integer id) + { + UcsRackDto rack = context.getApi().getInfrastructureApi().getManagedRack(target, id); + return wrap(context, ManagedRack.class, rack); + } + + /** + * Retrieve the list of supported storage devices. + *

+ * This method will get the list of the storage devices that are supported in the datacenter. + * + * @return List of supported storage devices. This list has only the default information for the + * storage devices, such as the management and iscsi ports, or the default credentials + * to access the device. + */ + @EnterpriseEdition + public List listSupportedStorageDevices() + { + StorageDevicesMetadataDto devices = + context.getApi().getInfrastructureApi().listSupportedStorageDevices(target); + return wrap(context, StorageDeviceMetadata.class, devices.getCollection()); + } + + /** + * Retrieve the list of supported storage devices matching the filter. + *

+ * This method will get the list of the storage devices that are supported in the datacenter. + * + * @param filter Filter to be applied to the list. + * @return List of supported storage devices. This list has only the default information for the + * storage devices, such as the management and iscsi ports, or the default credentials + * to access the device. + */ + @EnterpriseEdition + public List listSupportedStorageDevices( + final Predicate filter) + { + return Lists.newLinkedList(filter(listSupportedStorageDevices(), filter)); + } + + /** + * Retrieve a single supported storage devices matching the filter. + * + * @param filter Filter to be applied to the list. + * @return First supported storage device matching the filter or null if there is + * none. + */ + @EnterpriseEdition + public StorageDeviceMetadata findSupportedStorageDevice( + final Predicate filter) + { + return Iterables.getFirst(filter(listSupportedStorageDevices(), filter), null); + } + + /** + * Retrieve the list of storage devices in this datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrievethelistofstoragedevices + * @return List of storage devices in this datacenter. + */ + @EnterpriseEdition + public List listStorageDevices() + { + StorageDevicesDto devices = + context.getApi().getInfrastructureApi().listStorageDevices(target); + return wrap(context, StorageDevice.class, devices.getCollection()); + } + + /** + * Retrieve a filtered list of storage devices in this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrievethelistofstoragedevices + * @return Filtered list of storage devices in this datacenter. + */ + @EnterpriseEdition + public List listStorageDevices(final Predicate filter) + { + return Lists.newLinkedList(filter(listStorageDevices(), filter)); + } + + /** + * Retrieve the first storage device matching the filter within the list of devices in this + * datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrievethelistofstoragedevices + * @return First storage device matching the filter or null if there is none. + */ + @EnterpriseEdition + public StorageDevice findStorageDevice(final Predicate filter) + { + return Iterables.getFirst(filter(listStorageDevices(), filter), null); + } + + /** + * Retrieve a single storage device. + * + * @param id Unique ID of the storage device in this datacenter. + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrieveastoragedevice + * @return Storage device with the given id or null if it does not exist. + */ + @EnterpriseEdition + public StorageDevice getStorageDevice(final Integer id) + { + StorageDeviceDto device = + context.getApi().getInfrastructureApi().getStorageDevice(target, id); + return wrap(context, StorageDevice.class, device); + } + + /** + * Retrieve the list of remote services of this datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * RetrievealistofRemoteServices + * @return List of remote services in this datacenter. + */ + public List listRemoteServices() + { + RemoteServicesDto remoteServices = + context.getApi().getInfrastructureApi().listRemoteServices(target); + return wrap(context, RemoteService.class, remoteServices.getCollection()); + } + + /** + * Retrieve a filtered list of remote services of this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * RetrievealistofRemoteServices + * @return Filtered list of remote services in this datacenter. + */ + public List listRemoteServices(final Predicate filter) + { + return Lists.newLinkedList(filter(listRemoteServices(), filter)); + } + + /** + * Retrieve the first remote service matching the filter within the list of remote services in + * this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * RetrievealistofRemoteServices + * @return First remote service matching the filter or null if there is none. + */ + public RemoteService findRemoteService(final Predicate filter) + { + return Iterables.getFirst(filter(listRemoteServices(), filter), null); + } + + private void createRemoteServices() + { + if (this.edition == AbiquoEdition.ENTERPRISE) + { + createRemoteService(RemoteServiceType.BPM_SERVICE); + createRemoteService(RemoteServiceType.DHCP_SERVICE); + createRemoteService(RemoteServiceType.STORAGE_SYSTEM_MONITOR); + } + + createRemoteService(RemoteServiceType.APPLIANCE_MANAGER); + createRemoteService(RemoteServiceType.VIRTUAL_SYSTEM_MONITOR); + createRemoteService(RemoteServiceType.NODE_COLLECTOR); + createRemoteService(RemoteServiceType.VIRTUAL_FACTORY); + } + + private void createRemoteService(final RemoteServiceType type) + { + RemoteService.builder(context, this).type(type).ip(this.ip).build().save(); + } + + /** + * Retrieve the list of datacenter limits by all enterprises. The Datacenter Limits resource + * allows you to assign datacenters and allocated resources in them to be used by an enterprise. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievelimitsbydatacenter + * @return List of datacenter limits by all enterprises. + */ + public List listLimits() + { + DatacentersLimitsDto dto = + context.getApi().getInfrastructureApi().listLimits(this.unwrap()); + return DomainWrapper.wrap(context, Limits.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of datacenter limits by enterprises. The Datacenter Limits resource + * allows you to assign datacenters and allocated resources in them to be used by an enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievelimitsbydatacenter + * @return Filtered list of datacenter limits by all enterprises. + */ + public List listLimits(final Predicate filter) + { + return Lists.newLinkedList(filter(listLimits(), filter)); + } + + /** + * Retrieve the first datacenter limits matching the filter within the list of datacenter limits + * by enterprise. The Datacenter Limits resource allows you to assign datacenters and allocated + * resources in them to be used by an enterprise. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievelimitsbydatacenter + * @return First datacenter limits matching the filter or null if there is none. + */ + public Limits findLimits(final Predicate filter) + { + return Iterables.getFirst(filter(listLimits(), filter), null); + } + + /** + * Retrieve the list of tiers in ths datacenter. + * + * @see API: + * http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers + * + * @return List of tiers in this datacenter. + */ + @EnterpriseEdition + public List listTiers() + { + TiersDto dto = context.getApi().getInfrastructureApi().listTiers(this.unwrap()); + return DomainWrapper.wrap(context, Tier.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of tiers in this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: + * http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers + * + * @return Filtered list of tiers in this datacenter. + */ + @EnterpriseEdition + public List listTiers(final Predicate filter) + { + return Lists.newLinkedList(filter(listTiers(), filter)); + } + + /** + * Retrieve the first tier matching the filter within the list of tiers in this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrievethelistofstoragedevices + * @return First tier matching the filter or null if there is none. + */ + @EnterpriseEdition + public Tier findTier(final Predicate filter) + { + return Iterables.getFirst(filter(listTiers(), filter), null); + } + + /** + * Retrieve the list of public, external and unmanaged networks in this datacenter. + * + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Getthelistofpublicnetworks + * @return List of public, external and unmanaged networks in this datacenter. + */ + public List> listNetworks() + { + VLANNetworksDto networks = context.getApi().getInfrastructureApi().listNetworks(target); + return Network.wrapNetworks(context, networks.getCollection()); + } + + /** + * Retrieve a filtered list of public, external and unmanaged networks in this datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Getthelistofpublicnetworks + */ + public List> listNetworks(final Predicate> filter) + { + return Lists.newLinkedList(filter(listNetworks(), filter)); + } + + /** + * Retrieve the first network matching the filter within the list of networks. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Getthelistofpublicnetworks + * @return Filtered list of public, external and unmanaged networks in this datacenter. + */ + public Network< ? > findNetwork(final Predicate> filter) + { + return Iterables.getFirst(filter(listNetworks(), filter), null); + } + + /** + * Retrieve the list of networks of this datacenter matching the given type. + * + * @param type Network type filter. + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Getthelistofpublicnetworks + * @return List of networks of this datacenter matching the given type. + */ + public List> listNetworks(final NetworkType type) + { + NetworkOptions options = NetworkOptions.builder().type(type).build(); + VLANNetworksDto networks = + context.getApi().getInfrastructureApi().listNetworks(target, options); + return Network.wrapNetworks(context, networks.getCollection()); + } + + /** + * Retrieve a filtered list of networks of this datacenter matching the given type. + * + * @param type Network type filter. + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Getthelistofpublicnetworks + * @return Filtered list of networks of this datacenter matching the given type. + */ + public List> listNetworks(final NetworkType type, + final Predicate> filter) + { + return Lists.newLinkedList(filter(listNetworks(type), filter)); + } + + /** + * Retrieve the first network of the given type matching the filter. + * + * @param type Network type filter. + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource- + * Getthelistofpublicnetworks + * @return First network of the given type matching the filter or null if there is + * none. + */ + public Network< ? > findNetwork(final NetworkType type, final Predicate> filter) + { + return Iterables.getFirst(filter(listNetworks(type), filter), null); + } + + /** + * Retrieve a single public, external or unmanaged network from this datacenter. + * {@link org.jclouds.abiquo.domain.network.Network#toExternalNetwork}, + * {@link org.jclouds.abiquo.domain.network.Network#toPublicNetwork} and + * {@link org.jclouds.abiquo.domain.network.Network#toUnmanagedNetwork} can be used to convert + * the Network into the appropiate domain object. + * + * @param id Unique ID of the network in this datacenter. + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#PublicNetworkResource# + * PublicNetworkResource-Getthelistofpublicnetworks + * @return Network with the given id or null if it does not exist. + */ + public Network< ? > getNetwork(final Integer id) + { + VLANNetworkDto network = context.getApi().getInfrastructureApi().getNetwork(target, id); + return Network.wrapNetwork(context, network); + } + + // Actions + + /** + * Retrieve the hypervisor type from remote machine. + * + * @param ip IP address of the physical machine. + * @see API: + * @return Hypervisor type of the remote machine. + * @throws Exception If the hypervisor type information cannot be retrieved. + */ + public HypervisorType getHypervisorType(final String ip) + { + DatacenterOptions options = DatacenterOptions.builder().ip(ip).build(); + + String type = + context.getApi().getInfrastructureApi().getHypervisorTypeFromMachine(target, options); + + return HypervisorType.valueOf(type); + } + + /** + * Retrieve the list of available hypervisor types in the datacenter. + * + * @see API: + * @return List of available hypervisor types in the datacenter. + */ + @EnterpriseEdition + public List listAvailableHypervisors() + { + HypervisorTypesDto types = + context.getApi().getInfrastructureApi().getHypervisorTypes(target); + + return getHypervisorTypes(types); + } + + /** + * Retrieve a filtered list of available hypervisor types in the datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: + * @return Filtered list of available hypervisor types in the datacenter. + */ + @EnterpriseEdition + public List listAvailableHypervisors(final Predicate filter) + { + return Lists.newLinkedList(filter(listAvailableHypervisors(), filter)); + } + + /** + * Retrieve the first hypervisor type matching the filter within the list of types. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveavailablehypervisortypes + * @return First hypervisor type matching the filter or null if there is none. + */ + @EnterpriseEdition + public HypervisorType findHypervisor(final Predicate filter) + { + return Iterables.getFirst(filter(listAvailableHypervisors(), filter), null); + } + + private List getHypervisorTypes(final HypervisorTypesDto dtos) + { + List types = Lists.newArrayList(); + + for (HypervisorTypeDto dto : dtos.getCollection()) + { + types.add(HypervisorType.fromId(dto.getId())); + } + + return types; + } + + /** + * Searches a remote machine and retrieves an Machine object with its information. + * + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @return A physical machine if found or null. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveremotemachineinformation + */ + public Machine discoverSingleMachine(final String ip, final HypervisorType hypervisorType, + final String user, final String password) + { + return discoverSingleMachine(ip, hypervisorType, user, password, hypervisorType.defaultPort); + } + + /** + * Searches a remote machine and retrieves an Machine object with its information. + * + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @param port Port to connect. + * @return A physical machine if found or null. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveremotemachineinformation + */ + public Machine discoverSingleMachine(final String ip, final HypervisorType hypervisorType, + final String user, final String password, final int port) + { + MachineDto dto = + context + .getApi() + .getInfrastructureApi() + .discoverSingleMachine(target, ip, hypervisorType, user, password, + MachineOptions.builder().port(port).build()); + + // Credentials are not returned by the API + dto.setUser(user); + dto.setPassword(password); + + return wrap(context, Machine.class, dto); + } + + /** + * Searches multiple remote machines and retrieves an Machine list with its information. + * + * @param ipFrom IP address of the remote first hypervisor to check. + * @param ipTo IP address of the remote last hypervisor to check. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievealistofremotemachineinformation + */ + public List discoverMultipleMachines(final String ipFrom, final String ipTo, + final HypervisorType hypervisorType, final String user, final String password) + { + return discoverMultipleMachines(ipFrom, ipTo, hypervisorType, user, password, + hypervisorType.defaultPort); + } + + /** + * Searches multiple remote machines and retrieves an Machine list with its information. + * + * @param ipFrom IP address of the remote first hypervisor to check. + * @param ipTo IP address of the remote last hypervisor to check. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @param port Port to connect. + * @return The physical machine list. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievealistofremotemachineinformation + */ + public List discoverMultipleMachines(final String ipFrom, final String ipTo, + final HypervisorType hypervisorType, final String user, final String password, + final int port) + { + MachinesDto dto = + context + .getApi() + .getInfrastructureApi() + .discoverMultipleMachines(target, ipFrom, ipTo, hypervisorType, user, password, + MachineOptions.builder().port(port).build()); + + // Credentials are not returned by the API + for (MachineDto machine : dto.getCollection()) + { + machine.setUser(user); + machine.setPassword(password); + } + + return wrap(context, Machine.class, dto.getCollection()); + } + + /** + * Check the state of a remote machine. This feature is used to check the state from a remote + * machine giving its location, user, password and hypervisor type. This machine does not need + * to be managed by Abiquo. + * + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine state if the machine is found or null. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Checkthestatefromremotemachine + */ + public MachineState checkMachineState(final String ip, final HypervisorType hypervisorType, + final String user, final String password) + { + return checkMachineState(ip, hypervisorType, user, password, + MachineOptions.builder().port(hypervisorType.defaultPort).build()); + } + + /** + * Check the state of a remote machine. This feature is used to check the state from a remote + * machine giving its location, user, password and hypervisor type. This machine does not need + * to be managed by Abiquo. + * + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @param options. + * @return The physical machine state if the machine is found or null. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Checkthestatefromremotemachine + */ + public MachineState checkMachineState(final String ip, final HypervisorType hypervisorType, + final String user, final String password, final MachineOptions options) + { + MachineStateDto dto = + context.getApi().getInfrastructureApi() + .checkMachineState(target, ip, hypervisorType, user, password, options); + + return dto.getState(); + } + + /** + * Check the ipmi configuration state of a remote machine. This feature is used to check the + * ipmi configuration state from a remote machine giving its location, user and password. This + * machine does not need to be managed by Abiquo. + * + * @param ip IP address of the remote hypervisor to connect. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine state if the machine is found or null. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Checktheipmistatefromremotemachine + */ + public MachineIpmiState checkMachineIpmiState(final String ip, final String user, + final String password) + { + MachineIpmiStateDto dto = + context.getApi().getInfrastructureApi() + .checkMachineIpmiState(target, ip, user, password); + return dto.getState(); + } + + /** + * Check the ipmi configuration state of a remote machine. This feature is used to check the + * ipmi configuration state from a remote machine giving its location, user and password. This + * machine does not need to be managed by Abiquo. + * + * @param ip IP address of the remote hypervisor to connect. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine state if the machine is found or null. + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Checktheipmistatefromremotemachine + */ + public MachineIpmiState checkMachineIpmiState(final String ip, final String user, + final String password, final IpmiOptions options) + { + MachineIpmiStateDto dto = + context.getApi().getInfrastructureApi() + .checkMachineIpmiState(target, ip, user, password, options); + return dto.getState(); + } + + /** + * Retrieve the list of virtual machine templates in the repository of this datacenter. + * + * @param enterprise Owner of the templates. + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineTemplateResource# + * VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates + * @return List of virtual machine templates in the repository of this datacenter. + */ + public List listTemplatesInRepository(final Enterprise enterprise) + { + VirtualMachineTemplatesDto dto = + context.getApi().getVirtualMachineTemplateApi() + .listVirtualMachineTemplates(enterprise.getId(), target.getId()); + return wrap(context, VirtualMachineTemplate.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of virtual machine templates in the repository of this datacenter. + * + * @param enterprise Owner of the templates. + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineTemplateResource# + * VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates + * @return Filtered list of virtual machine templates in the repository of this datacenter. + */ + public List listTemplatesInRepository(final Enterprise enterprise, + final Predicate filter) + { + return Lists.newLinkedList(filter(listTemplatesInRepository(enterprise), filter)); + } + + /** + * Retrieve the first virtual machine template within the list of templates of this datacenter + * from the given enterprise. + * + * @param enterprise Owner of the templates. + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineTemplateResource# + * VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates + * @return First virtual machine template matching the filter or null if there is + * none. + */ + public VirtualMachineTemplate findTemplateInRepository(final Enterprise enterprise, + final Predicate filter) + { + return Iterables.getFirst(filter(listTemplatesInRepository(enterprise), filter), null); + } + + /** + * Retrieve a single virtual machine template in of this datacenter from the given enterprise. + * + * @param enterprise Owner of the templates. + * @param id Unique ID of the template in the datacenter repository for the given enterprise. + * @see API: http://community.abiquo.com/display/ABI20/VirtualMachineTemplateResource# + * VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates + * @return Virtual machine template with the given id in the given enterpriess or + * null if it does not exist. + */ + public VirtualMachineTemplate getTemplateInRepository(final Enterprise enterprise, + final Integer id) + { + VirtualMachineTemplateDto template = + context.getApi().getVirtualMachineTemplateApi() + .getVirtualMachineTemplate(enterprise.getId(), target.getId(), id); + return wrap(context, VirtualMachineTemplate.class, template); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder + { + private RestContext context; + + private String name; + + private String location; + + private String ip; + + private AbiquoEdition edition; + + public Builder(final RestContext context) + { + super(); + this.context = context; + } + + public Builder remoteServices(final String ip, final AbiquoEdition edition) + { + this.ip = ip; + this.edition = edition; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder location(final String location) + { + this.location = location; + return this; + } + + public Datacenter build() + { + DatacenterDto dto = new DatacenterDto(); + dto.setName(name); + dto.setLocation(location); + Datacenter datacenter = new Datacenter(context, dto); + datacenter.edition = edition; + datacenter.ip = ip; + return datacenter; + } + + public static Builder fromDatacenter(final Datacenter in) + { + return Datacenter.builder(in.context).name(in.getName()).location(in.getLocation()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getLocation() + { + return target.getLocation(); + } + + public String getName() + { + return target.getName(); + } + + public void setLocation(final String location) + { + target.setLocation(location); + } + + public void setName(final String name) + { + target.setName(name); + } + + public String getUUID() + { + return target.getUuid(); + } + + @Override + public String toString() + { + return "Datacenter [id=" + getId() + ", location=" + getLocation() + ", name=" + getName() + + ", uuid=" + getUUID() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java new file mode 100644 index 0000000000..65709d48cb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java @@ -0,0 +1,101 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.DatastoreDto; + +/** + * Adds high level functionality to {@link DatastoreDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class Datastore extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. This resource cannot be created. + */ + private Datastore(final RestContext context, final DatastoreDto target) + { + super(context, target); + } + + // Delegate methods + + public String getDatastoreUUID() + { + return target.getDatastoreUUID(); + } + + public String getDirectory() + { + return target.getDirectory(); + } + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public String getRootPath() + { + return target.getRootPath(); + } + + public long getSize() + { + return target.getSize(); + } + + public long getUsedSize() + { + return target.getUsedSize(); + } + + public boolean isEnabled() + { + return target.isEnabled(); + } + + public void setEnabled(final boolean enabled) + { + target.setEnabled(enabled); + } + + @Override + public String toString() + { + return "Datastore [id=" + getId() + ", uuid=" + getDatastoreUUID() + ", directory=" + + getDirectory() + ", name=" + getName() + ", rootPath=" + getRootPath() + ", size=" + + getSize() + ", usedSize=" + getUsedSize() + ", enabled=" + isEnabled() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java new file mode 100644 index 0000000000..bdf59459e0 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.FsmDto; + +/** + * Adds high level functionality to {@link FsmDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Rack+Resource + */ +@EnterpriseEdition +public class Fsm extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Fsm(final RestContext context, final FsmDto target) + { + super(context, target); + } + + // Delegate Methods + + public String getDescription() + { + return target.getDescription(); + } + + public String getDn() + { + return target.getDn(); + } + + public String getError() + { + return target.getError(); + } + + public String getProgress() + { + return target.getProgress(); + } + + public String getStatus() + { + return target.getStatus(); + } + + @Override + public String toString() + { + return "Fsm [Dn=" + getDn() + ", Description=" + getDescription() + ", Error=" + getError() + + ", Progress=" + getProgress() + ", Status=" + getStatus() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java new file mode 100644 index 0000000000..8969b85b77 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java @@ -0,0 +1,102 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.LogicServerPolicyDto; + +/** + * Adds high level functionality to {@link LogicServerDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Rack+Resource + */ +@EnterpriseEdition +public class LogicServer extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected LogicServer(final RestContext context, final LogicServerDto target) + { + super(context, target); + } + + // Delegate Methods + + public String getName() + { + return target.getName(); + } + + public void setType(final String value) + { + target.setType(value); + } + + public String getAssociated() + { + return target.getAssociated(); + } + + public String getType() + { + return target.getType(); + } + + public String getAssociatedTo() + { + return target.getAssociatedTo(); + } + + public String getDescription() + { + return target.getDescription(); + } + + public void setDescription(final String value) + { + target.setDescription(value); + } + + public List getCollection() + { + return target.getCollection(); + } + + @Override + public String toString() + { + return "LogicServer [name=" + getName() + ", associated=" + getAssociated() + ", type=" + + getType() + ", associatedTo=" + getAssociatedTo() + ", description=" + + getDescription() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java new file mode 100644 index 0000000000..d3616852f9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java @@ -0,0 +1,549 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; +import org.jclouds.abiquo.predicates.infrastructure.DatastorePredicates; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.MachineState; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.DatastoresDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachineStateDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to {@link MachineDto}. This resource allows you to manage physical + * machines in the cloud infrastructure. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/MachineResource + */ +public class Machine extends AbstractPhysicalMachine +{ + /** The rack where the machine belongs. */ + protected Rack rack; + + /** + * Constructor to be used only by the builder. + */ + protected Machine(final RestContext context, final MachineDto target) + { + super(context, target); + } + + /** + * Create a new physical machine in Abiquo. The best way to create a machine if first calling + * {@link Datacenter#discoverSingleMachine} or {@link Datacenter#discoverMultipleMachines}. This + * will return a new {@link Machine}. The following steps are: enabling a datastore, selecting a + * virtual switch and choosing a rack. Refer link for more information. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveremotemachineinformation + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * Createamachine + */ + public void save() + { + target = context.getApi().getInfrastructureApi().createMachine(rack.unwrap(), target); + } + + @Override + public MachineState check() + { + MachineStateDto dto = + context.getApi().getInfrastructureApi().checkMachineState(target, true); + MachineState state = dto.getState(); + target.setState(state); + return state; + } + + // Parent access + /** + * Retrieve the unmanaged rack where the machine is. + * + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaRack + */ + public Rack getRack() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.RACK), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.RACK); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), TypeLiteral.get(RackDto.class)); + + return wrap(context, Rack.class, parser.apply(response)); + } + + // Children access + + @Override + public List getDatastores() + { + return wrap(context, Datastore.class, target.getDatastores().getCollection()); + } + + @Override + public Datastore findDatastore(final String name) + { + return find(getDatastores(), DatastorePredicates.name(name), null); + } + + /** + * Gets the list of virtual machines in the physical machine. + * + * @return The list of virtual machines in the physical machine. + * @see API: http://community.abiquo.com/display/ABI20/Machine+Resource#MachineResource- + * Retrievethelistofvirtualmachinesbymachine'shypervisor + */ + public List listVirtualMachines() + { + MachineOptions options = MachineOptions.builder().sync(false).build(); + VirtualMachinesWithNodeExtendedDto vms = + context.getApi().getInfrastructureApi().listVirtualMachinesByMachine(target, options); + return wrap(context, VirtualMachine.class, vms.getCollection()); + } + + /** + * Gets the list of virtual machines in the physical machine matching the given filter. + * + * @param filter The filter to apply. + * @return The list of virtual machines in the physical machine matching the given filter. + */ + public List listVirtualMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualMachines(), filter)); + } + + /** + * Gets a single virtual machine in the physical machine matching the given filter. + * + * @param filter The filter to apply. + * @return The virtual machine or null if none matched the given filter. + */ + public VirtualMachine findVirtualMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualMachines(), filter), null); + } + + /** + * Gets the list of virtual machines in the physical machine sinchronizing virtual machines from + * remote hypervisor with abiquo's database. + * + * @return The list of virtual machines in the physical machine. + * @see API: http://community.abiquo.com/display/ABI20/Machine+Resource#MachineResource- + * Retrievethelistofvirtualmachinesbymachine'shypervisor + */ + public List listRemoteVirtualMachines() + { + MachineOptions options = MachineOptions.builder().sync(true).build(); + VirtualMachinesWithNodeExtendedDto vms = + context.getApi().getInfrastructureApi().listVirtualMachinesByMachine(target, options); + return wrap(context, VirtualMachine.class, vms.getCollection()); + } + + /** + * Gets the list of virtual machines in the physical machine matching the given filter + * sinchronizing virtual machines from remote hypervisor with abiquo's database. + * + * @param filter The filter to apply. + * @return The list of remote virtual machines in the physical machine matching the given + * filter. + */ + public List listRemoteVirtualMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listVirtualMachines(), filter)); + } + + /** + * Gets a single virtual machine in the physical machine matching the given filter sinchronizing + * virtual machines from remote hypervisor with abiquo's database. + * + * @param filter The filter to apply. + * @return The virtual machine or null if none matched the given filter. + */ + public VirtualMachine findRemoteVirtualMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listVirtualMachines(), filter), null); + } + + /** + * Reserve the machine for the given enterprise. + *

+ * When a {@link Machine} is reserved for an {@link Enterprise}, only the users of that + * enterprise will be able to deploy {@link VirtualMachine}s in it. + * + * @param enterprise The enterprise reserving the machine. + */ + public void reserveFor(final Enterprise enterprise) + { + target = + context.getApi().getInfrastructureApi().reserveMachine(enterprise.unwrap(), target); + } + + /** + * Cancels the machine reservation for the given enterprise. + * + * @param enterprise The enterprise to cancel reservation for. + */ + public void cancelReservationFor(final Enterprise enterprise) + { + context.getApi().getInfrastructureApi().cancelReservation(enterprise.unwrap(), target); + target.getLinks().remove(target.searchLink(ParentLinkName.ENTERPRISE)); + } + + /** + * Check if the machine is reserved. + * + * @return Boolean indicating if the machine is reserved for an enterprise. + */ + public boolean isReserved() + { + return target.searchLink(ParentLinkName.ENTERPRISE) != null; + } + + /** + * Get the enterprise that has reserved the machine or null if the machine is not + * reserved. + * + * @return The enterprise that has reserved the machine or null if the machine is + * not reserved. + */ + public Enterprise getOwnerEnterprise() + { + if (!isReserved()) + { + return null; + } + + EnterpriseDto enterprise = + context.getApi().getEnterpriseApi() + .getEnterprise(target.getIdFromLink(ParentLinkName.ENTERPRISE)); + + return wrap(context, Enterprise.class, enterprise); + } + + // Builder + + public static Builder builder(final RestContext context, + final Rack rack) + { + return new Builder(context, rack); + } + + public static class Builder + { + private RestContext context; + + private String name, description; + + private Integer virtualRamInMb; + + private Integer virtualRamUsedInMb = DEFAULT_VRAM_USED; + + private Integer virtualCpuCores; + + private Integer virtualCpusUsed = DEFAULT_VCPU_USED; + + private String virtualSwitch; + + private Integer port; + + private String ip; + + private MachineState state = MachineState.STOPPED; + + private String ipService; + + private HypervisorType type; + + private String user; + + private String password; + + private Iterable datastores; + + private String ipmiIp; + + private Integer ipmiPort; + + private String ipmiUser; + + private String ipmiPassword; + + private Rack rack; + + public Builder(final RestContext context, final Rack rack) + { + super(); + checkNotNull(rack, ValidationErrors.NULL_RESOURCE + Rack.class); + this.rack = rack; + this.context = context; + } + + public Builder state(final MachineState state) + { + this.state = state; + return this; + } + + public Builder ipmiPassword(final String ipmiPassword) + { + this.ipmiPassword = ipmiPassword; + return this; + } + + public Builder ipmiUser(final String ipmiUser) + { + this.ipmiUser = ipmiUser; + return this; + } + + public Builder ipmiPort(final int ipmiPort) + { + this.ipmiPort = ipmiPort; + return this; + } + + public Builder ipmiIp(final String ipmiIp) + { + this.ipmiIp = ipmiIp; + return this; + } + + public Builder user(final String user) + { + this.user = user; + return this; + } + + public Builder ip(final String ip) + { + this.ip = ip; + if (ipService == null) + { + ipService = ip; + } + return this; + } + + public Builder ipService(final String ipService) + { + this.ipService = ipService; + return this; + } + + public Builder password(final String password) + { + this.password = password; + return this; + } + + public Builder virtualSwitch(final String virtualSwitch) + { + this.virtualSwitch = virtualSwitch; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder description(final String description) + { + this.description = description; + return this; + } + + public Builder port(final int port) + { + this.port = port; + return this; + } + + public Builder datastores(final Iterable datastores) + { + this.datastores = datastores; + return this; + } + + public Builder virtualRamInMb(final int virtualRamInMb) + { + this.virtualRamInMb = virtualRamInMb; + return this; + } + + public Builder virtualRamUsedInMb(final int virtualRamUsedInMb) + { + this.virtualRamUsedInMb = virtualRamUsedInMb; + return this; + } + + public Builder virtualCpuCores(final int virtualCpuCores) + { + this.virtualCpuCores = virtualCpuCores; + return this; + } + + public Builder virtualCpusUsed(final int virtualCpusUsed) + { + this.virtualCpusUsed = virtualCpusUsed; + return this; + } + + public Builder hypervisorType(final HypervisorType hypervisorType) + { + this.type = hypervisorType; + + // Sets default hypervisor port + if (this.port == null) + { + this.port = hypervisorType.defaultPort; + } + + return this; + } + + public Builder rack(final Rack rack) + { + checkNotNull(rack, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.rack = rack; + return this; + } + + public Machine build() + { + MachineDto dto = new MachineDto(); + dto.setName(name); + dto.setDescription(description); + dto.setVirtualRamInMb(virtualRamInMb); + dto.setVirtualRamUsedInMb(virtualRamUsedInMb); + dto.setVirtualCpuCores(virtualCpuCores); + dto.setVirtualCpusUsed(virtualCpusUsed); + dto.setVirtualSwitch(virtualSwitch); + if (port != null) + { + dto.setPort(port); + } + dto.setIp(ip); + dto.setIpService(ipService); + dto.setType(type); + dto.setUser(user); + dto.setPassword(password); + dto.setIpmiIP(ipmiIp); + dto.setIpmiPassword(ipmiPassword); + if (ipmiPort != null) + { + dto.setIpmiPort(ipmiPort); + } + dto.setIpmiUser(ipmiUser); + dto.setState(state); + + DatastoresDto datastoresDto = new DatastoresDto(); + datastoresDto.getCollection().addAll(unwrap(datastores)); + dto.setDatastores(datastoresDto); + + Machine machine = new Machine(context, dto); + machine.rack = rack; + + return machine; + } + + public static Builder fromMachine(final Machine in) + { + Builder builder = + Machine.builder(in.context, in.rack).name(in.getName()) + .description(in.getDescription()).virtualCpuCores(in.getVirtualCpuCores()) + .virtualCpusUsed(in.getVirtualCpusUsed()) + .virtualRamInMb(in.getVirtualRamInMb()) + .virtualRamUsedInMb(in.getVirtualRamUsedInMb()) + .virtualSwitch(in.getVirtualSwitch()).port(in.getPort()).ip(in.getIp()) + .ipService(in.getIpService()).hypervisorType(in.getType()).user(in.getUser()) + .password(in.getPassword()).ipmiIp(in.getIpmiIp()) + .ipmiPassword(in.getIpmiPassword()).ipmiUser(in.getIpmiUser()) + .state(in.getState()).datastores(in.getDatastores()); + + // Parameters that can be null + if (in.getIpmiPort() != null) + { + builder.ipmiPort(in.getIpmiPort()); + } + + return builder; + } + } + + // Delegate methods + + public void setRack(final Rack rack) + { + this.rack = rack; + } + + public VirtualMachine getVirtualMachine(final Integer virtualMachineId) + { + VirtualMachineWithNodeExtendedDto vm = + context.getApi().getInfrastructureApi().getVirtualMachine(target, virtualMachineId); + return wrap(context, VirtualMachine.class, vm); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java new file mode 100644 index 0000000000..94dba1d27f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java @@ -0,0 +1,786 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.FsmsDto; +import com.abiquo.server.core.infrastructure.LogicServersDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.OrganizationsDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link RackDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource + */ +@EnterpriseEdition +public class ManagedRack extends DomainWrapper +{ + /** The default minimum VLAN id. */ + private static final int DEFAULT_VLAN_ID_MIN = 2; + + /** The default maximum VLAN id. */ + private static final int DEFAULT_VLAN_ID_MAX = 4094; + + /** The default maximum VLAN per virtual datacenter. */ + private static final int DEFAULT_VLAN_PER_VDC = 1; + + /** The default nrsq factor. */ + private static final int DEFAULT_NRSQ = 10; + + /** The datacenter where the rack belongs. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected ManagedRack(final RestContext context, + final UcsRackDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the managed rack. + * + * @see API: + * http://community.abiquo.com/display/ABI20/Rack+Resource#RackResource#RackResource- + * DeleteaRack + */ + public void delete() + { + context.getApi().getInfrastructureApi().deleteRack(target); + target = null; + } + + /** + * Create a new managed rack in Abiquo. This method wil discover the blades configured in the + * UCS. If the data provided for the connection is invalid a UcsRack will be created in Abiquo + * but with no Physical Machines attached to it. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource-CreateanewUCSRack< + * /a> + */ + public void save() + { + target = + context.getApi().getInfrastructureApi() + .createManagedRack(datacenter.unwrap(), target); + } + + /** + * Update rack information in the server with the data from this rack. The IP data member cannot + * be updated. If changed will be ignored and the old IP will remain. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource#RackResource- + * UpdateanexistingUCSrack + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateManagedRack(target); + } + + // Parent access + /** + * Retrieve the datacenter where this rack is. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveadatacenter + */ + public Datacenter getDatacenter() + { + Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + return wrap(context, Datacenter.class, context.getApi().getInfrastructureApi() + .getDatacenter(datacenterId)); + } + + // Children access + + /** + * Retrieve the list of blades in this rack. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrievealistofMachines + */ + public List listMachines() + { + MachinesDto machines = context.getApi().getInfrastructureApi().listMachines(target); + return wrap(context, Blade.class, machines.getCollection()); + } + + /** + * Retrieve a filtered list of blades in this rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrievealistofMachines + */ + public List listMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listMachines(), filter)); + } + + /** + * Retrieve the first blade matching the filter within the list of machines in this rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrievealistofMachines + */ + public Blade findMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listMachines(), filter), null); + } + + /** + * Retrieve the list of service profiles in this UCS rack. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofallservicesprofilesinaUCSrack + */ + public List listServiceProfiles() + { + LogicServersDto profiles = + context.getApi().getInfrastructureApi().listServiceProfiles(target); + return wrap(context, LogicServer.class, profiles.getCollection()); + } + + /** + * Retrieve a filtered list of service profiles in this UCS rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofallservicesprofilesinaUCSrack + */ + public List listServiceProfiles(final Predicate filter) + { + return Lists.newLinkedList(filter(listServiceProfiles(), filter)); + } + + /** + * Retrieve the first service profile matching the filter within the list of profiles in this + * rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrievealistofallservicesprofilesinaUCSrack + */ + public LogicServer findServiceProfile(final Predicate filter) + { + return Iterables.getFirst(filter(listServiceProfiles(), filter), null); + } + + /** + * Retrieve the list of service profile templates in this UCS rack. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource- + * RetrievealistofallServicesProfilesTemplatesinaUCSRack + */ + public List listServiceProfileTemplates() + { + LogicServersDto templates = + context.getApi().getInfrastructureApi().listServiceProfileTemplates(target); + return wrap(context, LogicServer.class, templates.getCollection()); + } + + /** + * Retrieve a filtered list of service profile templates in this UCS rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource- + * RetrievealistofallServicesProfilesTemplatesinaUCSRack + */ + public List listServiceProfileTemplates(final Predicate filter) + { + return Lists.newLinkedList(filter(listServiceProfileTemplates(), filter)); + } + + /** + * Retrieve the first service profile template matching the filter within the list of templates + * in this rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/RackResource- + * RetrievealistofallServicesProfilesTemplatesinaUCSRack + */ + public LogicServer findServiceProfileTemplate(final Predicate filter) + { + return Iterables.getFirst(filter(listServiceProfileTemplates(), filter), null); + } + + /** + * Retrieve the list of organization in this UCS rack. The credentials in the UcsRack + * configuration might not have enough rights in the UCS to retrieve all organizations. Then + * only the allowed ones are returned. This data is not persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/ + */ + public List listOrganizations() + { + OrganizationsDto organizations = + context.getApi().getInfrastructureApi().listOrganizations(target); + return wrap(context, Organization.class, organizations.getCollection()); + } + + /** + * Retrieve a filtered list of organization in this UCS rack. The credentials in the UcsRack + * configuration might not have enough rights in the UCS to retrieve all organizations. Then + * only the allowed ones are returned. This data is not persisted in Abiquo. + * + * @param filter Filter to be applied to the list. + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrieveallorganizationsfromaUCS + */ + public List listOrganizations(final Predicate filter) + { + return Lists.newLinkedList(filter(listOrganizations(), filter)); + } + + /** + * Retrieve the first organization matching the filter within the list of organization in this + * rack. The credentials in the UcsRack configuration might not have enough rights in the UCS to + * retrieve all organizations. Then only the allowed ones are returned. This data is not + * persisted in Abiquo. + * + * @param filter Filter to be applied to the list. + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrieveallorganizationsfromaUCS + */ + public Organization findOrganization(final Predicate filter) + { + return Iterables.getFirst(filter(listOrganizations(), filter), null); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * RetrieveFSMofanentityinUCS + */ + public List listFsm(final String entityName) + { + FsmsDto fsms = context.getApi().getInfrastructureApi().listFsms(target, entityName); + return wrap(context, Fsm.class, fsms.getCollection()); + } + + // Actions + + /** + * Clone a Service Profile this rack. This data is not persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * ClonelogicserverinUCS + */ + public void cloneLogicServer(final LogicServer logicServer, final Organization organization, + final String newName) + { + context.getApi().getInfrastructureApi() + .cloneLogicServer(this.unwrap(), logicServer.unwrap(), organization.unwrap(), newName); + } + + /** + * Associate a Service Profile and a Blade in UCS. If the Service Profile is already associated + * then the request cannot be completed. This data is not persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * AssociatelogicserverwithabladeinUCS + */ + public void associateLogicServer(final String bladeName, final LogicServer logicServer, + final Organization organization) + { + context + .getApi() + .getInfrastructureApi() + .associateLogicServer(this.unwrap(), logicServer.unwrap(), organization.unwrap(), + bladeName); + } + + /** + * Clone and associate a Service Profile and a Blade in UCS. If the Blade is already associated + * then Abiquo will dissociate it first. If the request cannot be completed successfully the + * Blade might be left with no Service Profile associated. This data is not persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * CloneandassociateLogicServerwithabladeinUCS + */ + public void cloneAndAssociateLogicServer(final String bladeName, final LogicServer logicServer, + final Organization organization, final String logicServerName) + { + context + .getApi() + .getInfrastructureApi() + .cloneAndAssociateLogicServer(this.unwrap(), logicServer.unwrap(), + organization.unwrap(), bladeName, logicServerName); + } + + /** + * Instantiate and associate a Service Profile Template and a Blade in UCS. If the Service + * Profile is already associated the request cannot be successful. If the Blade is already + * associated then Abiquo will dissociate it first. If the request cannot be completed + * successfully the Blade might be left with no Service Profile associated. This data is not + * persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * AssociateabladewithaLogicServerTemplate + */ + public void associateLogicServerTemplate(final String bladeName, final LogicServer logicServer, + final Organization organization, final String logicServerName) + { + context + .getApi() + .getInfrastructureApi() + .associateTemplate(this.unwrap(), logicServer.unwrap(), organization.unwrap(), + bladeName, logicServerName); + } + + /** + * Dissociates a Service Profile and a Blade in UCS. This data is not persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * DisassociatelogicserverfromabladeinUCS + */ + public void disassociateLogicServer(final LogicServer logicServer) + { + context.getApi().getInfrastructureApi() + .dissociateLogicServer(this.unwrap(), logicServer.unwrap()); + } + + /** + * Deletes a Service Profile in UCS. This data is not persisted in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource- + * DeletelogicserverwithabladeinUCS + */ + public void deleteLogicServer(final LogicServer logicServer) + { + context.getApi().getInfrastructureApi() + .deleteLogicServer(this.unwrap(), logicServer.unwrap()); + } + + // Builder + + public static Builder builder(final RestContext context, + final Datacenter datacenter) + { + return new Builder(context, datacenter); + } + + public static class Builder + { + private RestContext context; + + private Integer id; + + private String name; + + private String shortDescription; + + private boolean haEnabled = false; + + private Integer nrsq = DEFAULT_NRSQ; + + private Integer vlanIdMax = DEFAULT_VLAN_ID_MAX; + + private Integer vlanIdMin = DEFAULT_VLAN_ID_MIN; + + private Integer vlanPerVdcReserved = DEFAULT_VLAN_PER_VDC; + + private String vlansIdAvoided; + + private Integer port; + + private String ip; + + private String password; + + private String user; + + private String defaultTemplate; + + private Integer maxMachinesOn; + + private Datacenter datacenter; + + public Builder(final RestContext context, + final Datacenter datacenter) + { + super(); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + this.context = context; + } + + public Builder port(final Integer port) + { + this.port = port; + return this; + } + + public Builder ipAddress(final String ip) + { + this.ip = ip; + return this; + } + + public Builder password(final String password) + { + this.password = password; + return this; + } + + public Builder user(final String user) + { + this.user = user; + return this; + } + + public Builder defaultTemplate(final String defaultTemplate) + { + this.defaultTemplate = defaultTemplate; + return this; + } + + public Builder maxMachinesOn(final Integer maxMachinesOn) + { + this.maxMachinesOn = maxMachinesOn; + return this; + } + + public Builder id(final Integer id) + { + this.id = id; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder shortDescription(final String shortDescription) + { + this.shortDescription = shortDescription; + return this; + } + + public Builder haEnabled(final boolean haEnabled) + { + this.haEnabled = haEnabled; + return this; + } + + public Builder nrsq(final int nrsq) + { + this.nrsq = nrsq; + return this; + } + + public Builder vlanIdMax(final int vlanIdMax) + { + this.vlanIdMax = vlanIdMax; + return this; + } + + public Builder vlanIdMin(final int vlanIdMin) + { + this.vlanIdMin = vlanIdMin; + return this; + } + + public Builder vlanPerVdcReserved(final int vlanPerVdcExpected) + { + this.vlanPerVdcReserved = vlanPerVdcExpected; + return this; + } + + public Builder VlansIdAvoided(final String vlansIdAvoided) + { + this.vlansIdAvoided = vlansIdAvoided; + return this; + } + + public Builder datacenter(final Datacenter datacenter) + { + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + return this; + } + + public ManagedRack build() + { + UcsRackDto dto = new UcsRackDto(); + dto.setId(id); + dto.setName(name); + dto.setShortDescription(shortDescription); + dto.setHaEnabled(haEnabled); + dto.setNrsq(nrsq); + dto.setVlanIdMax(vlanIdMax); + dto.setVlanIdMin(vlanIdMin); + dto.setVlanPerVdcReserved(vlanPerVdcReserved); + dto.setVlansIdAvoided(vlansIdAvoided); + dto.setPort(port); + dto.setIp(ip); + dto.setPassword(password); + dto.setUser(user); + dto.setDefaultTemplate(defaultTemplate); + dto.setMaxMachinesOn(maxMachinesOn); + + ManagedRack rack = new ManagedRack(context, dto); + rack.datacenter = datacenter; + return rack; + } + + public static Builder fromRack(final ManagedRack in) + { + return ManagedRack.builder(in.context, in.datacenter).id(in.getId()).name(in.getName()) + .shortDescription(in.getShortDescription()).haEnabled(in.isHaEnabled()) + .nrsq(in.getNrsq()).vlanIdMax(in.getVlanIdMax()).vlanIdMin(in.getVlanIdMin()) + .vlanPerVdcReserved(in.getVlanPerVdcReserved()) + .VlansIdAvoided(in.getVlansIdAvoided()).port(in.getPort()).ipAddress(in.getIp()) + .password(in.getPassword()).user(in.getUser()) + .defaultTemplate(in.getDefaultTemplate()).maxMachinesOn(in.getMaxMachinesOn()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public String getShortDescription() + { + return target.getShortDescription(); + } + + public void setShortDescription(final String description) + { + target.setShortDescription(description); + } + + public void setHaEnabled(final boolean haEnabled) + { + target.setHaEnabled(haEnabled); + } + + public boolean isHaEnabled() + { + return target.isHaEnabled(); + } + + public Integer getNrsq() + { + return target.getNrsq(); + } + + public Integer getVlanIdMax() + { + return target.getVlanIdMax(); + } + + public Integer getVlanIdMin() + { + return target.getVlanIdMin(); + } + + public Integer getVlanPerVdcReserved() + { + return target.getVlanPerVdcReserved(); + } + + public String getVlansIdAvoided() + { + return target.getVlansIdAvoided(); + } + + public void setNrsq(final Integer nrsq) + { + target.setNrsq(nrsq); + } + + public void setVlanIdMax(final Integer vlanIdMax) + { + target.setVlanIdMax(vlanIdMax); + } + + public void setVlanIdMin(final Integer vlanIdMin) + { + target.setVlanIdMin(vlanIdMin); + } + + public void setVlanPerVdcReserved(final Integer vlanPerVdcReserved) + { + target.setVlanPerVdcReserved(vlanPerVdcReserved); + } + + public void setVlansIdAvoided(final String vlansIdAvoided) + { + target.setVlansIdAvoided(vlansIdAvoided); + } + + public String getIp() + { + return target.getIp(); + } + + public String getLongDescription() + { + return target.getLongDescription(); + } + + public Integer getMaxMachinesOn() + { + return target.getMaxMachinesOn(); + } + + public String getPassword() + { + return target.getPassword(); + } + + public Integer getPort() + { + return target.getPort(); + } + + public String getUser() + { + return target.getUser(); + } + + public void setDefaultTemplate(final String defaultTemplate) + { + target.setDefaultTemplate(defaultTemplate); + } + + public String getDefaultTemplate() + { + return target.getDefaultTemplate(); + } + + public void setIp(final String ip) + { + target.setIp(ip); + } + + public void setMaxMachinesOn(final Integer maxMachinesOn) + { + target.setMaxMachinesOn(maxMachinesOn); + } + + public void setPassword(final String password) + { + target.setPassword(password); + } + + public void setPort(final Integer port) + { + target.setPort(port); + } + + public void setUser(final String user) + { + target.setUser(user); + } + + @Override + public String toString() + { + return "ManagedRack [id=" + getId() + ", name=" + getName() + ", shortDescription=" + + getShortDescription() + ", haEnabled=" + isHaEnabled() + ", nrsq=" + getNrsq() + + ", vlanIdMax=" + getVlanIdMax() + ", vlanIdMin=" + getVlanIdMin() + + ", vlanPerVdcReserved=" + getVlanPerVdcReserved() + ", vlansIdAvoided=" + + getVlansIdAvoided() + ", ip=" + getIp() + ", longDescription=" + getLongDescription() + + ", maxMachinesOn=" + getMaxMachinesOn() + ", password=**PROTECTED**, port=" + + getPort() + ", user=" + getUser() + ", defaultTemplate=" + getDefaultTemplate() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java new file mode 100644 index 0000000000..6fafe38e53 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java @@ -0,0 +1,108 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.OrganizationDto; + +/** + * Adds high level functionality to {@link OrganizationDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource + */ +@EnterpriseEdition +public class Organization extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Organization(final RestContext context, final OrganizationDto target) + { + super(context, target); + } + + // Delegate Methods + + public String getDescription() + { + return target.getDescription(); + } + + public String getDn() + { + return target.getDn(); + } + + public String getLevel() + { + return target.getLevel(); + } + + public String getName() + { + return target.getName(); + } + + public String getStatus() + { + return target.getStatus(); + } + + public void setDescription(final String value) + { + target.setDescription(value); + } + + public void setDn(final String dn) + { + target.setDn(dn); + } + + public void setLevel(final String value) + { + target.setLevel(value); + } + + public void setName(final String value) + { + target.setName(value); + } + + public void setStatus(final String value) + { + target.setStatus(value); + } + + @Override + public String toString() + { + return "Organization [name=" + getName() + ", description=" + getDescription() + ", dn=" + + getDn() + ", level=" + getLevel() + ", status=" + getStatus() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java new file mode 100644 index 0000000000..6777facade --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java @@ -0,0 +1,421 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link RackDto}. Represents unmanaged racks in the Abiquo + * platform. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource + */ +public class Rack extends DomainWrapper +{ + /** The default minimum VLAN id. */ + private static final int DEFAULT_VLAN_ID_MIN = 2; + + /** The default maximum VLAN id. */ + private static final int DEFAULT_VLAN_ID_MAX = 4094; + + /** The default maximum VLAN per virtual datacenter. */ + private static final int DEFAULT_VLAN_PER_VDC = 1; + + /** The default nrsq factor. */ + private static final int DEFAULT_NRSQ = 10; + + /** The datacenter where the rack belongs. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected Rack(final RestContext context, final RackDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the unmanaged rack. + * + * @see API: + * http://community.abiquo.com/display/ABI20/Rack+Resource#RackResource#RackResource- + * DeleteaRack + */ + public void delete() + { + context.getApi().getInfrastructureApi().deleteRack(target); + target = null; + } + + /** + * Create a new unmanaged rack in Abiquo. + * + * @see API: http://community.abiquo.com/display/ABI20/RackResource#RackResource-CreateanewRack + */ + public void save() + { + target = context.getApi().getInfrastructureApi().createRack(datacenter.unwrap(), target); + } + + /** + * Update rack information in the server with the data from this rack. + * + * @see API: + * http://community.abiquo.com/display/ABI20/RackResource#RackResource-UpdateanexistingRack + * + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateRack(target); + } + + // Parent access + /** + * Retrieve the datacenter where this rack is. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveadatacenter + */ + public Datacenter getDatacenter() + { + Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + return wrap(context, Datacenter.class, context.getApi().getInfrastructureApi() + .getDatacenter(datacenterId)); + } + + // Children access + + /** + * Retrieve the list of physical machines in this rack. + * + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrievealistofMachines + */ + public List listMachines() + { + MachinesDto machines = context.getApi().getInfrastructureApi().listMachines(target); + return wrap(context, Machine.class, machines.getCollection()); + } + + /** + * Retrieve a filtered list of physical machines in this rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrievealistofMachines + */ + public List listMachines(final Predicate filter) + { + return Lists.newLinkedList(filter(listMachines(), filter)); + } + + /** + * Retrieve the first physical machine matching the filter within the list of machines in this + * rack. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/MachineResource#MachineResource- + * RetrievealistofMachines + */ + public Machine findMachine(final Predicate filter) + { + return Iterables.getFirst(filter(listMachines(), filter), null); + } + + /** + * Retrieve a single physical machine. + * + * @param id Unique ID of the physical machine in this rack. + * @see API: + * http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrieveaMachine + * + * @return Unmanaged rack with the given id or null if it does not exist. + */ + public Machine getMachine(final Integer id) + { + MachineDto machine = context.getApi().getInfrastructureApi().getMachine(target, id); + return wrap(context, Machine.class, machine); + } + + // Builder + + public static Builder builder(final RestContext context, + final Datacenter datacenter) + { + return new Builder(context, datacenter); + } + + public static class Builder + { + private RestContext context; + + private Integer id; + + private String name; + + private String shortDescription; + + private boolean haEnabled = false; + + private Integer nrsq = DEFAULT_NRSQ; + + private Integer vlanIdMax = DEFAULT_VLAN_ID_MAX; + + private Integer vlanIdMin = DEFAULT_VLAN_ID_MIN; + + private Integer vlanPerVdcReserved = DEFAULT_VLAN_PER_VDC; + + private String vlansIdAvoided; + + private Datacenter datacenter; + + public Builder(final RestContext context, + final Datacenter datacenter) + { + super(); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + this.context = context; + } + + public Builder id(final Integer id) + { + this.id = id; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder shortDescription(final String shortDescription) + { + this.shortDescription = shortDescription; + return this; + } + + public Builder haEnabled(final boolean haEnabled) + { + this.haEnabled = haEnabled; + return this; + } + + public Builder nrsq(final int nrsq) + { + this.nrsq = nrsq; + return this; + } + + public Builder vlanIdMax(final int vlanIdMax) + { + this.vlanIdMax = vlanIdMax; + return this; + } + + public Builder vlanIdMin(final int vlanIdMin) + { + this.vlanIdMin = vlanIdMin; + return this; + } + + public Builder vlanPerVdcReserved(final int vlanPerVdcExpected) + { + this.vlanPerVdcReserved = vlanPerVdcExpected; + return this; + } + + public Builder VlansIdAvoided(final String vlansIdAvoided) + { + this.vlansIdAvoided = vlansIdAvoided; + return this; + } + + public Builder datacenter(final Datacenter datacenter) + { + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + return this; + } + + public Rack build() + { + RackDto dto = new RackDto(); + dto.setId(id); + dto.setName(name); + dto.setShortDescription(shortDescription); + dto.setHaEnabled(haEnabled); + dto.setNrsq(nrsq); + dto.setVlanIdMax(vlanIdMax); + dto.setVlanIdMin(vlanIdMin); + dto.setVlanPerVdcReserved(vlanPerVdcReserved); + dto.setVlansIdAvoided(vlansIdAvoided); + Rack rack = new Rack(context, dto); + rack.datacenter = datacenter; + return rack; + } + + public static Builder fromRack(final Rack in) + { + return Rack.builder(in.context, in.datacenter).id(in.getId()).name(in.getName()) + .shortDescription(in.getShortDescription()).haEnabled(in.isHaEnabled()) + .nrsq(in.getNrsq()).vlanIdMax(in.getVlanIdMax()).vlanIdMin(in.getVlanIdMin()) + .vlanPerVdcReserved(in.getVlanPerVdcReserved()) + .VlansIdAvoided(in.getVlansIdAvoided()); + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public String getShortDescription() + { + return target.getShortDescription(); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setShortDescription(final String description) + { + target.setShortDescription(description); + } + + public void setHaEnabled(final boolean haEnabled) + { + target.setHaEnabled(haEnabled); + } + + public boolean isHaEnabled() + { + return target.isHaEnabled(); + } + + public Integer getNrsq() + { + return target.getNrsq(); + } + + public Integer getVlanIdMax() + { + return target.getVlanIdMax(); + } + + public Integer getVlanIdMin() + { + return target.getVlanIdMin(); + } + + public Integer getVlanPerVdcReserved() + { + return target.getVlanPerVdcReserved(); + } + + public String getVlansIdAvoided() + { + return target.getVlansIdAvoided(); + } + + public void setNrsq(final Integer nrsq) + { + target.setNrsq(nrsq); + } + + public void setVlanIdMax(final Integer vlanIdMax) + { + target.setVlanIdMax(vlanIdMax); + } + + public void setVlanIdMin(final Integer vlanIdMin) + { + target.setVlanIdMin(vlanIdMin); + } + + public void setVlanPerVdcReserved(final Integer vlanPerVdcReserved) + { + target.setVlanPerVdcReserved(vlanPerVdcReserved); + } + + public void setVlansIdAvoided(final String vlansIdAvoided) + { + target.setVlansIdAvoided(vlansIdAvoided); + } + + @Override + public String toString() + { + return "Rack [id=" + getId() + ", name=" + getName() + ", description=" + + getShortDescription() + ", haEnabled=" + isHaEnabled() + ", nrsq=" + getNrsq() + + ", vlanIdMax=" + getVlanIdMax() + ", vlanIdMin=" + getVlanIdMin() + + ", vlanPerVdcReserved=" + getVlanPerVdcReserved() + ", vlansIdAvoided=" + + getVlansIdAvoided() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/RemoteService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/RemoteService.java new file mode 100644 index 0000000000..568a742b59 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/RemoteService.java @@ -0,0 +1,277 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.RemoteServiceDto; + +/** + * Adds high level functionality to {@link RemoteServiceDto}. The Remote Service resource offers the + * functionality of managing the remote services of a datacenter in a logical way. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/RemoteServiceResource + */ +public class RemoteService extends DomainWrapper +{ + /** The default status. */ + private static final int DEFAULT_STATUS = 0; + + /** The datacenter using the remote service. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected RemoteService(final RestContext context, final RemoteServiceDto target) + { + super(context, target); + } + + /** + * Delete the remote service. + * + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * DeleteaRemoteService + */ + public void delete() + { + context.getApi().getInfrastructureApi().deleteRemoteService(target); + target = null; + } + + /** + * Create the remote service. + * + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * CreateaRemoteService + */ + public void save() + { + target = + context.getApi().getInfrastructureApi() + .createRemoteService(datacenter.unwrap(), target); + } + + /** + * Update remote service information in the server with the data from this remote service. + * + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * UpdateanexistingRemoteService + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateRemoteService(target); + } + + /** + * Check remote service availability. + * + * @see API: http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource- + * CheckthestatusofaRemoteService + */ + public boolean isAvailable() + { + // If the remote service can not be checked, assume it is available + return !getType().canBeChecked() ? true : context.getApi().getInfrastructureApi() + .isAvailable(target); + } + + // Parent access + + /** + * Retrieve the datacenter using this remotes service. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveadatacenter + */ + public Datacenter getDatacenter() + { + Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId); + datacenter = wrap(context, Datacenter.class, dto); + return datacenter; + } + + public static Builder builder(final RestContext context, final Datacenter datacenter) + { + return new Builder(context, datacenter); + } + + public static class Builder + { + private RestContext context; + + private Integer id; + + private Datacenter datacenter; + + private String ip; + + private Integer port; + + private RemoteServiceType type; + + private Integer status = DEFAULT_STATUS; + + // To be used only internally by the builder + private String uri; + + public Builder(final RestContext context, final Datacenter datacenter) + { + super(); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + this.context = context; + } + + public Builder datacenter(final Datacenter datacenter) + { + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + return this; + } + + public Builder status(final int status) + { + this.status = status; + return this; + } + + public Builder type(final RemoteServiceType type) + { + this.type = type; + return this; + } + + public Builder ip(final String ip) + { + this.ip = ip; + return this; + } + + public Builder port(final int port) + { + this.port = port; + return this; + } + + private String generateUri(final String ip, final Integer port, final RemoteServiceType type) + { + return type.getDefaultProtocol() + ip + ":" + port + "/" + type.getServiceMapping(); + } + + public RemoteService build() + { + if (uri == null) + { + checkNotNull(ip, ValidationErrors.MISSING_REQUIRED_FIELD + "ip"); + checkNotNull(type, ValidationErrors.MISSING_REQUIRED_FIELD + "type"); + + uri = generateUri(ip, port == null ? type.getDefaultPort() : port, type); + } + + RemoteServiceDto dto = new RemoteServiceDto(); + dto.setId(id); + dto.setType(type); + dto.setUri(uri); + dto.setStatus(status); + RemoteService remoteservice = new RemoteService(context, dto); + remoteservice.datacenter = datacenter; + return remoteservice; + } + + public static Builder fromRemoteService(final RemoteService in) + { + Builder builder = + RemoteService.builder(in.context, in.getDatacenter()).status(in.getStatus()) + .type(in.getType()); + builder.uri = in.getUri(); + return builder; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public RemoteServiceType getType() + { + return target.getType(); + } + + public int getStatus() + { + return target.getStatus(); + } + + public String getUri() + { + return target.getUri(); + } + + public void setStatus(final int status) + { + target.setStatus(status); + } + + public void setType(final RemoteServiceType type) + { + target.setType(type); + } + + public void setUri(final String uri) + { + target.setUri(uri); + } + + @Override + public String toString() + { + return "RemoteService [id=" + getId() + ", available=" + isAvailable() + ", type=" + + getType() + ", status=" + getStatus() + ", uri" + getUri() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java new file mode 100644 index 0000000000..de0360ca4c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java @@ -0,0 +1,532 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link StorageDeviceDto}. The Storage Device Resource offers the + * functionality of managing the external storage. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/StorageDeviceResource + */ +@EnterpriseEdition +public class StorageDevice extends DomainWrapper +{ + /** The datacenter where the storage device is. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected StorageDevice(final RestContext context, + final StorageDeviceDto target) + { + super(context, target); + } + + /** + * Delete the storage device. + * + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Deleteastoragedevice + */ + public void delete() + { + context.getApi().getInfrastructureApi().deleteStorageDevice(target); + target = null; + } + + /** + * Create a new storage device. + * + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Createastoragedevice + */ + public void save() + { + target = + context.getApi().getInfrastructureApi() + .createStorageDevice(datacenter.unwrap(), target); + } + + /** + * Update storage device information in the server with the data from this device. + * + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Updateastoragedevice + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateStorageDevice(target); + } + + // Parent access + + /** + * Retrieve the datacenter where this storage device is. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveadatacenter + */ + public Datacenter getDatacenter() + { + Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId); + datacenter = wrap(context, Datacenter.class, dto); + return datacenter; + } + + // Children access + + /** + * Retrieve the list of storage pools in this device (synchronized with the device). + * + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return Synchronized list of storage pools in this device. + */ + public List listRemoteStoragePools() + { + StoragePoolsDto storagePools = + context.getApi().getInfrastructureApi() + .listStoragePools(target, StoragePoolOptions.builder().sync(true).build()); + + List storagePoolList = + wrap(context, StoragePool.class, storagePools.getCollection()); + + for (StoragePool storagePool : storagePoolList) + { + storagePool.storageDevice = this; + } + + return storagePoolList; + } + + /** + * Retrieve a filtered list of storage pools in this device (synchronized with the device). + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return Filtered synchronized list of storage pools in this device. + */ + public List listRemoteStoragePools(final Predicate filter) + { + return Lists.newLinkedList(filter(listRemoteStoragePools(), filter)); + } + + /** + * Retrieve the first storage pool matching the filter within the list of storage pools in this + * device (synchronized with the device). + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return First storage pool (synchronized) matching the filter or null if there + * is none. + */ + public StoragePool findRemoteStoragePool(final Predicate filter) + { + return Iterables.getFirst(filter(listRemoteStoragePools(), filter), null); + } + + /** + * Retrieve the list of storage pools in this device from Abiquo database (may not be + * synchronized with the device). + * + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return Unsynchronized list of storage pools in this device. + */ + public List listStoragePools() + { + StoragePoolsDto storagePools = + context.getApi().getInfrastructureApi() + .listStoragePools(target, StoragePoolOptions.builder().sync(false).build()); + return wrap(context, StoragePool.class, storagePools.getCollection()); + } + + /** + * Retrieve a filtered list of storage pools in this device from Abiquo database (may not be + * synchronized with the device). + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return Filtered unsynchronized list of storage pools in this device. + */ + public List listStoragePools(final Predicate filter) + { + return Lists.newLinkedList(filter(listStoragePools(), filter)); + } + + /** + * Retrieve the first storage pool matching the filter within the list of storage pools in this + * device (unsynchronized with the device). + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return First storage pool (unsynchronized) matching the filter or null if there + * is none. + */ + public StoragePool findStoragePool(final Predicate filter) + { + return Iterables.getFirst(filter(listStoragePools(), filter), null); + } + + /** + * Retrieve a single storage pool in this device from Abiquo database. + * + * @param id Unique ID of the storage device in this datacenter. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievearegisteredpool + * @return Storage pool with the given id or null if it does not exist. + */ + public StoragePool getStoragePool(final String id) + { + StoragePoolDto storagePool = + context.getApi().getInfrastructureApi().getStoragePool(target, id); + return wrap(context, StoragePool.class, storagePool); + } + + /** + * Retrieve the list of tiers in the datacenter using this device. + * + * @see API: + * http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers + * + * @return List of tiers in the datacenter using this device. + */ + public List listTiersFromDatacenter() + { + DatacenterDto datacenter; + + if (this.datacenter == null) + { + datacenter = new DatacenterDto(); + datacenter.setId(target.getIdFromLink(ParentLinkName.DATACENTER)); + } + else + { + datacenter = this.getDatacenter().unwrap(); + } + + TiersDto dto = context.getApi().getInfrastructureApi().listTiers(datacenter); + return DomainWrapper.wrap(context, Tier.class, dto.getCollection()); + } + + /** + * Retrieve a filtered list of tiers in the datacenter using this device. + * + * @param filter Filter to be applied to the list. + * @see API: + * http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers + * + * @return Filtered list of tiers in the datacenter using this device. + */ + public List listTiersFromDatacenter(final Predicate filter) + { + return Lists.newLinkedList(filter(listTiersFromDatacenter(), filter)); + } + + /** + * Retrieve the first tier matching the filter within the list of tiers in the datacenter. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrievethelistofstoragedevices + * @return First tier matching the filter or null if there is none. + */ + public Tier findTierInDatacenter(final Predicate filter) + { + return Iterables.getFirst(filter(listTiersFromDatacenter(), filter), null); + } + + public static Builder builder(final RestContext context, + final Datacenter datacenter) + { + return new Builder(context, datacenter); + } + + public static class Builder + { + private RestContext context; + + private Datacenter datacenter; + + private String iscsiIp; + + private Integer iscsiPort; + + private String managementIp; + + private Integer managementPort; + + private String name; + + private String password; + + private String type; + + private String username; + + public Builder(final RestContext context, + final Datacenter datacenter) + { + super(); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + this.context = context; + } + + public Builder datacenter(final Datacenter datacenter) + { + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + this.datacenter = datacenter; + return this; + } + + public Builder iscsiIp(final String iscsiIp) + { + this.iscsiIp = iscsiIp; + return this; + } + + public Builder iscsiPort(final int iscsiPort) + { + this.iscsiPort = iscsiPort; + return this; + } + + public Builder password(final String password) + { + this.password = password; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + public Builder managementPort(final int managementPort) + { + this.managementPort = managementPort; + return this; + } + + public Builder managementIp(final String managementIp) + { + this.managementIp = managementIp; + return this; + } + + public Builder type(final String type) + { + this.type = type; + return this; + } + + public Builder username(final String username) + { + this.username = username; + return this; + } + + public StorageDevice build() + { + StorageDeviceDto dto = new StorageDeviceDto(); + dto.setIscsiIp(iscsiIp); + dto.setIscsiPort(iscsiPort); + dto.setManagementIp(managementIp); + dto.setManagementPort(managementPort); + dto.setName(name); + dto.setPassword(password); + dto.setStorageTechnology(type); + dto.setUsername(username); + StorageDevice storageDevice = new StorageDevice(context, dto); + storageDevice.datacenter = datacenter; + return storageDevice; + } + + public static Builder fromStorageDevice(final StorageDevice in) + { + Builder builder = + StorageDevice.builder(in.context, in.getDatacenter()).iscsiIp(in.getIscsiIp()) + .iscsiPort(in.getIscsiPort()).managementIp(in.getManagementIp()) + .managementPort(in.getManagementPort()).name(in.getName()) + .password(in.getPassword()).type(in.getType()).username(in.getUsername()); + + return builder; + } + } + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getIscsiIp() + { + return target.getIscsiIp(); + } + + public int getIscsiPort() + { + return target.getIscsiPort(); + } + + public String getManagementIp() + { + return target.getManagementIp(); + } + + public int getManagementPort() + { + return target.getManagementPort(); + } + + public String getName() + { + return target.getName(); + } + + public String getPassword() + { + return target.getPassword(); + } + + public String getType() + { + return target.getStorageTechnology(); + } + + public String getUsername() + { + return target.getUsername(); + } + + public void setIscsiIp(final String iscsiIp) + { + target.setIscsiIp(iscsiIp); + } + + public void setIscsiPort(final int iscsiPort) + { + target.setIscsiPort(iscsiPort); + } + + public void setManagementIp(final String managementIp) + { + target.setManagementIp(managementIp); + } + + public void setManagementPort(final int managementPort) + { + target.setManagementPort(managementPort); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setPassword(final String password) + { + target.setPassword(password); + } + + public void setType(final String type) + { + target.setStorageTechnology(type); + } + + public void setUsername(final String username) + { + target.setUsername(username); + } + + @Override + public String toString() + { + return "StorageDevice [id=" + getId() + ", iscsiIp=" + getIscsiIp() + ", iscsiPort=" + + getIscsiPort() + ", managementIp=" + getManagementIp() + ", managementPort=" + + getManagementPort() + ", name=" + getName() + ", password=" + getPassword() + + ", type=" + getType() + ", user=" + getUsername() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceMetadata.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceMetadata.java new file mode 100644 index 0000000000..853b8d95bb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceMetadata.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.storage.StorageDeviceMetadataDto; + +/** + * metadata describing a Storage Device. + * + * @author Ignasi Barrera + */ +public class StorageDeviceMetadata extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected StorageDeviceMetadata(final RestContext context, + final StorageDeviceMetadataDto target) + { + super(context, target); + } + + // Delegate methods + + public String getType() + { + return target.getType(); + } + + public int getDefaultManagementPort() + { + return target.getDefaultManagementPort(); + } + + public int getDefaultIscsiPort() + { + return target.getDefaultIscsiPort(); + } + + public boolean requiresAuthentication() + { + return target.isRequiresAuthentication(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java new file mode 100644 index 0000000000..579e0c40bd --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java @@ -0,0 +1,376 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to {@link StoragePoolDto}. The Storage Pool Resource allows you to + * perform any administrative task for remote pools. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/StoragePoolResource + */ +@EnterpriseEdition +public class StoragePool extends DomainWrapper +{ + /** The default value for the used space. */ + private static final long DEFAULT_USED_SIZE = 0; + + /** The datacenter where the storage device is. */ + // Package protected to allow the storage device to be set automatically when discovering the + // pools in a device. + StorageDevice storageDevice; + + /** + * Constructor to be used only by the builder. + */ + protected StoragePool(final RestContext context, final StoragePoolDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Delete the storage pool. + * + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Deleteastoragepool + */ + public void delete() + { + context.getApi().getInfrastructureApi().deleteStoragePool(target); + target = null; + } + + /** + * Create a storage pool. Create a storage pool means registering an existing storage pool + * obtained from {@link StorageDevice#listRemoteStoragePools} method and saving it. The Storage + * Pools must be associated with a Tier using {@link #setTier}. + * + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Createastoragepoolwithatierlink + */ + public void save() + { + target = + context.getApi().getInfrastructureApi() + .createStoragePool(storageDevice.unwrap(), target); + } + + /** + * Update pool information in the server with the data from this pool. Storage pool parameters + * cannot be updated by a user, so the parameters are only a representation of the remote pool. + * Although the whole storage pool entity is sent to the API in the update call, the only thing + * a user can change is the tier that the pool belongs to by calling {@link #setTier}. + * + * @see API: http://community.abiquo.com/display/ABI20/Storage+Pool+Resource#StoragePoolResource- + * UpdateaStoragePool + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateStoragePool(target); + } + + public void refresh() + { + target = + context.getApi().getInfrastructureApi() + .refreshStoragePool(target, StoragePoolOptions.builder().sync(true).build()); + } + + /** + * Define the tier in which the pool will be added. + * + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Createastoragepoolwithatierlink + */ + public void setTier(final Tier tier) + { + checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Privilege.class); + checkNotNull(tier.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + Tier.class); + + this.updateLink(target, ParentLinkName.TIER, tier.unwrap(), "edit"); + } + + // Parent access + + /** + * Get the device where the pool belongs. + * + * @see API: http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource- + * Retrieveastoragedevice + */ + public StorageDevice getStorageDevice() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.STORAGE_DEVICE), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.STORAGE_DEVICE); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(StorageDeviceDto.class)); + + return wrap(context, StorageDevice.class, parser.apply(response)); + } + + // Children access + + /** + * Get the tier assigned to the pool. The storage pool needs to be persisted in Abiquo first. + * + * @return The tier assinged to this storage pool. + */ + public Tier getTier() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.TIER), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.TIER); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), TypeLiteral.get(TierDto.class)); + + return wrap(context, Tier.class, parser.apply(response)); + } + + // Builder + + public static Builder builder(final RestContext context, final StorageDevice storageDevice) + { + return new Builder(context, storageDevice); + } + + public static class Builder + { + private RestContext context; + + private StorageDevice storageDevice; + + private Long availableSizeInMb; + + // The enabled flag is still not used. It will be added when Abiquo includes anstorage + // allocator + + // private Boolean enabled; + + private String name; + + private Long totalSizeInMb; + + private Long usedSizeInMb = DEFAULT_USED_SIZE; + + public Builder(final RestContext context, final StorageDevice storageDevice) + { + super(); + checkNotNull(storageDevice, ValidationErrors.NULL_RESOURCE + StorageDevice.class); + this.storageDevice = storageDevice; + this.context = context; + } + + public Builder storageDevice(final StorageDevice storageDevice) + { + checkNotNull(storageDevice, ValidationErrors.NULL_RESOURCE + StorageDevice.class); + this.storageDevice = storageDevice; + return this; + } + + /** + * @deprecated This value is no longer used in Abiquo and will be removed in future + * versions. + */ + @Deprecated + public Builder availableSizeInMb(final long availableSizeInMb) + { + this.availableSizeInMb = availableSizeInMb; + return this; + } + + public Builder name(final String name) + { + this.name = name; + return this; + } + + // The enabled flag is still not used. It will be added when Abiquo includes anstorage + // allocator + + // public Builder enabled(final boolean enabled) + // { + // this.enabled = enabled; + // return this; + // } + + public Builder totalSizeInMb(final long totalSizeInMb) + { + this.totalSizeInMb = totalSizeInMb; + if (availableSizeInMb == null) + { + availableSizeInMb = totalSizeInMb; + } + return this; + } + + /** + * @deprecated This value is no longer used in Abiquo and will be removed in future + * versions. + */ + @Deprecated + public Builder usedSizeInMb(final long usedSizeInMb) + { + this.usedSizeInMb = usedSizeInMb; + return this; + } + + public StoragePool build() + { + StoragePoolDto dto = new StoragePoolDto(); + dto.setAvailableSizeInMb(availableSizeInMb); + + // The enabled flag is still not used. It will be added when Abiquo includes anstorage + // allocator + // dto.setEnabled(enabled); + + dto.setName(name); + dto.setTotalSizeInMb(totalSizeInMb); + dto.setUsedSizeInMb(usedSizeInMb); + StoragePool storagePool = new StoragePool(context, dto); + storagePool.storageDevice = storageDevice; + return storagePool; + } + + public static Builder fromStoragePool(final StoragePool in) + { + Builder builder = + StoragePool.builder(in.context, in.getStorageDevice()) + .availableSizeInMb(in.getAvailableSizeInMb())/* .enabled(in.getEnabled()) */ + .totalSizeInMb(in.getTotalSizeInMb()).usedSizeInMb(in.getUsedSizeInMb()); + + return builder; + } + } + + // Delegate methods + + /** + * @deprecated This value is no longer used in Abiquo and will be removed in future versions. + */ + @Deprecated + public long getAvailableSizeInMb() + { + return target.getAvailableSizeInMb(); + } + + // The enabled flag is still not used. It will be added when Abiquo includes anstorage + // allocator + + // public boolean getEnabled() + // { + // return target.getEnabled(); + // } + + public String getName() + { + return target.getName(); + } + + public long getTotalSizeInMb() + { + return target.getTotalSizeInMb(); + } + + /** + * @deprecated This value is no longer used in Abiquo and will be removed in future versions. + */ + @Deprecated + public long getUsedSizeInMb() + { + return target.getUsedSizeInMb(); + } + + // The enabled flag is still not used. It will be added when Abiquo includes anstorage + // allocator + + // public void setEnabled(final boolean enabled) + // { + // target.setEnabled(enabled); + // } + + public void setName(final String name) + { + target.setName(name); + } + + public void setTotalSizeInMb(final long totalSizeInMb) + { + target.setTotalSizeInMb(totalSizeInMb); + } + + // Readonly property + public String getUUID() + { + return target.getIdStorage(); + } + + @Override + public String toString() + { + return "StoragePool [name=" + getName() + ", totalSizeInMb=" + getTotalSizeInMb() + + ", uuid=" + getUUID() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java new file mode 100644 index 0000000000..c39db98d54 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java @@ -0,0 +1,187 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds high level functionality to {@link TierDto}. The Tier Resource offers the functionality of + * managing the logic of QoS volume management. These are only logical levels of QoS and the real + * QoS (networking speed, volume replication, availability) must be configured manually in the + * infrastructure. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/TierResource + */ +@EnterpriseEdition +public class Tier extends DomainWrapper +{ + /** The datacenter where the tier belongs. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected Tier(final RestContext context, final TierDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Update tier information in the server with the data from this tier. + * + * @see API: + * http://community.abiquo.com/display/ABI20/TierResource#TierResource-Updateatier + */ + public void update() + { + target = context.getApi().getInfrastructureApi().updateTier(target); + } + + /** + * Retrieve the list of storage pools in this tier. + * + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return List of storage pools in this tier. + */ + public List listStoragePools() + { + StoragePoolsDto storagePools = + context.getApi().getInfrastructureApi().listStoragePools(target); + return wrap(context, StoragePool.class, storagePools.getCollection()); + } + + /** + * Retrieve a filtered list of storage pools in this tier. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return Filtered list of storage pools in this tier. + */ + public List listStoragePools(final Predicate filter) + { + return Lists.newLinkedList(filter(listStoragePools(), filter)); + } + + /** + * Retrieve the first storage pool matching the filter within the list of pools in this tier. + * + * @param filter Filter to be applied to the list. + * @see API: http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource- + * Retrievestoragepools + * @return First storage pool matching the filter or null if there is none. + */ + public StoragePool findStoragePool(final Predicate filter) + { + return Iterables.getFirst(filter(listStoragePools(), filter), null); + } + + // Parent access + + /** + * Retrieve the datacenter where this tier is. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveadatacenter + */ + public Datacenter getDatacenter() + { + Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId); + datacenter = wrap(context, Datacenter.class, dto); + return datacenter; + } + + // Delegate methods + + public String getDescription() + { + return target.getDescription(); + } + + public boolean getEnabled() + { + return target.getEnabled(); + } + + public Integer getId() + { + return target.getId(); + } + + public String getName() + { + return target.getName(); + } + + public void setDescription(final String description) + { + target.setDescription(description); + } + + public void setEnabled(final boolean enabled) + { + target.setEnabled(enabled); + } + + public void setName(final String name) + { + target.setName(name); + } + + @Override + public String toString() + { + return "Tier [id=" + getId() + ", description=" + getDescription() + ", enabled=" + + getEnabled() + ", name=" + getName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/DatacenterOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/DatacenterOptions.java new file mode 100644 index 0000000000..11998cb5b0 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/DatacenterOptions.java @@ -0,0 +1,64 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query datacenters. + * + * @author Francesc Montserrat + */ +public class DatacenterOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + DatacenterOptions options = new DatacenterOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private String ip; + + public Builder ip(final String ip) + { + this.ip = ip; + return this; + } + + public DatacenterOptions build() + { + DatacenterOptions options = new DatacenterOptions(); + if (ip != null) + { + options.queryParameters.put("ip", ip); + } + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/IpmiOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/IpmiOptions.java new file mode 100644 index 0000000000..4bcc60293f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/IpmiOptions.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query ipmi config. + * + * @author scastro + */ +public class IpmiOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + IpmiOptions options = new IpmiOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private Integer port; + + /** + * Set the optional hypervisor port. + */ + public Builder port(final int port) + { + this.port = port; + return this; + } + + public IpmiOptions build() + { + IpmiOptions options = new IpmiOptions(); + if (port != null) + { + options.queryParameters.put("port", port.toString()); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/MachineOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/MachineOptions.java new file mode 100644 index 0000000000..f29db2dc0f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/MachineOptions.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query machines. + * + * @author Francesc Montserrat + */ +public class MachineOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + MachineOptions options = new MachineOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private Integer port; + + private Boolean sync; + + /** + * Set the optional hypervisor port. + */ + public Builder port(final int port) + { + this.port = port; + return this; + } + + /** + * Set the optional sync param. + */ + public Builder sync(final boolean sync) + { + this.sync = sync; + return this; + } + + public MachineOptions build() + { + MachineOptions options = new MachineOptions(); + if (port != null) + { + options.queryParameters.put("port", port.toString()); + } + + if (sync != null) + { + options.queryParameters.put("sync", sync.toString()); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/StoragePoolOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/StoragePoolOptions.java new file mode 100644 index 0000000000..af546ef991 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/options/StoragePoolOptions.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure.options; + +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query storage pools. + * + * @author Francesc Montserrat + */ + +@EnterpriseEdition +public class StoragePoolOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + StoragePoolOptions options = new StoragePoolOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private Boolean sync; + + /** + * Set the optional sync param. + */ + public Builder sync(final boolean sync) + { + this.sync = sync; + return this; + } + + public StoragePoolOptions build() + { + StoragePoolOptions options = new StoragePoolOptions(); + if (sync != null) + { + options.queryParameters.put("sync", sync.toString()); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/AbstractPublicIp.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/AbstractPublicIp.java new file mode 100644 index 0000000000..c3da0e3f98 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/AbstractPublicIp.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.network.AbstractInfrastructureIpDto; + +/** + * Adds generic high level functionality to {@link AbstractInfrastructureIpDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public abstract class AbstractPublicIp> + extends Ip +{ + /** + * Constructor to be used only by the builder. + */ + protected AbstractPublicIp(final RestContext context, + final T target) + { + super(context, target); + } + + // Delegate methods + + public boolean isAvailable() + { + return target.isAvailable(); + } + + public boolean isQuarantine() + { + return target.isQuarantine(); + } + + public void setAvailable(final boolean available) + { + target.setAvailable(available); + } + + public void setQuarantine(final boolean quarantine) + { + target.setQuarantine(quarantine); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalIp.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalIp.java new file mode 100644 index 0000000000..b881bf3a4f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalIp.java @@ -0,0 +1,89 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds generic high level functionality to {@link ExternalIpDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class ExternalIp extends AbstractPublicIp +{ + /** + * Constructor to be used only by the builder. + */ + protected ExternalIp(final RestContext context, + final ExternalIpDto target) + { + super(context, target); + } + + // Domain operations + + @Override + public ExternalNetwork getNetwork() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.EXTERNAL_NETWORK), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.EXTERNAL_NETWORK); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VLANNetworkDto.class)); + + return wrap(context, ExternalNetwork.class, parser.apply(response)); + } + + @Override + public NetworkType getNetworkType() + { + return NetworkType.EXTERNAL; + } + + @Override + public String toString() + { + return "ExternalIp [networkType=" + getNetworkType() + ", available=" + isAvailable() + + ", quarantine=" + isQuarantine() + ", id=" + getId() + ", ip=" + getIp() + ", mac=" + + getMac() + ", name=" + getName() + ", networkName=" + getNetworkName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalNetwork.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalNetwork.java new file mode 100644 index 0000000000..8dfa92de70 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/ExternalNetwork.java @@ -0,0 +1,259 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to external {@link VLANNetworkDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource + */ +@EnterpriseEdition +public class ExternalNetwork extends Network +{ + /** The datacenter where the network belongs. */ + private Datacenter datacenter; + + /** The enterprise where the network belongs. */ + private Enterprise enterprise; + + /** + * Constructor to be used only by the builder. + */ + protected ExternalNetwork(final RestContext context, + final VLANNetworkDto target) + { + super(context, target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -DeleteanExternalNetwork + */ + @Override + public void delete() + { + context.getApi().getInfrastructureApi().deleteNetwork(target); + target = null; + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -CreateanewExternalNetwork + */ + @Override + public void save() + { + this.addEnterpriseLink(); + target = + context.getApi().getInfrastructureApi().createNetwork(datacenter.unwrap(), target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -UpdateanExternalNetwork + */ + @Override + public void update() + { + target = context.getApi().getInfrastructureApi().updateNetwork(target); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Public+IPs+Resource#PublicIPsResource- + * ReturnthelistofIPsforaPublicNetwork + */ + @Override + public List listIps(final IpOptions options) + { + ExternalIpsDto ips = + context.getApi().getInfrastructureApi().listExternalIps(target, options); + return wrap(context, ExternalIp.class, ips.getCollection()); + } + + @Override + public ExternalIp getIp(final Integer id) + { + ExternalIpDto ip = context.getApi().getInfrastructureApi().getExternalIp(target, id); + return wrap(context, ExternalIp.class, ip); + } + + // Parent access + + public Enterprise getEnterprise() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.ENTERPRISE), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.ENTERPRISE); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(EnterpriseDto.class)); + + enterprise = wrap(context, Enterprise.class, parser.apply(response)); + return enterprise; + } + + public Datacenter getDatacenter() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.DATACENTER), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.DATACENTER); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(DatacenterDto.class)); + + datacenter = wrap(context, Datacenter.class, parser.apply(response)); + return datacenter; + } + + private void addEnterpriseLink() + { + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + Enterprise.class); + + RESTLink link = enterprise.unwrap().getEditLink(); + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + + target.addLink(new RESTLink("enterprise", link.getHref())); + } + + // Builder + + public static Builder builder(final RestContext context, + final Datacenter datacenter, final Enterprise enterprise) + { + return new Builder(context, datacenter, enterprise); + } + + public static class Builder extends NetworkBuilder + { + private Datacenter datacenter; + + private Enterprise enterprise; + + public Builder(final RestContext context, + final Datacenter datacenter, final Enterprise enterprise) + { + super(context); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Enterprise.class); + this.datacenter = datacenter; + this.enterprise = enterprise; + this.context = context; + } + + public Builder datacenter(final Datacenter datacenter) + { + this.datacenter = datacenter; + return this; + } + + public Builder enterprise(final Enterprise enterprise) + { + this.enterprise = enterprise; + return this; + } + + public ExternalNetwork build() + { + VLANNetworkDto dto = new VLANNetworkDto(); + dto.setName(name); + dto.setTag(tag); + dto.setGateway(gateway); + dto.setAddress(address); + dto.setMask(mask); + dto.setPrimaryDNS(primaryDNS); + dto.setSecondaryDNS(secondaryDNS); + dto.setSufixDNS(sufixDNS); + dto.setDefaultNetwork(defaultNetwork == null ? Boolean.FALSE : defaultNetwork); + dto.setUnmanaged(Boolean.FALSE); + dto.setType(NetworkType.EXTERNAL); + + ExternalNetwork network = new ExternalNetwork(context, dto); + network.datacenter = datacenter; + network.enterprise = enterprise; + + return network; + } + + public static Builder fromExternalNetwork(final ExternalNetwork in) + { + return ExternalNetwork.builder(in.context, in.datacenter, in.enterprise) + .name(in.getName()).tag(in.getTag()).gateway(in.getGateway()) + .address(in.getAddress()).mask(in.getMask()).primaryDNS(in.getPrimaryDNS()) + .secondaryDNS(in.getSecondaryDNS()).sufixDNS(in.getSufixDNS()) + .defaultNetwork(in.getDefaultNetwork()); + } + } + + @Override + public String toString() + { + return "External " + super.toString(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Ip.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Ip.java new file mode 100644 index 0000000000..ef39edfd5f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Ip.java @@ -0,0 +1,85 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.server.core.infrastructure.network.AbstractIpDto; + +/** + * Adds generic high level functionality to {@link AbstractIpDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public abstract class Ip> extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Ip(final RestContext context, final T target) + { + super(context, target); + } + + // Domain operations + + public abstract N getNetwork(); + + public abstract NetworkType getNetworkType(); + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getIp() + { + return target.getIp(); + } + + public String getMac() + { + return target.getMac(); + } + + public String getName() + { + return target.getName(); + } + + public String getNetworkName() + { + return target.getNetworkName(); + } + + @Override + public String toString() + { + return "Ip [id=" + getId() + ", ip=" + getIp() + ", mac=" + getMac() + ", name=" + + getName() + ", networkName=" + getNetworkName() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java new file mode 100644 index 0000000000..8e700b647b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java @@ -0,0 +1,379 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +/** + * Adds generic high level functionality to {@link VLANNetworkDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public abstract class Network> extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected Network(final RestContext context, + final VLANNetworkDto target) + { + super(context, target); + } + + // Domain operations + + public abstract void save(); + + public abstract void update(); + + public abstract void delete(); + + public abstract List listIps(IpOptions options); + + public abstract T getIp(Integer id); + + public List listIps() + { + // Disable pagination by default + return listIps(IpOptions.builder().disablePagination().build()); + } + + public List listIps(final Predicate filter) + { + return Lists.newLinkedList(filter(listIps(), filter)); + } + + public T findIp(final Predicate filter) + { + return Iterables.getFirst(filter(listIps(), filter), null); + } + + public List listUnusedIps() + { + return listIps(IpPredicates. notUsed()); + } + + public T findUnusedIp(final Predicate filter) + { + return Iterables.getFirst(filter(listUnusedIps(), filter), null); + } + + // Builder + + public static class NetworkBuilder> + { + protected RestContext context; + + protected String name; + + protected Integer tag; + + protected String gateway; + + protected String address; + + protected Integer mask; + + protected String primaryDNS; + + protected String secondaryDNS; + + protected String sufixDNS; + + protected Boolean defaultNetwork; + + public NetworkBuilder(final RestContext context) + { + super(); + this.context = context; + } + + @SuppressWarnings("unchecked") + public T name(final String name) + { + this.name = name; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T tag(final Integer tag) + { + this.tag = tag; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T gateway(final String gateway) + { + this.gateway = gateway; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T address(final String address) + { + this.address = address; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T mask(final int mask) + { + this.mask = mask; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T primaryDNS(final String primaryDNS) + { + this.primaryDNS = primaryDNS; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T secondaryDNS(final String secondaryDNS) + { + this.secondaryDNS = secondaryDNS; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T sufixDNS(final String sufixDNS) + { + this.sufixDNS = sufixDNS; + return (T) this; + } + + @SuppressWarnings("unchecked") + public T defaultNetwork(final Boolean defaultNetwork) + { + this.defaultNetwork = defaultNetwork; + return (T) this; + } + } + + public PrivateNetwork toPrivateNetwork() + { + checkArgument(target.getType().equals(NetworkType.INTERNAL), + ValidationErrors.INVALID_NETWORK_TYPE + target.getType()); + + return wrap(context, PrivateNetwork.class, target); + + } + + public ExternalNetwork toExternalNetwork() + { + checkArgument(target.getType().equals(NetworkType.EXTERNAL), + ValidationErrors.INVALID_NETWORK_TYPE + target.getType()); + + return wrap(context, ExternalNetwork.class, target); + + } + + public PublicNetwork toPublicNetwork() + { + checkArgument(target.getType().equals(NetworkType.PUBLIC), + ValidationErrors.INVALID_NETWORK_TYPE + target.getType()); + + return wrap(context, PublicNetwork.class, target); + + } + + public UnmanagedNetwork toUnmanagedNetwork() + { + checkArgument(target.getType().equals(NetworkType.UNMANAGED), + ValidationErrors.INVALID_NETWORK_TYPE + target.getType()); + + return wrap(context, UnmanagedNetwork.class, target); + + } + + // Delegate methods + + public String getAddress() + { + return target.getAddress(); + } + + public Boolean getDefaultNetwork() + { + return target.getDefaultNetwork(); + } + + public String getGateway() + { + return target.getGateway(); + } + + public Integer getId() + { + return target.getId(); + } + + public Integer getMask() + { + return target.getMask(); + } + + public String getName() + { + return target.getName(); + } + + public String getPrimaryDNS() + { + return target.getPrimaryDNS(); + } + + public String getSecondaryDNS() + { + return target.getSecondaryDNS(); + } + + public String getSufixDNS() + { + return target.getSufixDNS(); + } + + public Integer getTag() + { + return target.getTag(); + } + + public NetworkType getType() + { + return target.getType(); + } + + public void setAddress(final String address) + { + target.setAddress(address); + } + + public void setDefaultNetwork(final Boolean defaultNetwork) + { + target.setDefaultNetwork(defaultNetwork); + } + + public void setGateway(final String gateway) + { + target.setGateway(gateway); + } + + public void setMask(final Integer mask) + { + target.setMask(mask); + } + + public void setName(final String name) + { + target.setName(name); + } + + public void setPrimaryDNS(final String primaryDNS) + { + target.setPrimaryDNS(primaryDNS); + } + + public void setSecondaryDNS(final String secondaryDNS) + { + target.setSecondaryDNS(secondaryDNS); + } + + public void setSufixDNS(final String sufixDNS) + { + target.setSufixDNS(sufixDNS); + } + + public void setTag(final Integer tag) + { + target.setTag(tag); + } + + @Override + public String toString() + { + return "Network [id=" + getId() + ", address=" + getAddress() + ", defaultNetwork=" + + getDefaultNetwork() + ", gateway=" + getGateway() + ", mask=" + getMask() + ", name=" + + getName() + ", primaryDNS=" + getPrimaryDNS() + ", secondaryDNS=" + getSecondaryDNS() + + ", suffixDNS=" + getSufixDNS() + ", tag=" + getTag() + ", type=" + getType() + "]"; + } + + public static Network< ? > wrapNetwork( + final RestContext context, final VLANNetworkDto dto) + { + if (dto == null) + { + return null; + } + + Network< ? > network = null; + + switch (dto.getType()) + { + case EXTERNAL: + network = wrap(context, ExternalNetwork.class, dto); + break; + case EXTERNAL_UNMANAGED: + // TODO: How do we manage External && unmanaged networks ? + throw new UnsupportedOperationException("EXTERNAL_UNMANAGED networks not supported yet"); + case INTERNAL: + network = wrap(context, PrivateNetwork.class, dto); + break; + case PUBLIC: + network = wrap(context, PublicNetwork.class, dto); + break; + case UNMANAGED: + network = wrap(context, UnmanagedNetwork.class, dto); + break; + } + + return network; + } + + public static List> wrapNetworks( + final RestContext context, final List dtos) + { + List> networks = Lists.newLinkedList(); + for (VLANNetworkDto dto : dtos) + { + networks.add(wrapNetwork(context, dto)); + } + return networks; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Nic.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Nic.java new file mode 100644 index 0000000000..78d7c3f295 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Nic.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.network.NicDto; + +/** + * Adds high level functionality to {@link NicDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/VirtualMachineNetworkConfiguration + */ +public class Nic extends DomainWrapper +{ + /** + * Constructor to be used only by the builder (if any). + */ + protected Nic(final RestContext context, final NicDto target) + { + super(context, target); + } + + // Parent access + + // Delegate methods + + public Integer getId() + { + return target.getId(); + } + + public String getIp() + { + return target.getIp(); + } + + public String getMac() + { + return target.getMac(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateIp.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateIp.java new file mode 100644 index 0000000000..1790551de4 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateIp.java @@ -0,0 +1,89 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds generic high level functionality to {@link PrivateIpDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class PrivateIp extends Ip +{ + /** + * Constructor to be used only by the builder. + */ + protected PrivateIp(final RestContext context, + final PrivateIpDto target) + { + super(context, target); + } + + // Domain operations + + @Override + public PrivateNetwork getNetwork() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.PRIVATE_NETWORK), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.PRIVATE_NETWORK); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VLANNetworkDto.class)); + + return wrap(context, PrivateNetwork.class, parser.apply(response)); + } + + @Override + public NetworkType getNetworkType() + { + return NetworkType.INTERNAL; + } + + @Override + public String toString() + { + return "PrivateIp [networkType=" + getNetworkType() + ", id=" + getId() + ", ip=" + getIp() + + ", mac=" + getMac() + ", name=" + getName() + ", networkName=" + getNetworkName() + + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateNetwork.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateNetwork.java new file mode 100644 index 0000000000..4d4abedf63 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PrivateNetwork.java @@ -0,0 +1,193 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Adds high level functionality to private {@link VLANNetworkDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Private+Network+Resource + */ +public class PrivateNetwork extends Network +{ + /** The virtual datacenter where the network belongs. */ + private VirtualDatacenter virtualDatacenter; + + /** + * Constructor to be used only by the builder. + */ + protected PrivateNetwork(final RestContext context, + final VLANNetworkDto target) + { + super(context, target); + } + + // Domain operations + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource + * -DeleteaPrivateNetwork + */ + @Override + public void delete() + { + context.getApi().getCloudApi().deletePrivateNetwork(target); + target = null; + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource + * -CreateaPrivateNetwork + */ + @Override + public void save() + { + target = + context.getApi().getCloudApi() + .createPrivateNetwork(virtualDatacenter.unwrap(), target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource + * -UpdateaPrivateNetwork + */ + @Override + public void update() + { + target = context.getApi().getCloudApi().updatePrivateNetwork(target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource + * -RetrievethelistofIPSofthePrivateNetwork + */ + @Override + public List listIps(final IpOptions options) + { + PrivateIpsDto ips = + context.getApi().getCloudApi().listPrivateNetworkIps(target, options); + return wrap(context, PrivateIp.class, ips.getCollection()); + } + + // Override to apply the filter in the server side + @Override + public List listUnusedIps() + { + IpOptions options = IpOptions.builder().disablePagination().free(true).build(); + PrivateIpsDto ips = + context.getApi().getCloudApi().listPrivateNetworkIps(target, options); + return wrap(context, PrivateIp.class, ips.getCollection()); + } + + @Override + public PrivateIp getIp(final Integer id) + { + PrivateIpDto ip = context.getApi().getCloudApi().getPrivateNetworkIp(target, id); + return wrap(context, PrivateIp.class, ip); + } + + // Builder + + public static Builder builder(final RestContext context) + { + return new Builder(context); + } + + public static class Builder extends NetworkBuilder + { + private VirtualDatacenter virtualDatacenter; + + public Builder(final RestContext context) + { + super(context); + this.context = context; + } + + public Builder virtualDatacenter(final VirtualDatacenter virtualDatacenter) + { + this.virtualDatacenter = virtualDatacenter; + return this; + } + + public PrivateNetwork build() + { + VLANNetworkDto dto = new VLANNetworkDto(); + dto.setName(name); + dto.setTag(tag); + dto.setGateway(gateway); + dto.setAddress(address); + dto.setMask(mask); + dto.setPrimaryDNS(primaryDNS); + dto.setSecondaryDNS(secondaryDNS); + dto.setSufixDNS(sufixDNS); + dto.setDefaultNetwork(defaultNetwork); + dto.setUnmanaged(false); + dto.setType(NetworkType.INTERNAL); + + PrivateNetwork network = new PrivateNetwork(context, dto); + network.virtualDatacenter = virtualDatacenter; + + return network; + } + + public static Builder fromPrivateNetwork(final PrivateNetwork in) + { + return PrivateNetwork.builder(in.context).name(in.getName()).tag(in.getTag()) + .gateway(in.getGateway()).address(in.getAddress()).mask(in.getMask()) + .primaryDNS(in.getPrimaryDNS()).secondaryDNS(in.getSecondaryDNS()) + .sufixDNS(in.getSufixDNS()).defaultNetwork(in.getDefaultNetwork()) + .virtualDatacenter(in.virtualDatacenter); + } + } + + @Override + public String toString() + { + return "Private " + super.toString(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicIp.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicIp.java new file mode 100644 index 0000000000..e2f0ebd0f3 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicIp.java @@ -0,0 +1,87 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds generic high level functionality to {@link PublicIpDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class PublicIp extends AbstractPublicIp +{ + /** + * Constructor to be used only by the builder. + */ + protected PublicIp(final RestContext context, + final PublicIpDto target) + { + super(context, target); + } + + @Override + public PublicNetwork getNetwork() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.PUBLIC_NETWORK), + ValidationErrors.MISSING_REQUIRED_LINK + ParentLinkName.PUBLIC_NETWORK); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VLANNetworkDto.class)); + + return wrap(context, PublicNetwork.class, parser.apply(response)); + } + + @Override + public NetworkType getNetworkType() + { + return NetworkType.PUBLIC; + } + + @Override + public String toString() + { + return "PublicIp [networkType=" + getNetworkType() + ", available=" + isAvailable() + + ", quarantine=" + isQuarantine() + ", id=" + getId() + ", ip=" + getIp() + ", mac=" + + getMac() + ", name=" + getName() + ", networkName=" + getNetworkName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicNetwork.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicNetwork.java new file mode 100644 index 0000000000..554166d80f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/PublicNetwork.java @@ -0,0 +1,215 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to public {@link VLANNetworkDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource + */ +@EnterpriseEdition +public class PublicNetwork extends Network +{ + /** The datacenter where the network belongs. */ + private Datacenter datacenter; + + /** + * Constructor to be used only by the builder. + */ + protected PublicNetwork(final RestContext context, + final VLANNetworkDto target) + { + super(context, target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -DeleteaPublicNetwork + */ + @Override + public void delete() + { + context.getApi().getInfrastructureApi().deleteNetwork(target); + target = null; + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -CreateanewPublicNetwork + */ + @Override + public void save() + { + target = + context.getApi().getInfrastructureApi().createNetwork(datacenter.unwrap(), target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -UpdateaPublicNetwork + */ + @Override + public void update() + { + target = context.getApi().getInfrastructureApi().updateNetwork(target); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Public+IPs+Resource#PublicIPsResource- + * ReturnthelistofIPsforaPublicNetwork + */ + @Override + public List listIps(final IpOptions options) + { + PublicIpsDto ips = + context.getApi().getInfrastructureApi().listPublicIps(target, options); + return wrap(context, PublicIp.class, ips.getCollection()); + } + + @Override + public PublicIp getIp(final Integer id) + { + PublicIpDto ip = context.getApi().getInfrastructureApi().getPublicIp(target, id); + return wrap(context, PublicIp.class, ip); + } + + // Parent access + + public Datacenter getDatacenter() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.DATACENTER), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.DATACENTER); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(DatacenterDto.class)); + + datacenter = wrap(context, Datacenter.class, parser.apply(response)); + return datacenter; + } + + // Builder + + public static Builder builder(final RestContext context, + final Datacenter datacenter) + { + return new Builder(context, datacenter); + } + + public static class Builder extends NetworkBuilder + { + private Datacenter datacenter; + + public Builder(final RestContext context, + final Datacenter datacenter) + { + super(context); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Enterprise.class); + this.datacenter = datacenter; + this.context = context; + } + + public Builder datacenter(final Datacenter datacenter) + { + this.datacenter = datacenter; + return this; + } + + public PublicNetwork build() + { + VLANNetworkDto dto = new VLANNetworkDto(); + dto.setName(name); + dto.setTag(tag); + dto.setGateway(gateway); + dto.setAddress(address); + dto.setMask(mask); + dto.setPrimaryDNS(primaryDNS); + dto.setSecondaryDNS(secondaryDNS); + dto.setSufixDNS(sufixDNS); + dto.setDefaultNetwork(defaultNetwork); + dto.setUnmanaged(false); + dto.setType(NetworkType.PUBLIC); + + PublicNetwork network = new PublicNetwork(context, dto); + network.datacenter = datacenter; + + return network; + } + + public static Builder fromPublicNetwork(final PublicNetwork in) + { + return PublicNetwork.builder(in.context, in.datacenter).name(in.getName()) + .tag(in.getTag()).gateway(in.getGateway()).address(in.getAddress()) + .mask(in.getMask()).primaryDNS(in.getPrimaryDNS()) + .secondaryDNS(in.getSecondaryDNS()).sufixDNS(in.getSufixDNS()) + .defaultNetwork(in.getDefaultNetwork()); + } + } + + @Override + public String toString() + { + return "Public " + super.toString(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedIp.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedIp.java new file mode 100644 index 0000000000..c6fb0cd363 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedIp.java @@ -0,0 +1,89 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds generic high level functionality to {@link UnmanagedIpDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class UnmanagedIp extends AbstractPublicIp +{ + /** + * Constructor to be used only by the builder. + */ + protected UnmanagedIp(final RestContext context, + final UnmanagedIpDto target) + { + super(context, target); + } + + // Domain operations + + @Override + public UnmanagedNetwork getNetwork() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.UNMANAGED_NETWORK), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.UNMANAGED_NETWORK); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(VLANNetworkDto.class)); + + return wrap(context, UnmanagedNetwork.class, parser.apply(response)); + } + + @Override + public NetworkType getNetworkType() + { + return NetworkType.UNMANAGED; + } + + @Override + public String toString() + { + return "UnmanagedIp [networkType=" + getNetworkType() + ", available=" + isAvailable() + + ", quarantine=" + isQuarantine() + ", id=" + getId() + ", ip=" + getIp() + ", mac=" + + getMac() + ", name=" + getName() + ", networkName=" + getNetworkName() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedNetwork.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedNetwork.java new file mode 100644 index 0000000000..81c0ddd877 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/UnmanagedNetwork.java @@ -0,0 +1,260 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.reference.rest.ParentLinkName; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.inject.TypeLiteral; + +/** + * Adds high level functionality to external {@link VLANNetworkDto}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource + */ +@EnterpriseEdition +public class UnmanagedNetwork extends Network +{ + /** The datacenter where the network belongs. */ + private Datacenter datacenter; + + /** The enterprise where the network belongs. */ + private Enterprise enterprise; + + /** + * Constructor to be used only by the builder. + */ + protected UnmanagedNetwork(final RestContext context, + final VLANNetworkDto target) + { + super(context, target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -DeleteanUnmanagedNetwork + */ + @Override + public void delete() + { + context.getApi().getInfrastructureApi().deleteNetwork(target); + target = null; + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -CreateanewUnmanagedNetwork + */ + @Override + public void save() + { + this.addEnterpriseLink(); + target = + context.getApi().getInfrastructureApi().createNetwork(datacenter.unwrap(), target); + } + + /** + * @see API: + * http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource + * -UpdateanUnmanagedNetwork + */ + @Override + public void update() + { + target = context.getApi().getInfrastructureApi().updateNetwork(target); + } + + /** + * @see API: http://community.abiquo.com/display/ABI20/Public+IPs+Resource#PublicIPsResource- + * ReturnthelistofIPsforaPublicNetwork + */ + @Override + public List listIps(final IpOptions options) + { + UnmanagedIpsDto ips = + context.getApi().getInfrastructureApi().listUnmanagedIps(target, options); + return wrap(context, UnmanagedIp.class, ips.getCollection()); + } + + @Override + public UnmanagedIp getIp(final Integer id) + { + UnmanagedIpDto ip = context.getApi().getInfrastructureApi().getUnmanagedIp(target, id); + return wrap(context, UnmanagedIp.class, ip); + } + + // Parent access + + public Enterprise getEnterprise() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.ENTERPRISE), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.ENTERPRISE); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(EnterpriseDto.class)); + + enterprise = wrap(context, Enterprise.class, parser.apply(response)); + return enterprise; + } + + public Datacenter getDatacenter() + { + RESTLink link = + checkNotNull(target.searchLink(ParentLinkName.DATACENTER), + ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.DATACENTER); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get(DatacenterDto.class)); + + datacenter = wrap(context, Datacenter.class, parser.apply(response)); + return datacenter; + } + + private void addEnterpriseLink() + { + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + Enterprise.class); + + RESTLink link = enterprise.unwrap().searchLink("edit"); + + checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); + + target.addLink(new RESTLink("enterprise", link.getHref())); + } + + // Builder + + public static Builder builder(final RestContext context, + final Datacenter datacenter, final Enterprise enterprise) + { + return new Builder(context, datacenter, enterprise); + } + + public static class Builder extends NetworkBuilder + { + private Datacenter datacenter; + + private Enterprise enterprise; + + public Builder(final RestContext context, + final Datacenter datacenter, final Enterprise enterprise) + { + super(context); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); + checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Enterprise.class); + this.datacenter = datacenter; + this.enterprise = enterprise; + this.context = context; + } + + public Builder datacenter(final Datacenter datacenter) + { + this.datacenter = datacenter; + return this; + } + + public Builder enterprise(final Enterprise enterprise) + { + this.enterprise = enterprise; + return this; + } + + public UnmanagedNetwork build() + { + VLANNetworkDto dto = new VLANNetworkDto(); + dto.setName(name); + dto.setTag(tag); + dto.setGateway(gateway); + dto.setAddress(address); + dto.setMask(mask); + dto.setPrimaryDNS(primaryDNS); + dto.setSecondaryDNS(secondaryDNS); + dto.setSufixDNS(sufixDNS); + dto.setDefaultNetwork(defaultNetwork); + dto.setUnmanaged(true); + dto.setType(NetworkType.UNMANAGED); + + UnmanagedNetwork network = new UnmanagedNetwork(context, dto); + network.datacenter = datacenter; + network.enterprise = enterprise; + + return network; + } + + public static Builder fromUnmanagedNetwork(final UnmanagedNetwork in) + { + return UnmanagedNetwork.builder(in.context, in.datacenter, in.enterprise) + .name(in.getName()).tag(in.getTag()).gateway(in.getGateway()) + .address(in.getAddress()).mask(in.getMask()).primaryDNS(in.getPrimaryDNS()) + .secondaryDNS(in.getSecondaryDNS()).sufixDNS(in.getSufixDNS()) + .defaultNetwork(in.getDefaultNetwork()); + } + } + + @Override + public String toString() + { + return "Unmanaged " + super.toString(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/IpOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/IpOptions.java new file mode 100644 index 0000000000..d44191bed9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/IpOptions.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network.options; + +import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Available options to query ips. + * + * @author Francesc Montserrat + */ +public class IpOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + IpOptions options = new IpOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder extends BaseFilterOptionsBuilder + { + private Boolean free; + + public Builder free(final boolean free) + { + this.free = free; + return this; + } + + public IpOptions build() + { + IpOptions options = new IpOptions(); + + if (free != null) + { + options.queryParameters.put("free", String.valueOf(free)); + } + + return addFilterOptions(options); + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/NetworkOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/NetworkOptions.java new file mode 100644 index 0000000000..f97d182c96 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/network/options/NetworkOptions.java @@ -0,0 +1,81 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.abiquo.model.enumerator.NetworkType; + +/** + * Available options to query networks. + * + * @author Francesc Montserrat + */ +public class NetworkOptions extends BaseHttpRequestOptions +{ + public static Builder builder() + { + return new Builder(); + } + + @Override + protected Object clone() throws CloneNotSupportedException + { + NetworkOptions options = new NetworkOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static class Builder + { + private NetworkType type; + + private Boolean all; + + public Builder type(final NetworkType type) + { + this.type = type; + return this; + } + + public Builder all(final boolean all) + { + this.all = all; + return this; + } + + public NetworkOptions build() + { + NetworkOptions options = new NetworkOptions(); + + if (type != null) + { + options.queryParameters.put("type", String.valueOf(type)); + } + + if (all != null) + { + options.queryParameters.put("all", String.valueOf(all)); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/FilterOptions.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/FilterOptions.java new file mode 100644 index 0000000000..34b62699ba --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/FilterOptions.java @@ -0,0 +1,143 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.options.search; + +import org.jclouds.abiquo.domain.options.search.reference.OrderBy; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.collect.Multimap; + +/** + * Available options to filter and pagination methods. + * + * @author Francesc Montserrat + */ +public class FilterOptions extends BaseHttpRequestOptions +{ + @Override + protected Object clone() throws CloneNotSupportedException + { + FilterOptions options = new FilterOptions(); + options.queryParameters.putAll(queryParameters); + return options; + } + + public static FilterOptionsBuilder builder() + { + return new FilterOptionsBuilder(); + } + + public static class FilterOptionsBuilder extends BaseFilterOptionsBuilder + { + public FilterOptions build() + { + FilterOptions options = new FilterOptions(); + return super.addFilterOptions(options); + } + } + + @SuppressWarnings("unchecked") + public static class BaseFilterOptionsBuilder> + { + protected Integer startWith; + + protected Integer limit; + + protected OrderBy by; + + protected String has; + + protected Boolean asc; + + public T startWith(final int startWith) + { + this.startWith = startWith; + return (T) this; + } + + public T has(final String has) + { + this.has = has; + return (T) this; + } + + public T limit(final int limit) + { + this.limit = limit; + return (T) this; + } + + public T orderBy(final OrderBy by) + { + this.by = by; + return (T) this; + } + + public T ascendant(final boolean asc) + { + this.asc = asc; + return (T) this; + } + + public T descendant(final boolean desc) + { + this.asc = !desc; + return (T) this; + } + + public T disablePagination() + { + this.limit = 0; + return (T) this; + } + + protected O addFilterOptions(final O options) + { + Multimap queryParameters = options.buildQueryParameters(); + + if (startWith != null) + { + queryParameters.put("startwith", startWith.toString()); + } + + if (limit != null) + { + queryParameters.put("limit", limit.toString()); + } + + if (has != null) + { + queryParameters.put("has", has); + } + + if (by != null) + { + queryParameters.put("by", by.getValue()); + } + + if (asc != null) + { + queryParameters.put("asc", asc.toString()); + } + + return options; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/reference/OrderBy.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/reference/OrderBy.java new file mode 100644 index 0000000000..75fede5905 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/options/search/reference/OrderBy.java @@ -0,0 +1,44 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.options.search.reference; + +/** + * Available fields to order search results. + * + * @author Francesc Montserrat + * @author Ignasi Barrera + */ +public enum OrderBy +{ + NAME("name"), ID("id"), VIRTUALDATACENTER("virtualdatacenter"), VIRTUALMACHINE("virtualmachine"), VIRTUALAPPLIANCE( + "virtualappliance"), TIER("tier"), TOTALSIZE("totalsize"), STATE("state"); + + public String value; + + public String getValue() + { + return value; + } + + private OrderBy(final String value) + { + this.value = value; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncJob.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncJob.java new file mode 100644 index 0000000000..19d47fef4e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncJob.java @@ -0,0 +1,87 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.task; + + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.task.Job.JobState; +import com.abiquo.server.core.task.Job.JobType; +import com.abiquo.server.core.task.JobDto; + +/** + * Adds generic high level functionality to {JobDto}. + * + * @author Francesc Montserrat + */ +public class AsyncJob extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected AsyncJob(final RestContext context, final JobDto target) + { + super(context, target); + } + + // Delegate methods + + public String getDescription() + { + return target.getDescription(); + } + + public String getId() + { + return target.getId(); + } + + public JobState getRollbackState() + { + return target.getRollbackState(); + } + + public JobState getState() + { + return target.getState(); + } + + public long getTimestamp() + { + return target.getTimestamp(); + } + + public JobType getType() + { + return target.getType(); + } + + @Override + public String toString() + { + return "AsyncJob [id=" + getId() + ", description=" + getDescription() + ", rollbackState=" + + getRollbackState() + ", state=" + getState() + ", timestamp=" + getTimestamp() + + ", type=" + getType() + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java new file mode 100644 index 0000000000..7e1f02fd48 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.task; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.task.TaskDto; +import com.abiquo.server.core.task.enums.TaskState; +import com.abiquo.server.core.task.enums.TaskType; + +/** + * Adds generic high level functionality to {TaskDto}. + * + * @author Francesc Montserrat + */ +public class AsyncTask extends DomainWrapper +{ + /** + * Constructor to be used only by the builder. + */ + protected AsyncTask(final RestContext context, + final TaskDto target) + { + super(context, target); + } + + // Domain operations + + /** + * Refresh the state of the task. + */ + public void refresh() + { + RESTLink self = + checkNotNull(target.searchLink("self"), ValidationErrors.MISSING_REQUIRED_LINK + "self"); + + target = context.getApi().getTaskApi().getTask(self); + } + + // Children access + + /** + * Get the individual jobs that compose the current task. + */ + public List getJobs() + { + return wrap(context, AsyncJob.class, target.getJobs().getCollection()); + } + + // Delegate methods + + public String getOwnerId() + { + return target.getOwnerId(); + } + + public TaskState getState() + { + return target.getState(); + } + + public String getTaskId() + { + return target.getTaskId(); + } + + public long getTimestamp() + { + return target.getTimestamp(); + } + + public TaskType getType() + { + return target.getType(); + } + + public String getUserId() + { + return target.getUserId(); + } + + @Override + public String toString() + { + return "AsyncTask [taskId=" + getTaskId() + ", ownerId=" + getOwnerId() + ", timestamp=" + + getTimestamp() + ", userId=" + getUserId() + ", state=" + getState() + ", type=" + + getType() + "]"; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/util/LinkUtils.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/util/LinkUtils.java new file mode 100644 index 0000000000..485a4130ca --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/util/LinkUtils.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.util; + +import static com.google.common.collect.Iterables.filter; + +import java.util.List; + +import org.jclouds.abiquo.predicates.LinkPredicates; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.google.common.collect.Lists; + +/** + * Utility method to work with {@link RESTLink} objects. + * + * @author Ignasi Barrera + */ +public class LinkUtils +{ + /** + * Get the link that points to the current resource. + * + * @param dto The target dto. + * @return The link to the current resource. + */ + public static RESTLink getSelfLink(final SingleResourceTransportDto dto) + { + RESTLink link = dto.searchLink("edit"); + return link == null ? dto.searchLink("self") : link; + } + + /** + * Filter the given link list and return only the links that point to a NIC. + * + * @param links The list with the links to filter. + * @return A lsit with all links taht point to a NIC. + */ + public static List filterNicLinks(final List links) + { + return Lists.newLinkedList(filter(links, LinkPredicates.isNic())); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java new file mode 100644 index 0000000000..74621ac69e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java @@ -0,0 +1,57 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.handlers; + +import javax.annotation.Resource; + +import org.jclouds.abiquo.events.monitor.MonitorEvent; +import org.jclouds.logging.Logger; + +/** + * Base class for all {@link MonitorEvent} handlers. + * + * @author Ignasi Barrera + */ +public abstract class AbstractEventHandler +{ + @Resource + protected Logger logger = Logger.NULL; + + /** + * Checks if the current handler must handle the dispatched event. + * + * @param event The event being dispatched. + * @return Boolean indicating if the event must be handled by the current handler. + */ + protected abstract boolean handles(MonitorEvent event); + + // Public getters and setters to allow non-guice code to set the appropriate logger + + public Logger getLogger() + { + return logger; + } + + public void setLogger(final Logger logger) + { + this.logger = logger; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java new file mode 100644 index 0000000000..7973fe31dc --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java @@ -0,0 +1,169 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.handlers; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.concurrent.CountDownLatch; + +import org.jclouds.abiquo.events.monitor.MonitorEvent; +import org.jclouds.logging.Logger; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Throwables; +import com.google.common.collect.Lists; +import com.google.common.eventbus.Subscribe; + +/** + * An event handler that blocks the thread until all monitored objects have been finished being + * watched. + *

+ * Due to Guava Issue + * 786 {@link #handle(MonitorEvent)} is marked finalto avoid having duplicate + * events. + * + * @author Ignasi Barrera + * @param The monitored object. + */ +public class BlockingEventHandler extends AbstractEventHandler +{ + /** The signal used to lock the thread. */ + @VisibleForTesting + CountDownLatch completeSignal; + + /** + * The objects being locked. + *

+ * This class handles events in a thread safe way. Otherwise this collections should be + * synchronised. + */ + protected List lockedObjects; + + public BlockingEventHandler(final T... lockedObjects) + { + this(Logger.NULL, lockedObjects); + } + + public BlockingEventHandler(final Logger logger, final T... lockedObjects) + { + super(); + checkArgument(checkNotNull(lockedObjects, "lockedObjects").length > 0, + "must provide at least one object"); + this.logger = checkNotNull(logger, "logger"); + this.lockedObjects = Lists.newArrayList(lockedObjects); + this.logger.debug("created BlockingEventHandler locking %s objects", lockedObjects.length); + } + + @Override + protected boolean handles(final MonitorEvent event) + { + logger.debug("checking if %s event on %s must be handled by %s", event.getType(), + event.getTarget(), this); + boolean handles = lockedObjects.contains(event.getTarget()); + logger.debug("%s event on %s must %sbe handled", event.getType(), event.getTarget(), + handles ? "" : "not "); + return handles; + } + + /** + * Handles the dispatched event in a thread safe way. + *

+ * Due to Guava Issue + * 786 {@link #handle(MonitorEvent)} is marked finalto avoid having duplicate + * events. + * + * @see {@link #doBeforeRelease(MonitorEvent)} + */ + @Subscribe + public final void handle(final MonitorEvent event) + { + if (handles(event)) + { + logger.debug("handling %s", event); + + try + { + doBeforeRelease(event); + } + finally + { + // Always release the lock, even if the handler code fails + release(event.getTarget()); + } + } + } + + /** + * Blocks the thread until all locked objects have been released. + */ + public void lock() + { + // When invoking the lock, it is possible that all events have + // already been consumed. If there are no objects to monitor, + // just ignore the lock. + if (!lockedObjects.isEmpty()) + { + try + { + completeSignal = new CountDownLatch(lockedObjects.size()); + logger.debug("creating lock for %s object(s)", lockedObjects.size()); + completeSignal.await(); + } + catch (InterruptedException ex) + { + Throwables.propagate(ex); + } + } + else + { + logger.debug("there is nothing to watch. Ignoring lock."); + } + } + + /** + * Releases the lock on the given object. + */ + protected void release(final T target) + { + logger.debug("releasing %s", target); + lockedObjects.remove(target); + + // The completeSignal might be null if the events have been consumed + // before acquiring the lock + if (completeSignal != null) + { + completeSignal.countDown(); + logger.debug("releasing lock for %s. %s remaining objects", target, + completeSignal.getCount()); + } + } + + /** + * Convenience method to bypass the Guava Issue 786 that + * forces the subscriber method to be final. + */ + protected void doBeforeRelease(final MonitorEvent event) + { + // Let subclasses may override it to customize behavior + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java new file mode 100644 index 0000000000..3bfbb59d0b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.monitor; + +/** + * Event dispatched when a monitoring job completes without error. + * + * @author Ignasi Barrera + */ +public class CompletedEvent extends MonitorEvent +{ + public CompletedEvent(final T target) + { + super(MonitorEvent.Type.COMPLETED, target); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java new file mode 100644 index 0000000000..e2be9763de --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.monitor; + +/** + * Event dispatched when a monitoring job completes with errors. + * + * @author Ignasi Barrera + */ +public class FailedEvent extends MonitorEvent +{ + public FailedEvent(final T target) + { + super(MonitorEvent.Type.FAILED, target); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java new file mode 100644 index 0000000000..e03dd791f2 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.monitor; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * base class for all monitor events. + * + * @author Ignasi Barrera + */ +public class MonitorEvent +{ + /** + * The type of the event. + */ + public static enum Type + { + COMPLETED, FAILED, TIMEOUT; + } + + /** The type of the event. */ + private Type type; + + /** The target object being monitored. */ + private T target; + + public MonitorEvent(final Type type, final T target) + { + super(); + this.type = checkNotNull(type, "type"); + this.target = checkNotNull(target, "target"); + } + + public Type getType() + { + return type; + } + + public void setType(final Type type) + { + this.type = type; + } + + public T getTarget() + { + return target; + } + + public void setTarget(final T target) + { + this.target = target; + } + + @Override + public String toString() + { + return "MonitorEvent [type=" + type + ", target=" + target + "]"; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java new file mode 100644 index 0000000000..6effde8184 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.monitor; + +/** + * Event dispatched when a monitoring job times out. + * + * @author Ignasi Barrera + */ +public class TimeoutEvent extends MonitorEvent +{ + public TimeoutEvent(final T target) + { + super(MonitorEvent.Type.TIMEOUT, target); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminApi.java new file mode 100644 index 0000000000..e01e6c6db9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminApi.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.abiquo.server.core.enterprise.RolesDto; +import com.abiquo.server.core.enterprise.UserDto; + +/** + * Provides synchronous access to Abiquo Admin API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see AdminAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface AdminApi +{ + /* ********************** User ********************** */ + + /** + * Get the information of the current user. + * + * @return The information of the current user. + */ + UserDto getCurrentUser(); + + /* ********************** Role ********************** */ + + /** + * List global roles. + * + * @return The list of global Roles. + */ + RolesDto listRoles(); + + /** + * List enterprise roles. + * + * @return The list of Roles for the given enterprise. + */ + RolesDto listRoles(EnterpriseDto enterprise); + + /** + * Retrieves the role of the given user. + * + * @param user The user. + * @return The role of the user. + */ + RoleDto getRole(UserDto user); + + /** + * Get the given role. + * + * @param roleId The id of the role. + * @return The role or null if it does not exist. + */ + RoleDto getRole(Integer roleId); + + /** + * Deletes an existing role. + * + * @param role The role to delete. + */ + void deleteRole(final RoleDto role); + + /** + * Updates an existing role. + * + * @param role The new attributes for the role. + * @return The updated role. + */ + RoleDto updateRole(RoleDto role); + + /** + * Create a new role. + * + * @param role The role to be created. + * @return The created role. + */ + RoleDto createRole(RoleDto role); + + /** + * Get privileges of the given role. + * + * @param role The role. + * @return The list of privileges. + */ + PrivilegesDto listPrivileges(RoleDto role); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminAsyncApi.java new file mode 100644 index 0000000000..3209c72b24 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/AdminAsyncApi.java @@ -0,0 +1,153 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.functions.enterprise.ParseEnterpriseId; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.abiquo.server.core.enterprise.RolesDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Admin API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see AdminApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +public interface AdminAsyncApi +{ + /*********************** Login ***********************/ + + /** + * @see AdminApi#getCurrentUser() + */ + @GET + @Path("/login") + @Consumes(UserDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getCurrentUser(); + + /*********************** Role ***********************/ + + /** + * @see AdminApi#listRoles() + */ + @GET + @Path("/admin/roles") + @Consumes(RolesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listRoles(); + + /** + * @see AdminApi#listRoles(Enterprise enterprise) + */ + @GET + @Path("/admin/roles") + @Consumes(RolesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listRoles( + @QueryParam("identerprise") @ParamParser(ParseEnterpriseId.class) final EnterpriseDto enterprise); + + /** + * @see AdminApi#getRole(UserDto) + */ + @GET + @Consumes(RoleDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getRole( + @EndpointLink("role") @BinderParam(BindToPath.class) UserDto user); + + /** + * @see AdminApi#getRole(Integer) + */ + @GET + @Path("/admin/roles/{role}") + @Consumes(RoleDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getRole(@PathParam("role") Integer roleId); + + /** + * @see AdminApi#deleteRole(RoleDto) + */ + @DELETE + ListenableFuture deleteRole( + @EndpointLink("edit") @BinderParam(BindToPath.class) RoleDto role); + + /** + * @see AdminApi#updateRole(RoleDto) + */ + @PUT + @Produces(RoleDto.BASE_MEDIA_TYPE) + @Consumes(RoleDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateRole( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) RoleDto role); + + /** + * @see AdminApi#createRole(RoleDto) + */ + @POST + @Path("/admin/roles") + @Produces(RoleDto.BASE_MEDIA_TYPE) + @Consumes(RoleDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createRole(@BinderParam(BindToXMLPayload.class) RoleDto role); + + /** + * @see AdminApi#listPrivileges(RoleDto) + */ + @GET + @Consumes(PrivilegesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPrivileges( + @EndpointLink("privileges") @BinderParam(BindToPath.class) RoleDto role); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java new file mode 100644 index 0000000000..e6ef57ff24 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudApi.java @@ -0,0 +1,680 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.cloud.options.VirtualApplianceOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.concurrent.Timeout; + +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceStateDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.cloud.VirtualMachineStateDto; +import com.abiquo.server.core.cloud.VirtualMachineTaskDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VMNetworkConfigurationsDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; +import com.abiquo.server.core.infrastructure.storage.DisksManagementDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; + +/** + * Provides synchronous access to Abiquo Cloud API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see CloudAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface CloudApi +{ + /*********************** Virtual Datacenter ***********************/ + + /** + * List all virtual datacenters. + * + * @param options Optional query params. + * @return The list of Datacenters. + */ + VirtualDatacentersDto listVirtualDatacenters(VirtualDatacenterOptions options); + + /** + * Get the given virtual datacenter. + * + * @param virtualDatacenterId The id of the virtual datacenter. + * @return The virtual datacenter or null if it does not exist. + */ + VirtualDatacenterDto getVirtualDatacenter(Integer virtualDatacenterId); + + /** + * Create a new virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter to be created. + * @param datacenter Datacenter where the virtualdatacenter will be deployed. + * @param enterprise Enterprise of the virtual datacenter. + * @return The created virtual datacenter. + */ + VirtualDatacenterDto createVirtualDatacenter(VirtualDatacenterDto virtualDatacenter, + DatacenterDto datacenter, EnterpriseDto enterprise); + + /** + * Updates an existing virtual datacenter. + * + * @param virtualDatacenter The new attributes for the virtual datacenter. + * @return The updated virtual datacenter. + */ + VirtualDatacenterDto updateVirtualDatacenter(VirtualDatacenterDto virtualDatacenter); + + /** + * Deletes an existing virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter to delete. + */ + void deleteVirtualDatacenter(VirtualDatacenterDto virtualDatacenter); + + /** + * List all available templates for the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The list of available templates. + */ + VirtualMachineTemplatesDto listAvailableTemplates(VirtualDatacenterDto virtualDatacenter); + + /** + * List all available templates for the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param options Filtering options. + * @return The list of available templates. + */ + VirtualMachineTemplatesDto listAvailableTemplates(VirtualDatacenterDto virtualDatacenter, + VirtualMachineTemplateOptions options); + + /** + * List all available ips to purchase in the datacenter by the virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param options Filtering options. + * @return The list of available ips. + */ + PublicIpsDto listAvailablePublicIps(VirtualDatacenterDto virtualDatacenter, IpOptions options); + + /** + * List all purchased public ip addresses in the virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param options Filtering options. + * @return The list of purchased ips. + */ + PublicIpsDto listPurchasedPublicIps(VirtualDatacenterDto virtualDatacenter, IpOptions options); + + /** + * Purchase a public IP. + * + * @param ip The public ip address to purchase. + * @return The purchased public ip. + */ + PublicIpDto purchasePublicIp(PublicIpDto publicIp); + + /** + * Release a public IP. + * + * @param ip The public ip address to purchase. + * @return The release public ip. + */ + PublicIpDto releasePublicIp(PublicIpDto publicIp); + + /** + * List the storage tiers available for the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The storage tiers available to the given virtual datacenter. + */ + @EnterpriseEdition + TiersDto listStorageTiers(VirtualDatacenterDto virtualDatacenter); + + /** + * Get the storage tier from the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param The id of the storage tier. + * @return The storage tiers available to the given virtual datacenter. + */ + @EnterpriseEdition + TierDto getStorageTier(VirtualDatacenterDto virtualDatacenter, Integer tierId); + + /*********************** Private Network ***********************/ + + /** + * Get the default network of the virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The default network of the virtual datacenter. + */ + VLANNetworkDto getDefaultNetwork(VirtualDatacenterDto virtualDatacenter); + + /** + * Set the default network of the virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param network The default network. + */ + void setDefaultNetwork(VirtualDatacenterDto virtualDatacenter, VLANNetworkDto network); + + /** + * List all private networks for a virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The list of private networks for the virtual datacenter. + */ + VLANNetworksDto listPrivateNetworks(VirtualDatacenterDto virtualDatacenter); + + /** + * Get the given private network from the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param virtualApplianceId The id of the private network. + * @return The private network or null if it does not exist. + */ + VLANNetworkDto getPrivateNetwork(VirtualDatacenterDto virtualDatacenter, + Integer privateNetworkId); + + /** + * Create a new private network in a virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param privateNetwork The private network to be created. + * @return The created private network. + */ + VLANNetworkDto createPrivateNetwork(final VirtualDatacenterDto virtualDatacenter, + final VLANNetworkDto privateNetwork); + + /** + * Updates an existing private network from the given virtual datacenter. + * + * @param privateNetwork The new attributes for the private network. + * @return The updated private network. + */ + VLANNetworkDto updatePrivateNetwork(VLANNetworkDto privateNetwork); + + /** + * Deletes an existing private network. + * + * @param privateNetwork The private network to delete. + */ + void deletePrivateNetwork(VLANNetworkDto privateNetwork); + + /*********************** Private Network IPs ***********************/ + + /** + * List all ips for a private network. + * + * @param network The private network. + * @return The list of ips for the private network. + */ + PrivateIpsDto listPrivateNetworkIps(VLANNetworkDto network); + + /** + * List all ips for a private network with options. + * + * @param network The private network. + * @param options Filtering options. + * @return The list of ips for the private network. + */ + PrivateIpsDto listPrivateNetworkIps(VLANNetworkDto network, IpOptions options); + + /** + * Get the requested ip from the given private network. + * + * @param network The private network. + * @param ipId The id of the ip to get. + * @return The requested ip. + */ + PrivateIpDto getPrivateNetworkIp(VLANNetworkDto network, Integer ipId); + + /*********************** Virtual Appliance ***********************/ + + /** + * List all virtual appliance for a virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The list of virtual appliances for the virtual datacenter. + */ + VirtualAppliancesDto listVirtualAppliances(VirtualDatacenterDto virtualDatacenter); + + /** + * Get the given virtual appliance from the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param virtualApplianceId The id of the virtual appliance. + * @return The virtual appliance or null if it does not exist. + */ + VirtualApplianceDto getVirtualAppliance(VirtualDatacenterDto virtualDatacenter, + Integer virtualApplianceId); + + /** + * Create a new virtual appliance in a virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param virtualAppliance The virtual appliance to be created. + * @return The created virtual appliance. + */ + VirtualApplianceDto createVirtualAppliance(VirtualDatacenterDto virtualDatacenter, + VirtualApplianceDto virtualAppliance); + + /** + * Updates an existing virtual appliance from the given virtual datacenter. + * + * @param virtualAppliance The new attributes for the virtual appliance. + * @return The updated virtual appliance. + */ + VirtualApplianceDto updateVirtualAppliance(VirtualApplianceDto virtualAppliance); + + /** + * Deletes an existing virtual appliance. + * + * @param virtualAppliance The virtual appliance to delete. + */ + void deleteVirtualAppliance(VirtualApplianceDto virtualAppliance); + + /** + * Deletes an existing virtual appliance. + * + * @param virtualAppliance The virtual appliance to delete. + * @param options The options to customize the delete operation (e.g. Force delete). + */ + void deleteVirtualAppliance(VirtualApplianceDto virtualAppliance, + VirtualApplianceOptions options); + + /** + * Deploy a virtual appliance. + * + * @param virtualAppliance The virtual appliance to deploy + * @param options the extra options for the deploy process. + * @return Response message to the deploy request. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto deployVirtualAppliance(VirtualApplianceDto virtualAppliance, + VirtualMachineTaskDto options); + + /** + * Undeploy a virtual appliance. + * + * @param virtualAppliance The virtual appliance to undeploy + * @param options the extra options for the undeploy process. + * @return Response message to the undeploy request. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto undeployVirtualAppliance(VirtualApplianceDto virtualAppliance, + VirtualMachineTaskDto options); + + /** + * Get the state of the given virtual appliance. + * + * @param virtualAppliance The given virtual appliance. + * @return The state of the given virtual appliance. + */ + VirtualApplianceStateDto getVirtualApplianceState(VirtualApplianceDto virtualAppliance); + + /*********************** Virtual Machine ***********************/ + + /** + * List all virtual machines for a virtual appliance. + * + * @param virtualAppliance The virtual appliance. + * @return The list of virtual machines for the virtual appliance. + */ + VirtualMachinesWithNodeExtendedDto listVirtualMachines(VirtualApplianceDto virtualAppliance); + + /** + * List all virtual machines for a virtual appliance. + * + * @param virtualAppliance The virtual appliance. + * @param options The options to filter the list of virtual machines. + * @return The list of virtual machines for the virtual appliance. + */ + VirtualMachinesWithNodeExtendedDto listVirtualMachines(VirtualApplianceDto virtualAppliance, + VirtualMachineOptions options); + + /** + * Get the given virtual machine from the given virtual machine. + * + * @param virtualAppliance The virtual appliance. + * @param virtualMachineId The id of the virtual machine. + * @return The virtual machine or null if it does not exist. + */ + VirtualMachineWithNodeExtendedDto getVirtualMachine(VirtualApplianceDto virtualAppliance, + Integer virtualMachineId); + + /** + * Create a new virtual machine in a virtual appliance. + * + * @param virtualAppliance The virtual appliance. + * @param virtualMachine The virtual machine to be created. + * @return The created virtual machine. + */ + VirtualMachineWithNodeExtendedDto createVirtualMachine(VirtualApplianceDto virtualAppliance, + VirtualMachineWithNodeExtendedDto virtualMachine); + + /** + * Deletes an existing virtual machine. + * + * @param virtualMachine The virtual machine to delete. + */ + void deleteVirtualMachine(VirtualMachineDto virtualMachine); + + /** + * Updates an existing virtual machine from the given virtual appliance. + * + * @param virtualMachine The new attributes for the virtual machine. + * @return The task reference or null if the operation completed synchronously. + */ + AcceptedRequestDto updateVirtualMachine(VirtualMachineWithNodeExtendedDto virtualMachine); + + /** + * Updates an existing virtual machine from the given virtual appliance. + * + * @param virtualMachine The new attributes for the virtual machine. + * @param options The update options. + * @return The task reference or null if the operation completed synchronously. + */ + AcceptedRequestDto updateVirtualMachine( + VirtualMachineWithNodeExtendedDto virtualMachine, VirtualMachineOptions options); + + /** + * Changes the state an existing virtual machine. + * + * @param virtualMachine The given virtual machine. + * @param state The new state. + * @return The task reference. + */ + AcceptedRequestDto changeVirtualMachineState(VirtualMachineDto virtualMachine, + VirtualMachineStateDto state); + + /** + * Get the state of the given virtual machine. + * + * @param virtualMachine The given virtual machine. + * @return The state of the given virtual machine. + */ + VirtualMachineStateDto getVirtualMachineState(VirtualMachineDto virtualMachine); + + /** + * Deploy a virtual machine with task options. + * + * @param virtualMachine The virtual machine to deploy. + * @param options extra deploy options. + * @return Response message to the deploy request. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto deployVirtualMachine(VirtualMachineDto virtualMachine, + VirtualMachineTaskDto options); + + /** + * Uneploy a virtual machine with task options. + * + * @param virtualMachine The virtual machine to undeploy. + * @param options extra deploy unoptions. + * @return Response message to the undeploy request. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto undeployVirtualMachine(VirtualMachineDto virtualMachine, + VirtualMachineTaskDto options); + + /** + * List all available network configurations for a virtual machine. + * + * @param virtualMachine The virtual machine. + * @return The list of network configurations. + */ + VMNetworkConfigurationsDto listNetworkConfigurations(VirtualMachineDto virtualMachine); + + /** + * Sets the gateway network to be used by this virtual machine. + * + * @param virtualMachine The virtual machine. + * @param network The gateway network to use. + */ + void setGatewayNetwork(final VirtualMachineDto virtualMachine, final VLANNetworkDto network); + + /** + * Reboot a virtual machine. + * + * @param virtualMachine The virtual machine to reboot. + * @return Response message to the reset request. + */ + AcceptedRequestDto rebootVirtualMachine(VirtualMachineDto virtualMachine); + + /******************* Virtual Machine Template ***********************/ + + /** + * Get the template of a virtual machine. + * + * @param virtualMachine The given virtual machine. + * @return The template of the given virtual machine. + */ + VirtualMachineTemplateDto getVirtualMachineTemplate(VirtualMachineDto virtualMachine); + + /** + * Get the volumes attached to the given virtual machine. + * + * @param virtualMachine The virtual machine. + * @return The volumes attached to the given virtual machine. + */ + VolumesManagementDto listAttachedVolumes(VirtualMachineDto virtualMachine); + + /** + * Detach all volumes from the given virtual machine. + *

+ * If the virtual machine is deployed, the operation will be executed asynchronously. + * + * @param virtualMachine The virtual machine. + * @return The task reference or null if the operation completed synchronously. + */ + AcceptedRequestDto detachAllVolumes(VirtualMachineDto virtualMachine); + + /** + * Replaces the current volumes attached to the virtual machine with the given ones. + *

+ * If the virtual machine is deployed, the operation will be executed asynchronously. + * + * @param virtualMachine The virtual machine. + * @param options virtual machine parameters + * @param volumes The new volumes for the virtual machine. + * @return The task reference or null if the operation completed synchronously. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto replaceVolumes(VirtualMachineDto virtualMachine, + VirtualMachineOptions options, VolumeManagementDto... volumes); + + /** + * List all hard disks attached to the given virtual machine. + * + * @param virtualMachine The virtual machine. + * @return The hard disks attached to the virtual machine. + */ + DisksManagementDto listAttachedHardDisks(VirtualMachineDto virtualMachine); + + /** + * Detach all hard disks from the given virtual machine. + *

+ * If the virtual machine is deployed, the operation will be executed asynchronously. + * + * @param virtualMachine The virtual machine. + * @return The task reference or null if the operation completed synchronously. + */ + AcceptedRequestDto detachAllHardDisks(VirtualMachineDto virtualMachine); + + /** + * Replaces the current hard disks attached to the virtual machine with the given ones. + *

+ * If the virtual machine is deployed, the operation will be executed asynchronously. + * + * @param virtualMachine The virtual machine. + * @param hardDisks The new hard disks for the virtual machine. + * @return The task reference or null if the operation completed synchronously. + */ + AcceptedRequestDto replaceHardDisks(VirtualMachineDto virtualMachine, + DiskManagementDto... hardDisks); + + /*********************** Hard disks ***********************/ + + /** + * List all hard disks in the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The hard disks in the virtual datacenter. + */ + DisksManagementDto listHardDisks(VirtualDatacenterDto virtualDatacenter); + + /** + * Get the hard disk with the given id in the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param diskId The id of the hard disk to get. + * @return The requested hard disk or null if it does not exist. + */ + DiskManagementDto getHardDisk(VirtualDatacenterDto virtualDatacenter, Integer diskId); + + /** + * Creates a new hard disk in the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter where the hard disk will be created. + * @param hardDisk The hard disk to create. + * @return The created hard disk. + */ + DiskManagementDto createHardDisk(VirtualDatacenterDto virtualDatacenter, + DiskManagementDto hardDisk); + + /** + * Deletes the given hard disk. + * + * @param hardDisk The hard disk to delete. + */ + void deleteHardDisk(DiskManagementDto hardDisk); + + /*********************** Volumes ***********************/ + + /** + * List all volumes in the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @return The volumes in the virtual datacenter. + */ + @EnterpriseEdition + VolumesManagementDto listVolumes(VirtualDatacenterDto virtualDatacenter); + + /** + * List all volumes in the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param options Optional parameters to filter the volume list. + * @return The volumes in the virtual datacenter. + */ + @EnterpriseEdition + VolumesManagementDto listVolumes(VirtualDatacenterDto virtualDatacenter, VolumeOptions options); + + /** + * Get a volume from the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter. + * @param volumeId The id of the volume to get. + * @return The volume or null if it does not exist. + */ + @EnterpriseEdition + VolumeManagementDto getVolume(VirtualDatacenterDto virtualDatacenter, Integer volumeId); + + /** + * Creates a volume in the given virtual datacenter. + * + * @param virtualDatacenter The virtual datacenter where the volume will be created. + * @param volume The volume to create. This volume dto must contain a link to the tier where the + * volume should be created. + * @return The created volume. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + VolumeManagementDto createVolume(VirtualDatacenterDto virtualDatacenter, + VolumeManagementDto volume); + + /** + * Modifies the given volume. + *

+ * If the virtual machine is deployed and the size of the volume is changed, then an + * asynchronous task will be generated to refresh the resources of the virtual machine in the + * hypervisor. + * + * @param volume The volume to modify. + * @return The task reference or null if no task was generated. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto updateVolume(VolumeManagementDto volume); + + /** + * Delete the given volume. + * + * @param volume The volume to delete. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void deleteVolume(VolumeManagementDto volume); + + /** + * Moves the given volume to a new virtual datacenter. + *

+ * The Abiquo API will return a 301 (Moved Permanently), so redirects must be enabled to make + * this method succeed. + * + * @param volume The volume to move. + * @param newVirtualDatacenter The destination virtual datacenter. + * @return The reference to the volume in the new virtual datacenter. + */ + @EnterpriseEdition + VolumeManagementDto moveVolume(VolumeManagementDto volume, + VirtualDatacenterDto newVirtualDatacenter); + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java new file mode 100644 index 0000000000..ce59a8b99c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/CloudAsyncApi.java @@ -0,0 +1,764 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.jclouds.abiquo.binders.AppendToPath; +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.binders.cloud.BindHardDiskRefsToPayload; +import org.jclouds.abiquo.binders.cloud.BindMoveVolumeToPath; +import org.jclouds.abiquo.binders.cloud.BindNetworkConfigurationRefToPayload; +import org.jclouds.abiquo.binders.cloud.BindNetworkRefToPayload; +import org.jclouds.abiquo.binders.cloud.BindVirtualDatacenterRefToPayload; +import org.jclouds.abiquo.binders.cloud.BindVolumeRefsToPayload; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.options.VirtualApplianceOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.functions.ReturnTaskReferenceOrNull; +import org.jclouds.abiquo.functions.cloud.ReturnMovedVolume; +import org.jclouds.abiquo.functions.enterprise.ParseEnterpriseId; +import org.jclouds.abiquo.functions.infrastructure.ParseDatacenterId; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceStateDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.cloud.VirtualMachineStateDto; +import com.abiquo.server.core.cloud.VirtualMachineTaskDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VMNetworkConfigurationDto; +import com.abiquo.server.core.infrastructure.network.VMNetworkConfigurationsDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; +import com.abiquo.server.core.infrastructure.storage.DisksManagementDto; +import com.abiquo.server.core.infrastructure.storage.MovedVolumeDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Cloud API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see CloudApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +@Path("/cloud") +public interface CloudAsyncApi +{ + /*********************** Virtual Datacenter ***********************/ + + /** + * @see CloudApi#listVirtualDatacenters(VirtualDatacenterOptions) + */ + @GET + @Path("/virtualdatacenters") + @Consumes(VirtualDatacentersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualDatacenters(VirtualDatacenterOptions options); + + /** + * @see CloudApi#getVirtualDatacenter(Integer) + */ + @GET + @Path("/virtualdatacenters/{virtualdatacenter}") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(VirtualDatacenterDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualDatacenter( + @PathParam("virtualdatacenter") Integer virtualDatacenterId); + + /** + * @see CloudApi#createVirtualDatacenter(VirtualDatacenterDto, Datacenter, Enterprise) + */ + @POST + @Path("/virtualdatacenters") + @Consumes(VirtualDatacenterDto.BASE_MEDIA_TYPE) + @Produces(VirtualDatacenterDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createVirtualDatacenter( + @BinderParam(BindToXMLPayload.class) final VirtualDatacenterDto virtualDatacenter, + @QueryParam("datacenter") @ParamParser(ParseDatacenterId.class) final DatacenterDto datacenter, + @QueryParam("enterprise") @ParamParser(ParseEnterpriseId.class) final EnterpriseDto enterprise); + + /** + * @see CloudApi#updateVirtualDatacenter(VirtualDatacenterDto) + */ + @PUT + @Consumes(VirtualDatacenterDto.BASE_MEDIA_TYPE) + @Produces(VirtualDatacenterDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateVirtualDatacenter( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#deleteVirtualDatacenter(VirtualDatacenterDto) + */ + @DELETE + ListenableFuture deleteVirtualDatacenter( + @EndpointLink("edit") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#listAvailableTemplates(VirtualDatacenterDto) + */ + @GET + @Consumes(VirtualMachineTemplatesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listAvailableTemplates( + @EndpointLink("templates") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#listAvailableTemplates(VirtualDatacenterDto, VirtualMachineTemplateOptions) + */ + @GET + @Consumes(VirtualMachineTemplatesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listAvailableTemplates( + @EndpointLink("templates") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + VirtualMachineTemplateOptions options); + + /** + * @see CloudApi#listStorageTiers(VirtualDatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(TiersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listStorageTiers( + @EndpointLink("tiers") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#getStorageTier(VirtualDatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(TierDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getStorageTier( + @EndpointLink("tiers") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(AppendToPath.class) Integer tierId); + + /*********************** Public IP ***********************/ + + /** + * @see CloudApi#listAvailablePublicIps(VirtualDatacenterDto, IpOptions) + */ + @GET + @Consumes(PublicIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listAvailablePublicIps( + @EndpointLink("topurchase") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + IpOptions options); + + /** + * @see CloudApi#listPurchasedPublicIps(VirtualDatacenterDto, IpOptions) + */ + @GET + @Consumes(PublicIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPurchasedPublicIps( + @EndpointLink("purchased") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + IpOptions options); + + /** + * @see CloudApi#purchasePublicIp(PublicIpDto) + */ + @PUT + @Consumes(PublicIpDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture purchasePublicIp( + @EndpointLink("purchase") @BinderParam(BindToPath.class) PublicIpDto publicIp); + + /** + * @see CloudApi#releasePublicIp(PublicIpDto) + */ + @PUT + @Consumes(PublicIpDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture releasePublicIp( + @EndpointLink("release") @BinderParam(BindToPath.class) PublicIpDto publicIp); + + /*********************** Private Network ***********************/ + + /** + * @see CloudApi#listPrivateNetworks(VirtualDatacenter) + */ + @GET + @Consumes(VLANNetworksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPrivateNetworks( + @EndpointLink("privatenetworks") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#getPrivateNetwork(VirtualDatacenterDto, Integer) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getPrivateNetwork( + @EndpointLink("privatenetworks") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(AppendToPath.class) Integer privateNetworkId); + + /** + * @see CloudApi#createPrivateNetwork(VirtualDatacenterDto, VLANNetworkDto) + */ + @POST + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @Produces(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createPrivateNetwork( + @EndpointLink("privatenetworks") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(BindToXMLPayload.class) VLANNetworkDto privateNetwork); + + /** + * @see CloudApi#updatePrivateNetwork(VLANNetworkDto) + */ + @PUT + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @Produces(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updatePrivateNetwork( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VLANNetworkDto privateNetwork); + + /** + * @see CloudApi#deletePrivateNetwork(VLANNetworkDto) + */ + @DELETE + ListenableFuture deletePrivateNetwork( + @EndpointLink("edit") @BinderParam(BindToPath.class) VLANNetworkDto privateNetwork); + + /** + * @see CloudApi#getDefaultNetwork(VirtualDatacenterDto) + */ + @GET + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getDefaultNetwork( + @EndpointLink("defaultnetwork") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#setDefaultNetwork(VirtualDatacenterDto, VLANNetworkDto) + */ + @PUT + @Produces(LinksDto.BASE_MEDIA_TYPE) + ListenableFuture setDefaultNetwork( + @EndpointLink("defaultvlan") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(BindNetworkRefToPayload.class) VLANNetworkDto network); + + /*********************** Private Network IPs ***********************/ + + /** + * @see CloudApi#listPrivateNetworkIps(VLANNetworkDto) + */ + @GET + @Consumes(PrivateIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPrivateNetworkIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network); + + /** + * @see CloudApi#listPrivateNetworkIps(VLANNetworkDto, IpOptions) + */ + @GET + @Consumes(PrivateIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPrivateNetworkIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + IpOptions options); + + /** + * @see CloudApi#getPrivateNetworkIp(VLANNetworkDto, Integer) + */ + @GET + @Consumes(PrivateIpDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getPrivateNetworkIp( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + @BinderParam(AppendToPath.class) Integer ipId); + + /*********************** Virtual Appliance ***********************/ + + /** + * @see CloudApi#listVirtualAppliances(VirtualDatacenterDto) + */ + @GET + @Consumes(VirtualAppliancesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualAppliances( + @EndpointLink("virtualappliances") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#getVirtualAppliance(VirtualDatacenterDto, Integer) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(VirtualApplianceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualAppliance( + @EndpointLink("virtualappliances") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(AppendToPath.class) Integer virtualApplianceId); + + /** + * @see CloudApi#getVirtualApplianceState(VirtualApplianceDto) + */ + @GET + @Consumes(VirtualApplianceStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualApplianceState( + @EndpointLink("state") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance); + + /** + * @see CloudApi#createVirtualAppliance(VirtualDatacenterDto, VirtualApplianceDto) + */ + @POST + @Consumes(VirtualApplianceDto.BASE_MEDIA_TYPE) + @Produces(VirtualApplianceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createVirtualAppliance( + @EndpointLink("virtualappliances") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(BindToXMLPayload.class) VirtualApplianceDto virtualAppliance); + + /** + * @see CloudApi#updateVirtualAppliance(VirtualApplianceDto) + */ + @PUT + @Consumes(VirtualApplianceDto.BASE_MEDIA_TYPE) + @Produces(VirtualApplianceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateVirtualAppliance( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VirtualApplianceDto virtualAppliance); + + /** + * @see CloudApi#deleteVirtualAppliance(VirtualApplianceDto) + */ + @DELETE + ListenableFuture deleteVirtualAppliance( + @EndpointLink("edit") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance); + + /** + * @see CloudApi#deleteVirtualAppliance(VirtualApplianceDto, VirtualApplianceOptions) + */ + @DELETE + ListenableFuture deleteVirtualAppliance( + @EndpointLink("edit") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, + VirtualApplianceOptions options); + + /** + * @see CloudApi#deployVirtualAppliance(VirtualApplianceDto, VirtualMachineTaskDto) + */ + @POST + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineTaskDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture> deployVirtualAppliance( + @EndpointLink("deploy") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, + @BinderParam(BindToXMLPayload.class) VirtualMachineTaskDto task); + + /** + * @see CloudApi#undeployVirtualAppliance(VirtualApplianceDto, VirtualMachineTaskDto) + */ + @POST + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineTaskDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture> undeployVirtualAppliance( + @EndpointLink("undeploy") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, + @BinderParam(BindToXMLPayload.class) VirtualMachineTaskDto task); + + /*********************** Virtual Machine ***********************/ + + /** + * @see CloudApi#listVirtualMachines(VirtualApplianceDto) + */ + @GET + @Consumes(VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachines( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance); + + /** + * @see CloudApi#listVirtualMachines(VirtualApplianceDto, VirtualMachineOptions) + */ + @GET + @Consumes(VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachines( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, + VirtualMachineOptions options); + + /** + * @see CloudApi#getVirtualMachine(VirtualApplianceDto, Integer) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualMachine( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, + @BinderParam(AppendToPath.class) Integer virtualMachineId); + + /** + * @see CloudApi#createVirtualMachine(VirtualApplianceDto, VirtualMachineWithNodeExtendedDto) + */ + @POST + @Consumes(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createVirtualMachine( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) VirtualApplianceDto virtualAppliance, + @BinderParam(BindToXMLPayload.class) VirtualMachineWithNodeExtendedDto virtualMachine); + + /** + * @see CloudApi#deleteVirtualMachine(VirtualMachineDto) + */ + @DELETE + ListenableFuture deleteVirtualMachine( + @EndpointLink("edit") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#updateVirtualMachine(VirtualMachineWithNodeExtendedDto) + */ + @PUT + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE) + ListenableFuture> updateVirtualMachine( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VirtualMachineWithNodeExtendedDto virtualMachine); + + /** + * @see CloudApi#updateVirtualMachine(VirtualMachineDto, VirtualMachineOptions) + */ + @PUT + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE) + ListenableFuture> updateVirtualMachine( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VirtualMachineWithNodeExtendedDto virtualMachine, + VirtualMachineOptions options); + + /** + * @see CloudApi#changeVirtualMachineState(VirtualMachineDto, VirtualMachineStateDto) + */ + @PUT + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture> changeVirtualMachineState( + @EndpointLink("state") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine, + @BinderParam(BindToXMLPayload.class) VirtualMachineStateDto state); + + /** + * @see CloudApi#getVirtualMachineState(VirtualMachineDto) + */ + @GET + @Consumes(VirtualMachineStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualMachineState( + @EndpointLink("state") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#listNetworkConfigurations(VirtualMachineDto) + */ + @GET + @Consumes(VMNetworkConfigurationsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listNetworkConfigurations( + @EndpointLink("configurations") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#setGatewayNetwork(VirtualMachineDto, VMNetworkConfigurationDto) + */ + @PUT + @Produces(LinksDto.BASE_MEDIA_TYPE) + ListenableFuture setGatewayNetwork( + @EndpointLink("configurations") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine, + @BinderParam(BindNetworkConfigurationRefToPayload.class) VLANNetworkDto network); + + /** + * @see CloudApi#rebootVirtualMachine(VirtualMachineDto) + */ + @POST + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture> rebootVirtualMachine( + @EndpointLink("reset") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /*********************** Virtual Machine Template ***********************/ + + /** + * @see CloudApi#getVirtualMachineTemplate(VirtualMachineTemplateDto) + */ + @GET + @Consumes(VirtualMachineTemplateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualMachineTemplate( + @EndpointLink("virtualmachinetemplate") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#listAttachedVolumes(VirtualMachineDto) + */ + @GET + @Consumes(VolumesManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listAttachedVolumes( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#detachAllVolumes(VirtualMachineDto) + */ + @DELETE + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + ListenableFuture> detachAllVolumes( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#replaceVolumes(VirtualMachineDto, VirtualMachineOptions, + * VolumeManagementDto...) + */ + @PUT + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(LinksDto.BASE_MEDIA_TYPE) + ListenableFuture> replaceVolumes( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine, + VirtualMachineOptions options, + @BinderParam(BindVolumeRefsToPayload.class) VolumeManagementDto... volumes); + + /** + * @see CloudApi#listAttachedHardDisks(VirtualMachineDto) + */ + @GET + @Consumes(DisksManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listAttachedHardDisks( + @EndpointLink("disks") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#detachAllHardDisks(VirtualMachineDto) + */ + @DELETE + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + ListenableFuture> detachAllHardDisks( + @EndpointLink("disks") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine); + + /** + * @see CloudApi#replaceHardDisks(VirtualMachineDto, DiskManagementDto...) + */ + @PUT + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(LinksDto.BASE_MEDIA_TYPE) + ListenableFuture> replaceHardDisks( + @EndpointLink("disks") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine, + @BinderParam(BindHardDiskRefsToPayload.class) DiskManagementDto... hardDisks); + + /** + * @see CloudApi#deployVirtualMachine(VirtualMachineDto, VirtualMachineTaskDto) + */ + @POST + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineTaskDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture> deployVirtualMachine( + @EndpointLink("deploy") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine, + @BinderParam(BindToXMLPayload.class) VirtualMachineTaskDto task); + + /** + * @see CloudApi#undeployVirtualMachine(VirtualMachineDto, VirtualMachineTaskDto) + */ + @POST + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineTaskDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture> undeployVirtualMachine( + @EndpointLink("undeploy") @BinderParam(BindToPath.class) VirtualMachineDto virtualMachine, + @BinderParam(BindToXMLPayload.class) VirtualMachineTaskDto task); + + /*********************** Hard disks ***********************/ + + /** + * @see CloudApi#listHardDisks(VirtualDatacenterDto) + */ + @GET + @Consumes(DisksManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listHardDisks( + @EndpointLink("disks") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#getHardDisk(VirtualDatacenterDto, Integer) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(DiskManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getHardDisk( + @EndpointLink("disks") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(AppendToPath.class) Integer diskId); + + /** + * @see CloudApi#createHardDisk(VirtualDatacenterDto, DiskManagementDto) + */ + @POST + @Consumes(DiskManagementDto.BASE_MEDIA_TYPE) + @Produces(DiskManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createHardDisk( + @EndpointLink("disks") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(BindToXMLPayload.class) DiskManagementDto hardDisk); + + /** + * @see CloudApi#deleteHardDisk(DiskManagementDto) + */ + @DELETE + ListenableFuture deleteHardDisk( + @EndpointLink("edit") @BinderParam(BindToPath.class) DiskManagementDto hardDisk); + + /*********************** Volumes ***********************/ + + /** + * @see CloudApi#listVolumes(VirtualDatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(VolumesManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVolumes( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter); + + /** + * @see CloudApi#listVolumes(VirtualDatacenterDto, VolumeOptions) + */ + @EnterpriseEdition + @GET + @Consumes(VolumesManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVolumes( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + VolumeOptions options); + + /** + * @see CloudApi#getVolume(VirtualDatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(VolumeManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVolume( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(AppendToPath.class) Integer volumeId); + + /** + * @see CloudApi#createVolume(VirtualDatacenterDto, VolumeManagementDto) + */ + @EnterpriseEdition + @POST + @Consumes(VolumeManagementDto.BASE_MEDIA_TYPE) + @Produces(VolumeManagementDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createVolume( + @EndpointLink("volumes") @BinderParam(BindToPath.class) VirtualDatacenterDto virtualDatacenter, + @BinderParam(BindToXMLPayload.class) VolumeManagementDto volume); + + /** + * @see CloudApi#updateVolume(VolumeManagementDto) + */ + @EnterpriseEdition + @PUT + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VolumeManagementDto.BASE_MEDIA_TYPE) + ListenableFuture> updateVolume( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VolumeManagementDto volume); + + /** + * @see CloudApi#updateVolume(VolumeManagementDto) + */ + @EnterpriseEdition + @DELETE + ListenableFuture deleteVolume( + @EndpointLink("edit") @BinderParam(BindToPath.class) VolumeManagementDto volume); + + /** + * @see CloudApi#moveVolume(VolumeManagementDto, VirtualDatacenterDto) + */ + @EnterpriseEdition + @POST + @ExceptionParser(ReturnMovedVolume.class) + @Consumes(MovedVolumeDto.BASE_MEDIA_TYPE) + @Produces(LinksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture moveVolume( + @BinderParam(BindMoveVolumeToPath.class) VolumeManagementDto volume, + @BinderParam(BindVirtualDatacenterRefToPayload.class) VirtualDatacenterDto newVirtualDatacenter); + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigApi.java new file mode 100644 index 0000000000..3e819ae42a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigApi.java @@ -0,0 +1,167 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.concurrent.Timeout; + +import com.abiquo.server.core.appslibrary.CategoriesDto; +import com.abiquo.server.core.appslibrary.CategoryDto; +import com.abiquo.server.core.config.LicenseDto; +import com.abiquo.server.core.config.LicensesDto; +import com.abiquo.server.core.config.SystemPropertiesDto; +import com.abiquo.server.core.config.SystemPropertyDto; +import com.abiquo.server.core.enterprise.PrivilegeDto; +import com.abiquo.server.core.enterprise.PrivilegesDto; + +/** + * Provides synchronous access to Abiquo Admin API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see ConfigAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface ConfigApi +{ + /*********************** License ***********************/ + + /** + * List all licenses. + * + * @return The list of licenses. + */ + @EnterpriseEdition + LicensesDto listLicenses(); + + /** + * List all active/inactive licenses. + * + * @param options Optional query params. + * @return The list of licenses. + */ + @EnterpriseEdition + LicensesDto listLicenses(LicenseOptions options); + + /** + * Add a new license. + * + * @param license The license to add. + * @return The added license. + */ + @EnterpriseEdition + LicenseDto addLicense(LicenseDto license); + + /** + * Removes an existing license. + * + * @param license The license to delete. + */ + @EnterpriseEdition + void removeLicense(LicenseDto license); + + /*********************** Privilege ***********************/ + + /** + * List all privileges in the system. + * + * @return The list of privileges. + */ + PrivilegesDto listPrivileges(); + + /** + * Get the given privilege. + * + * @param privilegeId The id of the privilege. + * @return The privilege or null if it does not exist. + */ + PrivilegeDto getPrivilege(Integer privilegeId); + + /*********************** System Properties ***********************/ + + /** + * List all system properties. + * + * @return The list of properties. + */ + SystemPropertiesDto listSystemProperties(); + + /** + * List properties with options. + * + * @param options Optional query params. + * @return The list of system properties. + */ + SystemPropertiesDto listSystemProperties(PropertyOptions options); + + /** + * Updates a system property. + * + * @param property The new attributes for the system property. + * @return The updated system property. + */ + SystemPropertyDto updateSystemProperty(SystemPropertyDto property); + + /*********************** Category ***********************/ + + /** + * List all categories. + * + * @return The list of categories. + */ + CategoriesDto listCategories(); + + /** + * Get the given category. + * + * @param categoryId The id of the category. + * @return The category or null if it does not exist. + */ + CategoryDto getCategory(Integer categoryId); + + /** + * Create a new category. + * + * @param icon The category to be created. + * @return The created category. + */ + CategoryDto createCategory(CategoryDto category); + + /** + * Updates an existing category. + * + * @param category The new attributes for the category. + * @return The updated category. + */ + CategoryDto updateCategory(CategoryDto category); + + /** + * Deletes an existing category. + * + * @param icon The category to delete. + */ + void deleteCategory(CategoryDto category); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigAsyncApi.java new file mode 100644 index 0000000000..d84ad5de9f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/ConfigAsyncApi.java @@ -0,0 +1,211 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.server.core.appslibrary.CategoriesDto; +import com.abiquo.server.core.appslibrary.CategoryDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.config.LicenseDto; +import com.abiquo.server.core.config.LicensesDto; +import com.abiquo.server.core.config.SystemPropertiesDto; +import com.abiquo.server.core.config.SystemPropertyDto; +import com.abiquo.server.core.enterprise.PrivilegeDto; +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Config API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see AdminApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +@Path("/config") +public interface ConfigAsyncApi +{ + /*********************** License ***********************/ + + /** + * @see ConfigApi#listLicenses() + */ + + @EnterpriseEdition + @GET + @Path("/licenses") + @Consumes(LicensesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listLicenses(); + + /** + * @see ConfigApi#listLicenses(LicenseOptions) + */ + @EnterpriseEdition + @GET + @Path("/licenses") + @Consumes(LicensesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listLicenses(LicenseOptions options); + + /** + * @see ConfigApi#addLicense(LicenseDto) + */ + @EnterpriseEdition + @POST + @Produces(LicenseDto.BASE_MEDIA_TYPE) + @Consumes(LicenseDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @Path("/licenses") + ListenableFuture addLicense(@BinderParam(BindToXMLPayload.class) LicenseDto license); + + /** + * @see ConfigApi#removeLicense(LicenseDto) + */ + @DELETE + @EnterpriseEdition + ListenableFuture removeLicense( + @EndpointLink("edit") @BinderParam(BindToPath.class) LicenseDto license); + + /*********************** Privilege ***********************/ + + /** + * @see ConfigApi#listPrivileges() + */ + @GET + @Path("/privileges") + @Consumes(PrivilegesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPrivileges(); + + /** + * @see ConfigApi#getPrivilege(Integer) + */ + @GET + @Path("/privileges/{privilege}") + @Consumes(PrivilegeDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPrivilege(@PathParam("privilege") Integer privilegeId); + + /*********************** System Properties ***********************/ + + /** + * @see ConfigApi#listSystemProperties() + */ + @GET + @Path("/properties") + @Consumes(SystemPropertiesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listSystemProperties(); + + /** + * @see ConfigApi#listSystemProperties(PropertyOptions) + */ + @GET + @Path("/properties") + @Consumes(SystemPropertiesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listSystemProperties(PropertyOptions options); + + /** + * @see ConfigApi#updateSystemProperty(VirtualDatacenterDto) + */ + @PUT + @Produces(SystemPropertyDto.BASE_MEDIA_TYPE) + @Consumes(SystemPropertyDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateSystemProperty( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) SystemPropertyDto property); + + /*********************** Category ***********************/ + + /** + * @see ConfigApi#listCategories() + */ + @GET + @Path("/categories") + @Consumes(CategoriesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listCategories(); + + /** + * @see ConfigApi#getCategory(Integer) + */ + @GET + @Path("/categories/{category}") + @Consumes(CategoryDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCategory(@PathParam("category") Integer categoryId); + + /** + * @see ConfigApi#createCategory(CategoryDto) + */ + @POST + @Path("/categories") + @Produces(CategoryDto.BASE_MEDIA_TYPE) + @Consumes(CategoryDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createCategory( + @BinderParam(BindToXMLPayload.class) CategoryDto category); + + /** + * @see ConfigApi#updateCategory(CategoryDto) + */ + @PUT + @Produces(CategoryDto.BASE_MEDIA_TYPE) + @Consumes(CategoryDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateCategory( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) CategoryDto category); + + /** + * @see ConfigApi#deleteCategory(CategoryDto) + */ + @DELETE + ListenableFuture deleteCategory( + @EndpointLink("edit") @BinderParam(BindToPath.class) CategoryDto category); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseApi.java new file mode 100644 index 0000000000..db01154f48 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseApi.java @@ -0,0 +1,359 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.enterprise.options.EnterpriseOptions; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.concurrent.Timeout; + +import com.abiquo.am.model.TemplatesStateDto; +import com.abiquo.server.core.appslibrary.DatacenterRepositoryDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListsDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; +import com.abiquo.server.core.enterprise.EnterprisesDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.abiquo.server.core.enterprise.UsersDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; + +/** + * Provides synchronous access to Abiquo Enterprise API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see EnterpriseAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface EnterpriseApi +{ + + /*********************** Enterprise ********************** */ + + /** + * List all enterprises. + * + * @return The list of Enterprises. + */ + EnterprisesDto listEnterprises(); + + /** + * List enterprises with options. + * + * @param options Filtering options. + * @return The list of Enterprises. + */ + EnterprisesDto listEnterprises(EnterpriseOptions options); + + /** + * List filtered enterprises by datacenter. + * + * @param datacenter The given datacenter. + * @param options Filtering options. + * @return The list of Enterprises. + */ + EnterprisesDto listEnterprises(DatacenterDto datacenter, EnterpriseOptions options); + + /** + * Create a new enterprise. + * + * @param enterprise The enterprise to be created. + * @return The created enterprise. + */ + EnterpriseDto createEnterprise(EnterpriseDto enterprise); + + /** + * Get the given enterprise. + * + * @param enterpriseId The id of the enterprise. + * @return The enterprise or null if it does not exist. + */ + EnterpriseDto getEnterprise(Integer enterpriseId); + + /** + * Updates an existing enterprise. + * + * @param enterprise The new attributes for the enterprise. + * @return The updated enterprise. + */ + EnterpriseDto updateEnterprise(EnterpriseDto enterprise); + + /** + * Deletes an existing enterprise. + * + * @param enterprise The enterprise to delete. + */ + void deleteEnterprise(EnterpriseDto enterprise); + + /** + * List the allowed datacenters to the given enterprise. + * + * @param enterpriseId The id of the enterprise. + * @return The allowed datacenters to the given enterprise. + */ + DatacentersDto listAllowedDatacenters(Integer enterpriseId); + + /** + * List all virtual datacenters of an enterprise. + * + * @param enterprise The given enterprise. + * @return The list of Datacenters. + */ + VirtualDatacentersDto listVirtualDatacenters(EnterpriseDto enterprise); + + /*********************** Enterprise Properties ***********************/ + + /** + * Get defined properties of the given enterprise. + * + * @param enterpriseId The enterprise id. + * @return Set of enterprise properties. + */ + @EnterpriseEdition + EnterprisePropertiesDto getEnterpriseProperties(EnterpriseDto enterprise); + + /** + * Updates the given enterprise properties set. + * + * @param properties The properties set. + * @return The updated properties. + */ + @EnterpriseEdition + EnterprisePropertiesDto updateEnterpriseProperties(EnterprisePropertiesDto properties); + + /*********************** Enterprise Limits ***********************/ + + /** + * Allows the given enterprise to use the given datacenter with the given limits. + * + * @param enterprise The enterprise. + * @param datacenter The datacenter to allow to the given enterprise. + * @param limits The usage limits for the enterprise in the given datacenter. + * @return The usage limits for the enterprise in the given datacenter. + */ + DatacenterLimitsDto createLimits(final EnterpriseDto enterprise, + final DatacenterDto datacenter, final DatacenterLimitsDto limits); + + /** + * Retreives the limits for the given enterprise and datacenter. + * + * @param enterprise The enterprise. + * @param datacenter The datacenter. + * @return The usage limits for the enterprise in the given datacenter. + */ + DatacentersLimitsDto getLimits(EnterpriseDto enterprise, DatacenterDto datacenter); + + /** + * Retreives limits for the given enterprise and any datacenter. + * + * @param enterprise The enterprise. + * @return The usage limits for the enterprise on any datacenter. + */ + DatacentersLimitsDto listLimits(EnterpriseDto enterprise); + + /** + * Updates an existing enterprise-datacenter limits. + * + * @param limits The new set of limits. + * @return The updated limits. + */ + DatacenterLimitsDto updateLimits(DatacenterLimitsDto limits); + + /** + * Deletes existing limits for a pair enterprise-datacenter. + * + * @param limits The limits to delete. + */ + void deleteLimits(DatacenterLimitsDto limits); + + /*********************** User ********************** */ + + /** + * Retreives users of the given enterprise. + * + * @param enterprise The enterprise. + * @return The users of the enterprise. + */ + UsersDto listUsers(final EnterpriseDto enterprise); + + /** + * Create a new user in the given enterprise. + * + * @param enterprise The enterprise. + * @param user The user to be created. + * @return The created user. + */ + UserDto createUser(EnterpriseDto enterprise, UserDto user); + + /** + * Get the given user from the given enterprise. + * + * @param enterprise The enterprise. + * @param userId The id of the user. + * @return The user or null if it does not exist. + */ + UserDto getUser(final EnterpriseDto enterprise, final Integer idUser); + + /** + * Updates an existing user. + * + * @param enterprise The new attributes for the user. + * @return The updated user. + */ + UserDto updateUser(UserDto user); + + /** + * Deletes existing user. + * + * @param user The user to delete. + */ + void deleteUser(UserDto user); + + /** + * Retrieves list of virtual machines by user. + * + * @param user The user. + * @return The list of virtual machines of the user. + */ + VirtualMachinesWithNodeExtendedDto listVirtualMachines(final UserDto user); + + /*********************** Datacenter Repository ***********************/ + + /** + * Get the given datacenter repository from the given enterprise. + * + * @param enterprise The enterprise. + * @param datacenterRepositoryId The id of the datacenter repository. + * @return The datacenter repository or null if it does not exist. + */ + DatacenterRepositoryDto getDatacenterRepository(final EnterpriseDto enterprise, + final Integer datacenterRepositoryId); + + /** + * Refreshes database with virtual machine templates existing in the repository filesystem. + * + * @param enterpriseId Id of the enterprise which information will be refreshed. + * @param datacenterRepositoryId Id of the datacenter repository contaning the templates. + */ + @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) + void refreshTemplateRepository(Integer enterpriseId, Integer datacenterRepositoryId); + + /*********************** Network ***********************/ + + /** + * List external networks of the enterprise + * + * @param enterprise The enterprise. + * @return The list of external networks created and assigned. + */ + @EnterpriseEdition + VLANNetworksDto listExternalNetworks(EnterpriseDto enterprise); + + /*********************** Cloud ***********************/ + + /** + * Retrieves list of virtual appliances by the given enterprise. + * + * @param enterprise The enterprise. + * @return The list of virtual appliances of the enterprise. + */ + VirtualAppliancesDto listVirtualAppliances(EnterpriseDto enterprise); + + /** + * List virtual machines for the enterprise + * + * @param enterprise The enterprise. + * @return The list of virtual machines by the enterprise. + */ + VirtualMachinesWithNodeExtendedDto listVirtualMachines(EnterpriseDto enterprise); + + /** + * List reserved machines for the enterprise + * + * @param enterprise The enterprise. + * @return The list of reserverd machines by the enterprise. + */ + MachinesDto listReservedMachines(EnterpriseDto enterprise); + + /** + * List all template definitions in apps library. + * + * @param enterprise The enterprise. + * @return The list of template definitions by the enterprise. + */ + TemplateDefinitionListsDto listTemplateDefinitionLists(EnterpriseDto enterprise); + + /** + * Create a new template definition list in apps library in the given enterprise. + * + * @param enterprise The enterprise. + * @param template The template to be created. + * @return The created template. + */ + TemplateDefinitionListDto createTemplateDefinitionList(EnterpriseDto enterprise, + TemplateDefinitionListDto templateList); + + /** + * Update an existing template definition list in apps library. + * + * @param template The template to be update. + * @return The updated template. + */ + TemplateDefinitionListDto updateTemplateDefinitionList(TemplateDefinitionListDto templateList); + + /** + * Deletes existing user. + * + * @param user The user to delete. + */ + void deleteTemplateDefinitionList(TemplateDefinitionListDto templateList); + + /** + * Get the given template definition list from the given enterprise. + * + * @param enterprise The enterprise. + * @param templateListId The id of the template definition list. + * @return The list or null if it does not exist. + */ + TemplateDefinitionListDto getTemplateDefinitionList(final EnterpriseDto enterprise, + final Integer templateListId); + + /** + * Get the list of status of a template definition list in a datacenter. + * + * @param templateList The template definition list. + * @param datacenter The given datacenter. + * @return The list of states. + */ + TemplatesStateDto listTemplateListStatus(TemplateDefinitionListDto templateList, + DatacenterDto datacenter); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseAsyncApi.java new file mode 100644 index 0000000000..3838fbc9af --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EnterpriseAsyncApi.java @@ -0,0 +1,425 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.jclouds.abiquo.binders.AppendToPath; +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.domain.enterprise.options.EnterpriseOptions; +import org.jclouds.abiquo.functions.infrastructure.ParseDatacenterId; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.am.model.TemplatesStateDto; +import com.abiquo.server.core.appslibrary.DatacenterRepositoryDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListsDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; +import com.abiquo.server.core.enterprise.EnterprisesDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.abiquo.server.core.enterprise.UsersDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Enterprise API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see EnterpriseApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +@Path("/admin") +public interface EnterpriseAsyncApi +{ + /*********************** Enterprise ***********************/ + + /** + * @see EnterpriseApi#listEnterprises() + */ + @GET + @Path("/enterprises") + @Consumes(EnterprisesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listEnterprises(); + + /** + * @see EnterpriseApi#listEnterprises(EnterpriseOptions) + */ + @GET + @Path("/enterprises") + @Consumes(EnterprisesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listEnterprises(EnterpriseOptions options); + + /** + * @see EnterpriseApi#listEnterprises(DatacenterDto, EnterpriseOptions) + */ + @GET + @Consumes(EnterprisesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listEnterprises( + @EndpointLink("enterprises") @BinderParam(BindToPath.class) DatacenterDto datacenter, + EnterpriseOptions options); + + /** + * @see EnterpriseApi#createEnterprise(EnterpriseDto) + */ + @POST + @Path("/enterprises") + @Produces(EnterpriseDto.BASE_MEDIA_TYPE) + @Consumes(EnterpriseDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createEnterprise( + @BinderParam(BindToXMLPayload.class) EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#getEnterprise(Integer) + */ + @GET + @Path("/enterprises/{enterprise}") + @Consumes(EnterpriseDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getEnterprise(@PathParam("enterprise") Integer enterpriseId); + + /** + * @see EnterpriseApi#updateEnterprise(EnterpriseDto) + */ + @PUT + @Produces(EnterpriseDto.BASE_MEDIA_TYPE) + @Consumes(EnterpriseDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateEnterprise( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#deleteEnterprise(EnterpriseDto) + */ + @DELETE + ListenableFuture deleteEnterprise( + @EndpointLink("edit") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#listAllowedDatacenters(Integer) + */ + @GET + @Path("/datacenters") + @Consumes(DatacentersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listAllowedDatacenters( + @QueryParam("idEnterprise") Integer enterpriseId); + + /** + * @see EnterpriseApi#listVirtualDatacenters(EnterpriseDto) + */ + @GET + @Consumes(VirtualDatacentersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualDatacenters( + @EndpointLink("cloud/virtualdatacenters") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /*********************** Enterprise Properties ***********************/ + + /** + * @see EnterpriseApi#getEnterpriseProperties(EnterpriseDto) + */ + @EnterpriseEdition + @GET + @Consumes(EnterprisePropertiesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getEnterpriseProperties( + @EndpointLink("properties") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#updateEnterpriseProperties(EnterprisePropertiesDto) + */ + @EnterpriseEdition + @PUT + @Produces(EnterprisePropertiesDto.BASE_MEDIA_TYPE) + @Consumes(EnterprisePropertiesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateEnterpriseProperties( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) EnterprisePropertiesDto properties); + + /*********************** Enterprise Limits ***********************/ + + /** + * @see EnterpriseApi#createLimits(EnterpriseDto, DatacenterDto, DatacenterLimitsDto) + */ + @POST + @Produces(DatacenterLimitsDto.BASE_MEDIA_TYPE) + @Consumes(DatacenterLimitsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createLimits( + @EndpointLink("limits") @BinderParam(BindToPath.class) final EnterpriseDto enterprise, + @QueryParam("datacenter") @ParamParser(ParseDatacenterId.class) final DatacenterDto datacenter, + @BinderParam(BindToXMLPayload.class) DatacenterLimitsDto limits); + + /** + * @see EnterpriseApi#getLimits(EnterpriseDto, DatacenterDto) + */ + @GET + @Consumes(DatacentersLimitsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getLimits( + @EndpointLink("limits") @BinderParam(BindToPath.class) final EnterpriseDto enterprise, + @QueryParam("datacenter") @ParamParser(ParseDatacenterId.class) final DatacenterDto datacenter); + + /** + * @see EnterpriseApi#updateLimits(DatacenterLimitsDto) + */ + @PUT + @Produces(DatacenterLimitsDto.BASE_MEDIA_TYPE) + @Consumes(DatacenterLimitsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateLimits( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) DatacenterLimitsDto limits); + + /** + * @see EnterpriseApi#deleteLimits(DatacenterLimitsDto) + */ + @DELETE + ListenableFuture deleteLimits( + @EndpointLink("edit") @BinderParam(BindToPath.class) DatacenterLimitsDto limits); + + /** + * @see EnterpriseApi#listLimits(EnterpriseDto) + */ + @GET + @Consumes(DatacentersLimitsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listLimits( + @EndpointLink("limits") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /*********************** User ***********************/ + + /** + * @see EnterpriseApi#listUsers(EnterpriseDto) + */ + @GET + @Consumes(UsersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listUsers( + @EndpointLink("users") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#getUser(EnterpriseDto, Integer) + */ + @GET + @Consumes(UserDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getUser( + @EndpointLink("users") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(AppendToPath.class) Integer userId); + + /** + * @see EnterpriseApi#createUser(EnterpriseDto) + */ + @POST + @Produces(UserDto.BASE_MEDIA_TYPE) + @Consumes(UserDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createUser( + @EndpointLink("users") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(BindToXMLPayload.class) UserDto user); + + /** + * @see EnterpriseApi#updateUser(UserDto) + */ + @PUT + @Produces(UserDto.BASE_MEDIA_TYPE) + @Consumes(UserDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateUser( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) UserDto user); + + /** + * @see EnterpriseApi#deleteUser(UserDto) + */ + @DELETE + ListenableFuture deleteUser( + @EndpointLink("edit") @BinderParam(BindToPath.class) UserDto user); + + /** + * @see EnterpriseApi#listVirtualMachines(UserDto) + */ + @GET + @Consumes(VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachines( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) final UserDto user); + + /*********************** Datacenter Repository ***********************/ + + /** + * @see EnterpriseApi#getDatacenterRepository(EnterpriseDto, Integer) + */ + @GET + @Consumes(DatacenterRepositoryDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getDatacenterRepository( + @EndpointLink("datacenterrepositories") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(AppendToPath.class) Integer datacenterRepositoryId); + + /** + * @see EnterpriseApi#refreshTemplateRepository(Integer, Integer) + */ + @PUT + @Path("/enterprises/{enterprise}/datacenterrepositories/{datacenterrepository}/actions/refresh") + ListenableFuture refreshTemplateRepository(@PathParam("enterprise") Integer enterpriseId, + @PathParam("datacenterrepository") Integer datacenterRepositoryId); + + /*********************** External Network ***********************/ + + /** + * @see EnterpriseApi#listExternalNetworks(EnterpriseDto) + */ + @EnterpriseEdition + @GET + @Consumes(VLANNetworksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listExternalNetworks( + @EndpointLink("externalnetworks") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /*********************** Cloud ***********************/ + + /** + * @see EnterpriseApi#listVirtualAppliances(EnterpriseDto) + */ + @GET + @Consumes(VirtualAppliancesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualAppliances( + @EndpointLink("virtualappliances") @BinderParam(BindToPath.class) final EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#listVirtualMachines(EnterpriseDto) + */ + @GET + @Consumes(VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachines( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /*********************** Machine ***********************/ + + /** + * @see EnterpriseApi#listVirtualMachines(EnterpriseDto) + */ + @GET + @Consumes(MachinesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listReservedMachines( + @EndpointLink("reservedmachines") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /*********************** Template definition list ***********************/ + + /** + * @see EnterpriseApi#listTemplateDefinitionLists(EnterpriseDto) + */ + @GET + @Consumes(TemplateDefinitionListsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listTemplateDefinitionLists( + @EndpointLink("appslib/templateDefinitionLists") @BinderParam(BindToPath.class) EnterpriseDto enterprise); + + /** + * @see EnterpriseApi#createTemplateDefinitionList(EnterpriseDto, TemplateDefinitionListDto) + */ + @POST + @Produces(TemplateDefinitionListDto.BASE_MEDIA_TYPE) + @Consumes(TemplateDefinitionListDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createTemplateDefinitionList( + @EndpointLink("appslib/templateDefinitionLists") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(BindToXMLPayload.class) TemplateDefinitionListDto templateList); + + /** + * @see EnterpriseApi#updateTemplateDefinitionList(TemplateDefinitionListDto) + */ + @PUT + @Produces(TemplateDefinitionListDto.BASE_MEDIA_TYPE) + @Consumes(TemplateDefinitionListDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateTemplateDefinitionList( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) TemplateDefinitionListDto templateList); + + /** + * @see EnterpriseApi#deleteTemplateDefinitionList(EnterpriseDto) + */ + @DELETE + ListenableFuture deleteTemplateDefinitionList( + @EndpointLink("edit") @BinderParam(BindToPath.class) TemplateDefinitionListDto templateList); + + /** + * @see EnterpriseApi#getTemplateDefinitionList(EnterpriseDto, Integer) + */ + @GET + @Consumes(TemplateDefinitionListDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTemplateDefinitionList( + @EndpointLink("appslib/templateDefinitionLists") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(AppendToPath.class) Integer templateListId); + + /** + * @see EnterpriseApi#getTemplateDefinitionList(EnterpriseDto, Integer) + */ + @GET + @Consumes(TemplatesStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listTemplateListStatus( + @EndpointLink("repositoryStatus") @BinderParam(BindToPath.class) TemplateDefinitionListDto templateList, + @QueryParam("datacenterId") @ParamParser(ParseDatacenterId.class) DatacenterDto datacenter); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventApi.java new file mode 100644 index 0000000000..39b6055f82 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventApi.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.concurrent.Timeout; + +import com.abiquo.server.core.event.EventsDto; + +/** + * Provides synchronous access to Abiquo Event API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see EventAsyncApi + * @author Ignasi Barrera + * @author Vivien Mahé + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface EventApi +{ + /** + * List events. + * + * @return The list of events. + */ + EventsDto listEvents(); + + /** + * List events using filters. + * + * @return The list of events using filters. + */ + EventsDto listEvents(EventOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventAsyncApi.java new file mode 100644 index 0000000000..ac7580d0cb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/EventAsyncApi.java @@ -0,0 +1,64 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; + +import com.abiquo.server.core.event.EventsDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Event API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see EventApi + * @author Ignasi Barrera + * @author Vivien Mahé + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +public interface EventAsyncApi +{ + /** + * @see EventApi#listEvents() + */ + @GET + @Path("/events") + @Consumes(EventsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listEvents(); + + /** + * @see EventApi#listEvents() + */ + @GET + @Path("/events") + @Consumes(EventsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listEvents(EventOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java new file mode 100644 index 0000000000..38d57230f6 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java @@ -0,0 +1,1038 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.infrastructure.options.DatacenterOptions; +import org.jclouds.abiquo.domain.infrastructure.options.IpmiOptions; +import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.domain.network.options.NetworkOptions; +import org.jclouds.abiquo.domain.options.search.FilterOptions; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.concurrent.Timeout; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.server.core.cloud.HypervisorTypesDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.BladeLocatorLedDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.FsmsDto; +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.LogicServersDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; +import com.abiquo.server.core.infrastructure.MachineStateDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.OrganizationDto; +import com.abiquo.server.core.infrastructure.OrganizationsDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.RacksDto; +import com.abiquo.server.core.infrastructure.RemoteServiceDto; +import com.abiquo.server.core.infrastructure.RemoteServicesDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.abiquo.server.core.infrastructure.UcsRacksDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VlanTagAvailabilityDto; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesMetadataDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; + +/** + * Provides synchronous access to Abiquo Infrastructure API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see InfrastructureAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface InfrastructureApi +{ + /*********************** Datacenter ***********************/ + + /** + * List all datacenters. + * + * @return The list of Datacenters. + */ + DatacentersDto listDatacenters(); + + /** + * Create a new datacenter. + * + * @param datacenter The datacenter to be created. + * @return The created datacenter. + */ + DatacenterDto createDatacenter(DatacenterDto datacenter); + + /** + * Get the given datacenter. + * + * @param datacenterId The id of the datacenter. + * @return The datacenter or null if it does not exist. + */ + DatacenterDto getDatacenter(Integer datacenterId); + + /** + * Updates an existing datacenter. + * + * @param datacenter The new attributes for the datacenter. + * @return The updated datacenter. + */ + DatacenterDto updateDatacenter(DatacenterDto datacenter); + + /** + * Deletes an existing datacenter. + * + * @param datacenter The datacenter to delete. + */ + void deleteDatacenter(DatacenterDto datacenter); + + /** + * Retrieve remote machine information. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveremotemachineinformation + * @param datacenter The datacenter. + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + MachineDto discoverSingleMachine(DatacenterDto datacenter, String ip, + HypervisorType hypervisorType, String user, String password); + + /** + * Retrieve remote machine information. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrieveremotemachineinformation + * @param datacenter The datacenter. + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @param options Optional query params. + * @return The physical machine. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + MachineDto discoverSingleMachine(DatacenterDto datacenter, String ip, + HypervisorType hypervisorType, String user, String password, MachineOptions options); + + /** + * Retrieve a list of remote machine information. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievealistofremotemachineinformation + * @param datacenter The datacenter. + * @param ipFrom IP address of the remote first hypervisor to check. + * @param ipTo IP address of the remote last hypervisor to check. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine list. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + MachinesDto discoverMultipleMachines(final DatacenterDto datacenter, final String ipFrom, + final String ipTo, final HypervisorType hypervisorType, final String user, + final String password); + + /** + * Retrieve a list of remote machine information. + * + * @see API: http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource- + * Retrievealistofremotemachineinformation + * @param datacenter The datacenter. + * @param ipFrom IP address of the remote first hypervisor to check. + * @param ipTo IP address of the remote last hypervisor to check. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @param options Optional query params. + * @return The physical machine list. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + MachinesDto discoverMultipleMachines(final DatacenterDto datacenter, final String ipFrom, + final String ipTo, final HypervisorType hypervisorType, final String user, + final String password, final MachineOptions options); + + /** + * Retreives limits for the given datacenter and any enterprise. + * + * @param datacenter The datacenter. + * @return The usage limits for the datacenter on any enterprise. + */ + DatacentersLimitsDto listLimits(DatacenterDto datacenter); + + /** + * Check the state of a remote machine. This machine does not need to be managed by Abiquo. + * + * @param datacenter The datacenter. + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @return The physical machine state information. + */ + MachineStateDto checkMachineState(DatacenterDto datacenter, String ip, + HypervisorType hypervisorType, String user, String password); + + /** + * Check the state of a remote machine. This machine does not need to be managed by Abiquo. + * + * @param datacenter The datacenter. + * @param ip IP address of the remote hypervisor to connect. + * @param hypervisorType Kind of hypervisor we want to connect. Valid values are {vbox, kvm, + * xen-3, vmx-04, hyperv-301, xenserver}. + * @param user User to log in. + * @param password Password to authenticate. + * @param options Optional query params. + * @return The physical machine state information. + */ + MachineStateDto checkMachineState(DatacenterDto datacenter, String ip, + HypervisorType hypervisorType, String user, String password, MachineOptions options); + + /** + * Check the ipmi configuration state of a remote machine. This machine does not need to be + * managed by Abiquo. + * + * @param datacenter The datacenter. + * @param ip IP address of the remote hypervisor to connect. + * @param user User to log in. + * @param password Password to authenticate. + * @return The ipmi configuration state information + */ + MachineIpmiStateDto checkMachineIpmiState(DatacenterDto datacenter, String ip, String user, + String password); + + /** + * Check the ipmi configuration state of a remote machine. This machine does not need to be + * managed by Abiquo. + * + * @param datacenter The datacenter. + * @param ip IP address of the remote hypervisor to connect. + * @param user User to log in. + * @param password Password to authenticate. + * @param options Optional query params. + * @return The ipmi configuration state information + */ + MachineIpmiStateDto checkMachineIpmiState(DatacenterDto datacenter, String ip, String user, + String password, IpmiOptions options); + + /*********************** Hypervisor ***********************/ + + /** + * Retreives the hypervisor type of a remote a machine. + * + * @param datacenter The datacenter. + * @param options Optional query params. + * @return The hypervisor type. + */ + String getHypervisorTypeFromMachine(DatacenterDto datacenter, DatacenterOptions options); + + /** + * Retreives the hypervisor types in the datacenter. + * + * @param datacenter The datacenter. + * @return The hypervisor types. + */ + HypervisorTypesDto getHypervisorTypes(DatacenterDto datacenter); + + /*********************** Unmanaged Rack ********************** */ + + /** + * List all not managed racks for a datacenter. + * + * @param datacenter The datacenter. + * @return The list of not managed racks for the datacenter. + */ + RacksDto listRacks(DatacenterDto datacenter); + + /** + * Create a new not managed rack in a datacenter. + * + * @param datacenter The datacenter. + * @param rack The rack to be created. + * @return The created rack. + */ + RackDto createRack(final DatacenterDto datacenter, final RackDto rack); + + /** + * Get the given rack from the given datacenter. + * + * @param datacenter The datacenter. + * @param rackId The id of the rack. + * @return The rack or null if it does not exist. + */ + RackDto getRack(DatacenterDto datacenter, Integer rackId); + + /** + * Updates an existing rack from the given datacenter. + * + * @param rack The new attributes for the rack. + * @return The updated rack. + */ + RackDto updateRack(final RackDto rack); + + /** + * Deletes an existing rack. + * + * @param rack The rack to delete. + */ + void deleteRack(final RackDto rack); + + /*********************** Managed Rack **********************/ + + /** + * List all managed racks for a datacenter. + * + * @param datacenter The datacenter. + * @return The list of managed racks for the datacenter. + */ + @EnterpriseEdition + @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) + UcsRacksDto listManagedRacks(DatacenterDto datacenter); + + /** + * Create a new managed rack in a datacenter. + * + * @param datacenter The datacenter. + * @param rack The managed rack to be created. + * @return The created rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + UcsRackDto createManagedRack(final DatacenterDto datacenter, final UcsRackDto rack); + + /** + * Get the given managed rack from the given datacenter. + * + * @param datacenter The datacenter. + * @param rackId The id of the rack. + * @return The rack or null if it does not exist. + */ + @EnterpriseEdition + @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) + UcsRackDto getManagedRack(DatacenterDto datacenter, Integer rackId); + + /** + * Updates an existing managed rack from the given datacenter. + * + * @param rack The new attributes for the rack. + * @return The updated rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + UcsRackDto updateManagedRack(final UcsRackDto rack); + + /** + * List all service profiles of the ucs rack. + * + * @param rack The ucs rack. + * @return The list of service profiles for the rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + LogicServersDto listServiceProfiles(UcsRackDto rack); + + /** + * List service profiles of the ucs rack with filtering options. + * + * @param rack The ucs rack. + * @param options Optional query params. + * @return The list of service profiles for the rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + LogicServersDto listServiceProfiles(UcsRackDto rack, FilterOptions options); + + /** + * List all service profile templates of the ucs rack. + * + * @param rack The ucs rack. + * @return The list of service profile templates for the rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + LogicServersDto listServiceProfileTemplates(UcsRackDto rack); + + /** + * List all service profile templates of the ucs rack with options. + * + * @param rack The ucs rack. + * @param options Optional query params. + * @return The list of service profile templates for the rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + LogicServersDto listServiceProfileTemplates(UcsRackDto rack, FilterOptions options); + + /** + * List all organizations of the ucs rack. + * + * @param rack The ucs rack. + * @return The list of organizations for the rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + OrganizationsDto listOrganizations(UcsRackDto rack); + + /** + * List all organizations of the ucs rack with options. + * + * @param rack The ucs rack. + * @param options Optional query params. + * @return The list of organizations for the rack. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + OrganizationsDto listOrganizations(UcsRackDto rack, FilterOptions options); + + /** + * Clone a service profile. + * + * @param rack The managed rack where thw service profile will be created. + * @param logicServer The original logic server. + * @param organization The organization to be associated. + * @param newName The name of the new service profile. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void cloneLogicServer(UcsRackDto rack, LogicServerDto logicServer, + OrganizationDto organization, String newName); + + /** + * Delete a service profile. + * + * @param rack The managed rack where the service profile will be created. + * @param logicServer The original logic server. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void deleteLogicServer(UcsRackDto rack, LogicServerDto logicServer); + + /** + * Associate a service profile with a blade. + * + * @param rack The managed rack where the service profile is. + * @param logicServer The logic server. + * @param organization The organization to be associated. + * @param bladeName The name of the blade. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void associateLogicServer(UcsRackDto rack, LogicServerDto logicServer, + OrganizationDto organization, String bladeName); + + /** + * Associate a service profile with a blade instantiating a service profile template. + * + * @param rack The managed rack where the service profile is. + * @param logicServer The logic server. + * @param organization The organization to be associated. + * @param newName Name of the new service profile. + * @param bladeName The name of the blade. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void associateTemplate(UcsRackDto rack, LogicServerDto logicServer, + OrganizationDto organization, String newName, String bladeName); + + /** + * Clone a service profile and associate it with a blade. + * + * @param rack The managed rack where the service profile is. + * @param logicServer The logic server. + * @param organization The organization to be associated. + * @param newName Name of the new service profile. + * @param bladeName The name of the blade. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void cloneAndAssociateLogicServer(UcsRackDto rack, LogicServerDto logicServer, + OrganizationDto organization, String newName, String bladeName); + + /** + * Dissociate a service profile from a blade. + * + * @param rack The managed rack where the service profile is. + * @param logicServer The logic server. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + void dissociateLogicServer(UcsRackDto rack, LogicServerDto logicServer); + + /** + * Get FSM list of an entity + * + * @param rack The managed rack where the entity belongs. + * @param dn Distinguished name of the entity. + * @param fsm The fsm. + */ + @EnterpriseEdition + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + FsmsDto listFsms(UcsRackDto rack, String dn); + + /*********************** Remote Service ********************** */ + + /** + * List all remote services of the datacenter. + * + * @param datacenter The datacenter. + * @return The list of remote services for the datacenter. + */ + RemoteServicesDto listRemoteServices(DatacenterDto dataceter); + + /** + * Create a new remote service in a datacenter. + * + * @param datacenter The datacenter. + * @param remoteService The remote service to be created. + * @return The created remote service. + */ + RemoteServiceDto createRemoteService(final DatacenterDto datacenter, + final RemoteServiceDto remoteService); + + /** + * Get the given remote service from the given datacenter. + * + * @param datacenter The datacenter. + * @param remoteServiceType The type of the remote service. + * @return The remote service or null if it does not exist. + */ + RemoteServiceDto getRemoteService(DatacenterDto datacenter, RemoteServiceType remoteServiceType); + + /** + * Updates an existing remote service from the given datacenter. + * + * @param remoteService The new attributes for the remote service. + * @return The updated remote service. + */ + RemoteServiceDto updateRemoteService(RemoteServiceDto remoteService); + + /** + * Deletes an existing remote service. + * + * @param remoteService The remote service to delete. + */ + void deleteRemoteService(RemoteServiceDto remoteService); + + /** + * Check if the given remote service is available and properly configured. + * + * @param remoteService The remote service to check. + * @return A Boolean indicating if the remote service is available. + */ + boolean isAvailable(RemoteServiceDto remoteService); + + /*********************** Machine ********************** */ + + /** + * Create a new physical machine in a rack. + * + * @param rack The rack. + * @param machine The physical machine to be created. + * @return The created physical machine. + */ + MachineDto createMachine(RackDto rack, MachineDto machine); + + /** + * Get the given machine from the given rack. + * + * @param rack The rack. + * @param machineId The id of the machine. + * @return The machine or null if it does not exist. + */ + MachineDto getMachine(RackDto rack, Integer machineId); + + /** + * Checks the real infrastructure state for the given physical machine. The machine is updated + * with the result state. + * + * @param machine The machine to check + * @paran boolean that indicates a database synchronization + * @return A machineStateDto with a machine state value from enum MachineState + */ + MachineStateDto checkMachineState(MachineDto machine, boolean sync); + + /** + * Checks the ipmi configuration state for the given physical machine. + * + * @param machine The machine to check + * @return A machineIpmiStateDto with a machine ipmi configuration state value from enum + * MachineState + */ + MachineIpmiStateDto checkMachineIpmiState(MachineDto machine); + + /** + * Updates an existing physical machine. + * + * @param machine The new attributes for the physical machine. + * @return The updated machine. + */ + MachineDto updateMachine(MachineDto machine); + + /** + * Deletes an existing physical machine. + * + * @param machine The physical machine to delete. + */ + void deleteMachine(MachineDto machine); + + /** + * Reserve the given machine for the given enterprise. + * + * @param enterprise The enterprise reserving the machine. + * @param machine The machine to reserve. + * @return The reserved machine. + */ + MachineDto reserveMachine(EnterpriseDto enterprise, MachineDto machine); + + /** + * Cancels the reservation of the given machine. + * + * @param enterprise The enterprise to cancel reservation. + * @param machine The machine to release. + */ + Void cancelReservation(EnterpriseDto enterprise, MachineDto machine); + + /** + * List all machines racks for a rack. + * + * @param rack The rack. + * @return The list of physical machines for the rack. + */ + MachinesDto listMachines(RackDto rack); + + /*********************** Blade ***********************/ + + /** + * Power off a physical machine in a UCS rack. + * + * @param machime The phyisical machine. + */ + @EnterpriseEdition + void powerOff(MachineDto machine); + + /** + * Power on a physical machine in a UCS rack. + * + * @param machime The phyisical machine. + */ + @EnterpriseEdition + void powerOn(MachineDto machine); + + /** + * Get the logic server associated with a machine in a Cisc UCS rack. + * + * @param machime The phyisical machine. + * @return The logic server. + */ + @EnterpriseEdition + LogicServerDto getLogicServer(MachineDto machine); + + /** + * Turn off locator led of a physical machine in a UCS rack. + * + * @param machime The phyisical machine. + */ + @EnterpriseEdition + void ledOn(MachineDto machine); + + /** + * Light locator led of a physical machine in a UCS rack. + * + * @param machime The phyisical machine. + */ + @EnterpriseEdition + void ledOff(MachineDto machine); + + /** + * Get led locator info from a physical machine in a UCS rack. + * + * @param machime The phyisical machine. + * @return Led locator information. + */ + @EnterpriseEdition + BladeLocatorLedDto getLocatorLed(MachineDto machine); + + /** + * List all virtual machines in a physical machine. + * + * @param machine The physical machine. + * @return The list of virtual machines in the physical machine. + */ + VirtualMachinesWithNodeExtendedDto listVirtualMachinesByMachine(MachineDto machine, + MachineOptions options); + + /** + * Get the given virtual machine + * + * @param machine + * @param virtualMachineId + * @return + */ + VirtualMachineWithNodeExtendedDto getVirtualMachine(MachineDto machine, Integer virtualMachineId); + + /*********************** Storage Device ***********************/ + + /** + * List all storage devices of the datacenter. + * + * @param datacenter The datacenter. + * @return The list of storage devices in the datacenter. + */ + @EnterpriseEdition + StorageDevicesDto listStorageDevices(DatacenterDto datacenter); + + /** + * List all supported storage devices. + * + * @param datacenter The datacenter. + * @return The list of supported storage devices. + */ + @EnterpriseEdition + StorageDevicesMetadataDto listSupportedStorageDevices(DatacenterDto datacenter); + + /** + * Get the storage device. + * + * @param storageDeviceId The id of the storage device. + * @return The storage device or null if it does not exist. + */ + @EnterpriseEdition + StorageDeviceDto getStorageDevice(DatacenterDto datacenter, Integer storageDeviceId); + + /** + * Create a new storage device. + * + * @param datacenter The datacenter. + * @param storageDevice The storage device to be created. + * @return The created storage device. + */ + @EnterpriseEdition + StorageDeviceDto createStorageDevice(final DatacenterDto datacenter, + final StorageDeviceDto storageDevice); + + /** + * Deletes an existing storage device. + * + * @param storageDevice The storage device to delete. + */ + @EnterpriseEdition + void deleteStorageDevice(StorageDeviceDto storageDevice); + + /** + * Updates an existing storage device. + * + * @param storageDevice The new attributes for the storage device. + * @return The updated storage device. + */ + @EnterpriseEdition + StorageDeviceDto updateStorageDevice(StorageDeviceDto storageDevice); + + /*********************** Tier ***********************/ + /** + * List all tiers of the datacenter. + * + * @param datacenter The datacenter. + * @return The list of tiers in the datacenter. + */ + @EnterpriseEdition + TiersDto listTiers(DatacenterDto datacenter); + + /** + * Updates a tier. + * + * @param tier The new attributes for the tier. + * @return The updated tier. + */ + @EnterpriseEdition + TierDto updateTier(TierDto tier); + + /** + * Get the tier. + * + * @param tierId The id of the tier. + * @return The tier or null if it does not exist. + */ + @EnterpriseEdition + TierDto getTier(DatacenterDto datacenter, Integer tierId); + + /*********************** Storage Pool ***********************/ + + /** + * List storage pools on a storage device. + * + * @param storageDevice The storage device. + * @param options Optional query params. + * @return The list of storage pools in the storage device. + */ + @EnterpriseEdition + StoragePoolsDto listStoragePools(StorageDeviceDto storageDeviceDto, + StoragePoolOptions storagePoolOptions); + + /** + * List storage pools on a tier. + * + * @param tier The tier device. + * @return The list of storage pools in the tier. + */ + @EnterpriseEdition + StoragePoolsDto listStoragePools(TierDto tier); + + /** + * Create a new storage pool in a storage device. + * + * @param storageDevice The storage device. + * @param storagePool The storage pool to be created. + * @return The created storage pool. + */ + @EnterpriseEdition + StoragePoolDto createStoragePool(StorageDeviceDto storageDevice, StoragePoolDto storagePool); + + /** + * Updates a storage pool. + * + * @param storagePool The new attributes for the storage pool. + * @return The updated tier. + */ + @EnterpriseEdition + StoragePoolDto updateStoragePool(StoragePoolDto storagePool); + + /** + * Deletes an existing storage pool. + * + * @param storagePool The storage pool to delete. + */ + @EnterpriseEdition + void deleteStoragePool(StoragePoolDto storagePool); + + /** + * Get the storage pool. + * + * @param storageDevice The storage device. + * @param storagePoolId The id of the storage pool. + * @return The storage pool or null if it does not exist. + */ + @EnterpriseEdition + StoragePoolDto getStoragePool(StorageDeviceDto storageDevice, String storagePoolId); + + /** + * Refresh the given storage pool data. + * + * @param storagePool The storage pool to refresh. + * @param options The options to query the storage pool. + * @return The updated storage pool. + */ + @EnterpriseEdition + StoragePoolDto refreshStoragePool(StoragePoolDto storagePool, StoragePoolOptions options); + + /*********************** Network ***********************/ + + /** + * List all public, external and not managed networks of a datacenter. + * + * @param datacenter The datacenter. + * @return The list of not public, external and not managed for the datacenter. + */ + @EnterpriseEdition + VLANNetworksDto listNetworks(DatacenterDto datacenter); + + /** + * List networks of a datacenter with options. + * + * @param datacenter The datacenter. + * @param options Optional query params. + * @return The list of not public, external and not managed for the datacenter. + */ + @EnterpriseEdition + VLANNetworksDto listNetworks(DatacenterDto datacenter, NetworkOptions options); + + /** + * Get the given network from the given datacenter. + * + * @param datacenter The datacenter. + * @param networkId The id of the network. + * @return The rack or null if it does not exist. + */ + VLANNetworkDto getNetwork(DatacenterDto datacenter, Integer networkId); + + /** + * Create a new public network. + * + * @param storageDevice The storage device. + * @param storagePool The storage pool to be created. + * @return The created storage pool. + */ + @EnterpriseEdition + VLANNetworkDto createNetwork(DatacenterDto datacenter, VLANNetworkDto network); + + /** + * Updates a network. + * + * @param network The new attributes for the network. + * @return The updated tier. + */ + @EnterpriseEdition + VLANNetworkDto updateNetwork(VLANNetworkDto network); + + /** + * Deletes an existing network. + * + * @param network The network to delete. + */ + @EnterpriseEdition + void deleteNetwork(VLANNetworkDto network); + + /** + * Check the availability of a tag. + * + * @param datacenter The datacenter. + * @param tag Tag to check. + * @return A tag availability object. + */ + @EnterpriseEdition + VlanTagAvailabilityDto checkTagAvailability(DatacenterDto datacenter, Integer tag); + + /*********************** Network IPs ***********************/ + + /** + * List all the IPs in the given public network. + * + * @param network The public network. + * @return The IPs in the given public network. + * @since 2.3 + */ + PublicIpsDto listPublicIps(VLANNetworkDto network); + + /** + * List all the IPs in the given public network. + * + * @param network The public network. + * @param options The filtering options. + * @return The IPs in the given public network. + * @since 2.3 + */ + PublicIpsDto listPublicIps(VLANNetworkDto network, IpOptions options); + + /** + * Get the given public ip. + * + * @param network The public network. + * @param ipId The id of the ip to get. + * @return The requested ip. + * @since 2.3 + */ + PublicIpDto getPublicIp(VLANNetworkDto network, Integer ipId); + + /** + * List all the IPs in the given external network. + * + * @param network The external network. + * @return The IPs in the given external network. + * @since 2.3 + */ + ExternalIpsDto listExternalIps(VLANNetworkDto network); + + /** + * List all the IPs in the given external network. + * + * @param network The external network. + * @param options The filtering options. + * @return The IPs in the given external network. + * @since 2.3 + */ + ExternalIpsDto listExternalIps(VLANNetworkDto network, IpOptions options); + + /** + * Get the given external ip. + * + * @param network The external network. + * @param ipId The id of the ip to get. + * @return The requested ip. + * @since 2.3 + */ + ExternalIpDto getExternalIp(VLANNetworkDto network, Integer ipId); + + /** + * List all the IPs in the given unmanaged network. + * + * @param network The unmanaged network. + * @return The IPs in the given unmanaged network. + * @since 2.3 + */ + UnmanagedIpsDto listUnmanagedIps(VLANNetworkDto network); + + /** + * List all the IPs in the given unmanaged network. + * + * @param network The unmanaged network. + * @param options The filtering options. + * @return The IPs in the given unmanaged network. + * @since 2.3 + */ + UnmanagedIpsDto listUnmanagedIps(VLANNetworkDto network, IpOptions options); + + /** + * Get the given unmanaged ip. + * + * @param network The unmanaged network. + * @param ipId The id of the ip to get. + * @return The requested ip. + * @since 2.3 + */ + UnmanagedIpDto getUnmanagedIp(VLANNetworkDto network, Integer ipId); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureAsyncApi.java new file mode 100644 index 0000000000..892b79bad1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureAsyncApi.java @@ -0,0 +1,1110 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.abiquo.binders.AppendToPath; +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.binders.infrastructure.AppendMachineIdToPath; +import org.jclouds.abiquo.binders.infrastructure.AppendRemoteServiceTypeToPath; +import org.jclouds.abiquo.binders.infrastructure.BindSupportedDevicesLinkToPath; +import org.jclouds.abiquo.binders.infrastructure.ucs.BindLogicServerParameters; +import org.jclouds.abiquo.binders.infrastructure.ucs.BindOrganizationParameters; +import org.jclouds.abiquo.domain.infrastructure.options.DatacenterOptions; +import org.jclouds.abiquo.domain.infrastructure.options.IpmiOptions; +import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.domain.network.options.NetworkOptions; +import org.jclouds.abiquo.domain.options.search.FilterOptions; +import org.jclouds.abiquo.functions.ReturnAbiquoExceptionOnNotFoundOr4xx; +import org.jclouds.abiquo.functions.ReturnFalseIfNotAvailable; +import org.jclouds.abiquo.functions.infrastructure.ParseDatacenterId; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.server.core.cloud.HypervisorTypesDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.BladeLocatorLedDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.FsmsDto; +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.LogicServersDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; +import com.abiquo.server.core.infrastructure.MachineStateDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.OrganizationDto; +import com.abiquo.server.core.infrastructure.OrganizationsDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.RacksDto; +import com.abiquo.server.core.infrastructure.RemoteServiceDto; +import com.abiquo.server.core.infrastructure.RemoteServicesDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.abiquo.server.core.infrastructure.UcsRacksDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VlanTagAvailabilityDto; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesMetadataDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Infrastructure API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see InfrastructureApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +@Path("/admin") +public interface InfrastructureAsyncApi +{ + /*********************** Datacenter ***********************/ + + /** + * @see InfrastructureApi#listDatacenters() + */ + @GET + @Path("/datacenters") + @Consumes(DatacentersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listDatacenters(); + + /** + * @see InfrastructureApi#createDatacenter(DatacenterDto) + */ + @POST + @Path("/datacenters") + @Produces(DatacenterDto.BASE_MEDIA_TYPE) + @Consumes(DatacenterDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createDatacenter( + @BinderParam(BindToXMLPayload.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#getDatacenter(Integer) + */ + @GET + @Path("/datacenters/{datacenter}") + @Consumes(DatacenterDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getDatacenter(@PathParam("datacenter") Integer datacenterId); + + /** + * @see InfrastructureApi#updateDatacenter(DatacenterDto) + */ + @PUT + @Produces(DatacenterDto.BASE_MEDIA_TYPE) + @Consumes(DatacenterDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateDatacenter( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#deleteDatacenter(DatacenterDto) + */ + @DELETE + ListenableFuture deleteDatacenter( + @EndpointLink("edit") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#discoverSingleMachine(DatacenterDto, String, HypervisorType, String, + * String) + */ + @GET + @Consumes(MachineDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture discoverSingleMachine( + @EndpointLink("discoversingle") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ip") String ip, @QueryParam("hypervisor") HypervisorType hypervisorType, + @QueryParam("user") String user, @QueryParam("password") String password); + + /** + * @see InfrastructureApi#discoverSingleMachine(DatacenterDto, String, HypervisorType, String, + * String, MachineOptions) + */ + @GET + @Consumes(MachineDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture discoverSingleMachine( + @EndpointLink("discoversingle") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ip") String ip, @QueryParam("hypervisor") HypervisorType hypervisorType, + @QueryParam("user") String user, @QueryParam("password") String password, + MachineOptions options); + + /** + * @see InfrastructureApi#discoverMultipleMachines(DatacenterDto, String, String, + * HypervisorType, String, String) + */ + @GET + @Consumes(MachinesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture discoverMultipleMachines( + @EndpointLink("discovermultiple") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ipFrom") String ipFrom, @QueryParam("ipTo") String ipTo, + @QueryParam("hypervisor") HypervisorType hypervisorType, @QueryParam("user") String user, + @QueryParam("password") String password); + + /** + * @see InfrastructureApi#discoverMultipleMachines(DatacenterDto, String, String, + * HypervisorType, String, String, MachineOptions) + */ + @GET + @Consumes(MachinesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture discoverMultipleMachines( + @EndpointLink("discovermultiple") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ipFrom") String ipFrom, @QueryParam("ipTo") String ipTo, + @QueryParam("hypervisor") HypervisorType hypervisorType, @QueryParam("user") String user, + @QueryParam("password") String password, MachineOptions options); + + /** + * @see InfrastructureApi#listLimits(DatacenterDto) + */ + @GET + @Consumes(DatacentersLimitsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listLimits( + @EndpointLink("getLimits") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#checkMachineState(DatacenterDto, String, String, HypervisorType, + * String, String) + */ + @GET + @Consumes(MachineStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture checkMachineState( + @EndpointLink("checkmachinestate") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ip") String ip, @QueryParam("hypervisor") HypervisorType hypervisorType, + @QueryParam("user") String user, @QueryParam("password") String password); + + /** + * @see InfrastructureApi#checkMachineState(DatacenterDto, String, String, HypervisorType, + * String, String, MachineOptions) + */ + @GET + @Consumes(MachineStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture checkMachineState( + @EndpointLink("checkmachinestate") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ip") String ip, @QueryParam("hypervisor") HypervisorType hypervisorType, + @QueryParam("user") String user, @QueryParam("password") String password, + MachineOptions options); + + /** + * @see InfrastructureApi#checkMachineIpmiState(DatacenterDto, String, String, String) + */ + @GET + @Consumes(MachineIpmiStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture checkMachineIpmiState( + @EndpointLink("checkmachineipmistate") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ip") String ip, @QueryParam("user") String user, + @QueryParam("password") String password); + + /** + * @see InfrastructureApi#checkMachineIpmiState(DatacenterDto, String, String, String, + * IpmiOptions) + */ + @GET + @Consumes(MachineIpmiStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnAbiquoExceptionOnNotFoundOr4xx.class) + ListenableFuture checkMachineIpmiState( + @EndpointLink("checkmachineipmistate") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @QueryParam("ip") String ip, @QueryParam("user") String user, + @QueryParam("password") String password, IpmiOptions options); + + /*********************** Hypervisor ***********************/ + /** + * @see InfrastructureApi#getHypervisorTypeFromMachine(DatacenterDto, DatacenterOptions) + */ + @GET + @Consumes(MediaType.TEXT_PLAIN) + @ResponseParser(ReturnStringIf2xx.class) + ListenableFuture getHypervisorTypeFromMachine( + @EndpointLink("hypervisor") @BinderParam(BindToPath.class) DatacenterDto datacenter, + DatacenterOptions options); + + /** + * @see InfrastructureApi#getHypervisorTypes(DatacenterDto) + */ + @GET + @Consumes(HypervisorTypesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getHypervisorTypes( + @EndpointLink("hypervisors") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /*********************** Unmanaged Rack ***********************/ + + /** + * @see InfrastructureApi#listRacks(DatacenterDto) + */ + @GET + @Consumes(RacksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listRacks( + @EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#createRack(DatacenterDto, RackDto) + */ + @POST + @Produces(RackDto.BASE_MEDIA_TYPE) + @Consumes(RackDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createRack( + @EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(BindToXMLPayload.class) RackDto rack); + + /** + * @see InfrastructureApi#getRack(DatacenterDto, Integer) + */ + @GET + @Consumes(RackDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getRack( + @EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(AppendToPath.class) Integer rackId); + + /** + * @see InfrastructureApi#updateRack(RackDto) + */ + @PUT + @Consumes(RackDto.BASE_MEDIA_TYPE) + @Produces(RackDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateRack( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) RackDto rack); + + /** + * @see InfrastructureApi#deleteRack(RackDto) + */ + @DELETE + ListenableFuture deleteRack( + @EndpointLink("edit") @BinderParam(BindToPath.class) RackDto rack); + + /*********************** Managed Rack ***********************/ + + /** + * @see InfrastructureApi#listManagedRacks(DatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(UcsRacksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listManagedRacks( + @EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#createManagedRack(DatacenterDto, UcsRackDto) + */ + @EnterpriseEdition + @POST + @Produces(UcsRackDto.BASE_MEDIA_TYPE) + @Consumes(UcsRackDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createManagedRack( + @EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(BindToXMLPayload.class) UcsRackDto rack); + + /** + * @see InfrastructureApi#getManagedRack(DatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @Consumes(UcsRackDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getManagedRack( + @EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(AppendToPath.class) Integer rackId); + + /** + * @see InfrastructureApi#updateManagedRack(UcsRackDto) + */ + @EnterpriseEdition + @PUT + @Consumes(UcsRackDto.BASE_MEDIA_TYPE) + @Produces(UcsRackDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateManagedRack( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) UcsRackDto rack); + + /** + * @see InfrastructureApi#listServiceProfiles(UcsRackDto) + */ + @EnterpriseEdition + @GET + @Consumes(LogicServersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listServiceProfiles( + @EndpointLink("logicservers") @BinderParam(BindToPath.class) UcsRackDto rack); + + /** + * @see InfrastructureApi#listServiceProfiles(UcsRackDto, QueryOptions) + */ + @EnterpriseEdition + @GET + @Consumes(LogicServersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listServiceProfiles( + @EndpointLink("logicservers") @BinderParam(BindToPath.class) UcsRackDto rack, + FilterOptions options); + + /** + * @see InfrastructureApi#listServiceProfileTemplates(UcsRackDto) + */ + @EnterpriseEdition + @GET + @Consumes(LogicServersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listServiceProfileTemplates( + @EndpointLink("ls-templates") @BinderParam(BindToPath.class) UcsRackDto rack); + + /** + * @see InfrastructureApi#listServiceProfileTemplates(UcsRackDto, LogicServerOptions) + */ + @EnterpriseEdition + @GET + @Consumes(LogicServersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listServiceProfileTemplates( + @EndpointLink("ls-templates") @BinderParam(BindToPath.class) UcsRackDto rack, + FilterOptions options); + + /** + * @see InfrastructureApi#listOrganizations(UcsRackDto) + */ + @EnterpriseEdition + @GET + @Consumes(OrganizationsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listOrganizations( + @EndpointLink("organizations") @BinderParam(BindToPath.class) UcsRackDto rack); + + /** + * @see InfrastructureApi#listOrganizations(UcsRackDto, OrganizationOptions) + */ + @EnterpriseEdition + @GET + @Consumes(OrganizationsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listOrganizations( + @EndpointLink("organizations") @BinderParam(BindToPath.class) UcsRackDto rack, + FilterOptions options); + + /** + * @see InfrastructureApi#cloneLogicServer(UcsRackDto, LogicServerDto, OrganizationDto, String) + */ + @EnterpriseEdition + @POST + ListenableFuture cloneLogicServer( + @EndpointLink("ls-clone") @BinderParam(BindToPath.class) UcsRackDto rack, + @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer, + @BinderParam(BindOrganizationParameters.class) OrganizationDto organization, + @QueryParam("newName") String newName); + + /** + * @see InfrastructureApi#associateLogicServer(UcsRackDto, LogicServerDto, OrganizationDto, + * String) + */ + @EnterpriseEdition + @POST + ListenableFuture associateLogicServer( + @EndpointLink("ls-associate") @BinderParam(BindToPath.class) UcsRackDto rack, + @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer, + @BinderParam(BindOrganizationParameters.class) OrganizationDto organization, + @QueryParam("bladeDn") String bladeName); + + /** + * @see InfrastructureApi#associateTemplate(UcsRackDto, LogicServerDto, OrganizationDto, String, + * String) + */ + @EnterpriseEdition + @POST + ListenableFuture associateTemplate( + @EndpointLink("ls-associatetemplate") @BinderParam(BindToPath.class) UcsRackDto rack, + @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer, + @BinderParam(BindOrganizationParameters.class) OrganizationDto organization, + @QueryParam("newName") String newName, @QueryParam("bladeDn") String bladeName); + + /** + * @see InfrastructureApi#cloneAndAssociateLogicServer(UcsRackDto, LogicServerDto, + * OrganizationDto, String, String) + */ + @EnterpriseEdition + @POST + ListenableFuture cloneAndAssociateLogicServer( + @EndpointLink("ls-associateclone") @BinderParam(BindToPath.class) UcsRackDto rack, + @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer, + @BinderParam(BindOrganizationParameters.class) OrganizationDto organization, + @QueryParam("newName") String newName, @QueryParam("bladeDn") String bladeName); + + /** + * @see InfrastructureApi#dissociateLogicServer(UcsRackDto, LogicServerDto) + */ + @EnterpriseEdition + @POST + ListenableFuture dissociateLogicServer( + @EndpointLink("ls-dissociate") @BinderParam(BindToPath.class) UcsRackDto rack, + @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer); + + /** + * @see InfrastructureApi#deleteLogicServer(UcsRackDto, LogicServerDto) + */ + @EnterpriseEdition + @POST + ListenableFuture deleteLogicServer( + @EndpointLink("ls-delete") @BinderParam(BindToPath.class) UcsRackDto rack, + @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer); + + /** + * @see InfrastructureApi#listFsms(UcsRackDto, String) + */ + @EnterpriseEdition + @GET + @Consumes(FsmsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listFsms( + @EndpointLink("fsm") @BinderParam(BindToPath.class) UcsRackDto rack, + @QueryParam("dn") String dn); + + /*********************** Remote Service ***********************/ + + /** + * @see InfrastructureApi#listRemoteServices(DatacenterDto) + */ + @GET + @Consumes(RemoteServicesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listRemoteServices( + @EndpointLink("remoteservices") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#createRemoteService(DatacenterDto, RemoteServiceDto) + */ + @POST + @Produces(RemoteServiceDto.BASE_MEDIA_TYPE) + @Consumes(RemoteServiceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createRemoteService( + @EndpointLink("remoteservices") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(BindToXMLPayload.class) RemoteServiceDto remoteService); + + /** + * @see InfrastructureApi#getRemoteService(DatacenterDto, RemoteServiceType) + */ + @GET + @Consumes(RemoteServiceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getRemoteService( + @EndpointLink("remoteservices") @BinderParam(BindToPath.class) final DatacenterDto datacenter, + @BinderParam(AppendRemoteServiceTypeToPath.class) final RemoteServiceType remoteServiceType); + + /** + * @see InfrastructureApi#updateRemoteService(RemoteServiceDto) + */ + @PUT + @Consumes(RemoteServiceDto.BASE_MEDIA_TYPE) + @Produces(RemoteServiceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateRemoteService( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) RemoteServiceDto remoteService); + + /** + * @see InfrastructureApi#deleteRemoteService(RemoteServiceDto) + */ + @DELETE + ListenableFuture deleteRemoteService( + @EndpointLink("edit") @BinderParam(BindToPath.class) RemoteServiceDto remoteService); + + /** + * @see InfrastructureApi#isAvailable(RemoteServiceDto) + */ + @GET + @ExceptionParser(ReturnFalseIfNotAvailable.class) + ListenableFuture isAvailable( + @EndpointLink("check") @BinderParam(BindToPath.class) RemoteServiceDto remoteService); + + /*********************** Machine ***********************/ + + /** + * @see InfrastructureApi#listMachines(RackDto) + */ + @GET + @Consumes(MachinesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listMachines( + @EndpointLink("machines") @BinderParam(BindToPath.class) RackDto rack); + + /** + * @see InfrastructureApi#createMachine(RackDto, MachineDto) + */ + @POST + @Produces(MachineDto.BASE_MEDIA_TYPE) + @Consumes(MachineDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createMachine( + @EndpointLink("machines") @BinderParam(BindToPath.class) RackDto rack, + @BinderParam(BindToXMLPayload.class) MachineDto machine); + + /** + * @see InfrastructureApi#getMachine(RackDto, Integer) + */ + @GET + @Consumes(MachineDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getMachine( + @EndpointLink("machines") @BinderParam(BindToPath.class) final RackDto rack, + @BinderParam(AppendToPath.class) Integer machineId); + + /** + * @see InfrastructureApi#checkMachineState(MachineDto) + */ + @GET + @Consumes(MachineStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture checkMachineState( + @EndpointLink("checkstate") @BinderParam(BindToPath.class) final MachineDto machine, + @QueryParam("sync") boolean sync); + + /** + * @see InfrastructureApi#checkMachineIpmiState(MachineDto) + */ + @GET + @Consumes(MachineIpmiStateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture checkMachineIpmiState( + @EndpointLink("checkipmistate") @BinderParam(BindToPath.class) final MachineDto machine); + + /** + * @see InfrastructureApi#updateMachine(MachineDto) + */ + @PUT + @Produces(MachineDto.BASE_MEDIA_TYPE) + @Consumes(MachineDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateMachine( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#deleteMachine(MachineDto) + */ + @DELETE + ListenableFuture deleteMachine( + @EndpointLink("edit") @BinderParam(BindToPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#reserveMachine(EnterpriseDto, MachineDto) + */ + @POST + @Consumes(MachineDto.BASE_MEDIA_TYPE) + @Produces(MachineDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture reserveMachine( + @EndpointLink("reservedmachines") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(BindToXMLPayload.class) MachineDto machine); + + /** + * @see InfrastructureApi#cancelReservation(EnterpriseDto, MachineDto) + */ + @DELETE + ListenableFuture cancelReservation( + @EndpointLink("reservedmachines") @BinderParam(BindToPath.class) EnterpriseDto enterprise, + @BinderParam(AppendMachineIdToPath.class) MachineDto machine); + + /*********************** Blade ***********************/ + + /** + * @see InfrastructureApi#powerOff(MachineDto) + */ + @EnterpriseEdition + @PUT + ListenableFuture powerOff( + @EndpointLink("poweroff") @BinderParam(BindToPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#powerOn(MachineDto) + */ + @EnterpriseEdition + @PUT + ListenableFuture powerOn( + @EndpointLink("poweron") @BinderParam(BindToPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#getLogicServer(MachineDto) + */ + @EnterpriseEdition + @GET + @Consumes(LogicServerDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getLogicServer( + @EndpointLink("logicserver") @BinderParam(BindToPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#ledOn(MachineDto) + */ + @EnterpriseEdition + @POST + ListenableFuture ledOn( + @EndpointLink("ledon") @BinderParam(BindToPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#ledOff(MachineDto) + */ + @EnterpriseEdition + @POST + ListenableFuture ledOff( + @EndpointLink("ledoff") @BinderParam(BindToPath.class) MachineDto machine); + + /** + * @see InfrastructureApi#getLedLocator(MachineDto) + */ + @EnterpriseEdition + @GET + @Consumes(BladeLocatorLedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getLocatorLed( + @EndpointLink("led") @BinderParam(BindToPath.class) MachineDto machine); + + /*********************** Storage Device ***********************/ + + /** + * @see InfrastructureApi#listVirtualMachinesByMachine(MachineDto) + */ + @GET + @Consumes(VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachinesByMachine( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) MachineDto machine, + MachineOptions options); + + /** + * @see InfrastructureApi#getVirtualMachine(MachineDto, Integer) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getVirtualMachine( + @EndpointLink("virtualmachines") @BinderParam(BindToPath.class) MachineDto machine, + @BinderParam(AppendToPath.class) Integer virtualMachineId); + + /*********************** Storage Device ***********************/ + + /** + * @see InfrastructureApi#listStorageDevices(DatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(StorageDevicesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listStorageDevices( + @EndpointLink("devices") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#listSupportedStorageDevices(DatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(StorageDevicesMetadataDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listSupportedStorageDevices( + @EndpointLink("devices") @BinderParam(BindSupportedDevicesLinkToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#getStorageDevice(DatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @Consumes(StorageDeviceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getStorageDevice( + @EndpointLink("devices") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(AppendToPath.class) Integer storageDeviceId); + + /** + * @see InfrastructureApi#createStorageDevice(DatacenterDto, StorageDeviceDto) + */ + @EnterpriseEdition + @POST + @Produces(StorageDeviceDto.BASE_MEDIA_TYPE) + @Consumes(StorageDeviceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createStorageDevice( + @EndpointLink("devices") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(BindToXMLPayload.class) StorageDeviceDto storageDevice); + + /** + * @see InfrastructureApi#deleteStorageDevice(StorageDeviceDto) + */ + @EnterpriseEdition + @DELETE + ListenableFuture deleteStorageDevice( + @EndpointLink("edit") @BinderParam(BindToPath.class) StorageDeviceDto storageDevice); + + /** + * @see InfrastructureApi#updateStorageDevice(StorageDeviceDto) + */ + @EnterpriseEdition + @PUT + @Produces(StorageDeviceDto.BASE_MEDIA_TYPE) + @Consumes(StorageDeviceDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateStorageDevice( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) StorageDeviceDto storageDevice); + + /*********************** Tier ***********************/ + + /** + * @see InfrastructureApi#listTiers(DatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(TiersDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listTiers( + @EndpointLink("tiers") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#updateTier(TierDto) + */ + @EnterpriseEdition + @PUT + @Produces(TierDto.BASE_MEDIA_TYPE) + @Consumes(TierDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateTier( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) TierDto tier); + + /** + * @see InfrastructureApi#getTier(DatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @Consumes(TierDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTier( + @EndpointLink("tiers") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(AppendToPath.class) Integer tierId); + + /*********************** Storage Pool ***********************/ + + /** + * @see InfrastructureApi#listStoragePools(StorageDeviceDto, StoragePoolOptions) + */ + @EnterpriseEdition + @GET + @Consumes(StoragePoolsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listStoragePools( + @EndpointLink("pools") @BinderParam(BindToPath.class) StorageDeviceDto storageDevice, + StoragePoolOptions options); + + /** + * @see InfrastructureApi#listStoragePools(TierDto) + */ + @EnterpriseEdition + @GET + @Consumes(StoragePoolsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listStoragePools( + @EndpointLink("pools") @BinderParam(BindToPath.class) TierDto tier); + + /** + * @see InfrastructureApi#createStoragePool(StorageDeviceDto, StoragePoolDto) + */ + @EnterpriseEdition + @POST + @Consumes(StoragePoolDto.BASE_MEDIA_TYPE) + @Produces(StoragePoolDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createStoragePool( + @EndpointLink("pools") @BinderParam(BindToPath.class) StorageDeviceDto storageDevice, + @BinderParam(BindToXMLPayload.class) StoragePoolDto storagePool); + + /** + * @see InfrastructureApi#updateStoragePool(StoragePoolDto) + */ + @EnterpriseEdition + @PUT + // For the most strangest reason in world, compiler does not accept + // constants StoragePoolDto.BASE_MEDIA_TYPE for this method. + @Consumes("application/vnd.abiquo.storagepool+xml") + @Produces("application/vnd.abiquo.storagepool+xml") + @JAXBResponseParser + ListenableFuture updateStoragePool( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) StoragePoolDto StoragePoolDto); + + /** + * @see InfrastructureApi#deleteStoragePool(StoragePoolDto) + */ + @EnterpriseEdition + @DELETE + ListenableFuture deleteStoragePool( + @EndpointLink("edit") @BinderParam(BindToPath.class) StoragePoolDto storagePool); + + /** + * @see InfrastructureApi#getStoragePool(StorageDeviceDto, String) + */ + @EnterpriseEdition + @GET + @Consumes(StoragePoolDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getStoragePool( + @EndpointLink("pools") @BinderParam(BindToPath.class) final StorageDeviceDto storageDevice, + @BinderParam(AppendToPath.class) final String storagePoolId); + + /** + * @see InfrastructureApi#refreshStoragePool(StoragePoolDto, StoragePoolOptions) + */ + @EnterpriseEdition + @GET + @Consumes(StoragePoolDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture refreshStoragePool( + @EndpointLink("edit") @BinderParam(BindToPath.class) StoragePoolDto storagePool, + StoragePoolOptions options); + + /*********************** Network ***********************/ + + /** + * @see InfrastructureApi#listNetworks(DatacenterDto) + */ + @EnterpriseEdition + @GET + @Consumes(VLANNetworksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listNetworks( + @EndpointLink("network") @BinderParam(BindToPath.class) DatacenterDto datacenter); + + /** + * @see InfrastructureApi#listNetwork(DatacenterDto, NetworkOptions) + */ + @EnterpriseEdition + @GET + @Consumes(VLANNetworksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listNetworks( + @EndpointLink("network") @BinderParam(BindToPath.class) DatacenterDto datacenter, + NetworkOptions options); + + /** + * @see InfrastructureApi#getNetwork(DatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getNetwork( + @EndpointLink("network") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(AppendToPath.class) Integer networkId); + + /** + * @see InfrastructureApi#createNetwork(DatacenterDto, VLANNetworkDto) + */ + @EnterpriseEdition + @POST + @Produces(VLANNetworkDto.BASE_MEDIA_TYPE) + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createNetwork( + @EndpointLink("network") @BinderParam(BindToPath.class) DatacenterDto datacenter, + @BinderParam(BindToXMLPayload.class) VLANNetworkDto network); + + /** + * @see InfrastructureApi#updateNetwork(VLANNetworkDto) + */ + @EnterpriseEdition + @PUT + @Produces(VLANNetworkDto.BASE_MEDIA_TYPE) + @Consumes(VLANNetworkDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateNetwork( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VLANNetworkDto network); + + /** + * @see InfrastructureApi#deleteNetwork(VLANNetworkDto) + */ + @EnterpriseEdition + @DELETE + ListenableFuture deleteNetwork( + @EndpointLink("edit") @BinderParam(BindToPath.class) VLANNetworkDto network); + + /** + * @see InfrastructureApi#checkTagAvailability(DatacenterDto, Integer) + */ + @EnterpriseEdition + @GET + @Path("/datacenters/{datacenter}/network/action/checkavailability") + @Consumes(VlanTagAvailabilityDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture checkTagAvailability( + @PathParam("datacenter") @ParamParser(ParseDatacenterId.class) DatacenterDto datacenter, + @QueryParam("tag") Integer tag); + + /*********************** Public Network IPs ***********************/ + + /** + * @see InfrastructureApi#listPublicIps(VLANNetworkDto) + */ + @GET + @Consumes(PublicIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPublicIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network); + + /** + * @see InfrastructureApi#listPublicIps(VLANNetworkDto, IpOptions) + */ + @GET + @Consumes(PublicIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listPublicIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + IpOptions options); + + /** + * @see InfrastructureApi#getPublicIp(VLANNetworkDto, Integer) + */ + @GET + @Consumes(PublicIpDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getPublicIp( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + @BinderParam(AppendToPath.class) Integer ipId); + + /** + * @see InfrastructureApi#listExternalIps(VLANNetworkDto) + */ + @GET + @Consumes(ExternalIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listExternalIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network); + + /** + * @see InfrastructureApi#listExternalIps(VLANNetworkDto, IpOptions) + */ + @GET + @Consumes(ExternalIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listExternalIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + IpOptions options); + + /** + * @see InfrastructureApi#getExternalIp(VLANNetworkDto, Integer) + */ + @GET + @Consumes(ExternalIpDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getExternalIp( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + @BinderParam(AppendToPath.class) Integer ipId); + + /** + * @see InfrastructureApi#listUnmanagedIps(VLANNetworkDto) + */ + @GET + @Consumes(UnmanagedIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listUnmanagedIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network); + + /** + * @see InfrastructureApi#listUnmanagedIps(VLANNetworkDto, IpOptions) + */ + @GET + @Consumes(UnmanagedIpsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listUnmanagedIps( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + IpOptions options); + + /** + * @see InfrastructureApi#getUnmanagedIp(VLANNetworkDto, Integer) + */ + @GET + @Consumes(UnmanagedIpDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture getUnmanagedIp( + @EndpointLink("ips") @BinderParam(BindToPath.class) VLANNetworkDto network, + @BinderParam(AppendToPath.class) Integer ipId); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java new file mode 100644 index 0000000000..989153bd36 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java @@ -0,0 +1,80 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +import com.abiquo.server.core.pricing.CurrenciesDto; +import com.abiquo.server.core.pricing.CurrencyDto; + +/** + * Provides synchronous access to Abiquo Pricing API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see PricingAsyncApi + * @author Ignasi Barrera + * @author Susana Acedo + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface PricingApi +{ + + /*********************** Currency ********************** */ + + /** + * List all currencies + * + * @return The list of currencies + */ + CurrenciesDto listCurrencies(); + + /** + * Get the given currency + * + * @param currencyId The id of the currency + * @return The currency + */ + CurrencyDto getCurrency(Integer currencyId); + + /** + * Create a new currency + * + * @param currency The currency to be created. + * @return The created currency. + */ + CurrencyDto createCurrency(CurrencyDto currency); + + /** + * Updates an existing currency + * + * @param currency The new attributes for the currency + * @return The updated currency + */ + CurrencyDto updateCurrency(final CurrencyDto currency); + + /** + * Deletes an existing currency + * + * @param currency The currency to delete + */ + void deleteCurrency(final CurrencyDto currency); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java new file mode 100644 index 0000000000..34dacbeec1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/PricingAsyncApi.java @@ -0,0 +1,108 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.server.core.pricing.CurrenciesDto; +import com.abiquo.server.core.pricing.CurrencyDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides synchronous access to Abiquo Pricing API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see PricingAsyncApi + * @author Ignasi Barrera + * @author Susana Acedo + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +@Path("/config") +public interface PricingAsyncApi +{ + /*********************** Currency ********************** */ + + /** + * @see ConfigApi#listCurrencies() + */ + @GET + @Path("/currencies") + @Consumes(CurrenciesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listCurrencies(); + + /** + * @see ConfigApi#getCurrency(Integer) + */ + @GET + @Path("/currencies/{currency}") + @Consumes(CurrencyDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCurrency(@PathParam("currency") Integer currencyId); + + /** + * @see ConfigApi#createCurrency(CurrencyDto) + */ + @POST + @Path("/currencies") + @Produces(CurrencyDto.BASE_MEDIA_TYPE) + @Consumes(CurrencyDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture createCurrency( + @BinderParam(BindToXMLPayload.class) CurrencyDto currency); + + /** + * @see ConfigApi#updateCurrency(CurrencyDto) + */ + @PUT + @Produces(CurrencyDto.BASE_MEDIA_TYPE) + @Consumes(CurrencyDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateCurrency( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) CurrencyDto currency); + + /** + * @see ConfigApi#deleteCurrency(CurrencyDto) + */ + @DELETE + ListenableFuture deleteCurrency( + @EndpointLink("edit") @BinderParam(BindToPath.class) CurrencyDto currency); + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskApi.java new file mode 100644 index 0000000000..92505dccff --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskApi.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.abiquo.server.core.task.TaskDto; +import com.abiquo.server.core.task.TasksDto; + +/** + * Provides synchronous access to Abiquo Task API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see TaskAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface TaskApi +{ + /*********************** Task ***********************/ + + /** + * Get a task from its link. + * + * @param link The link of the task. + * @return The task. + */ + TaskDto getTask(final RESTLink link); + + /** + * Get the list of tasks of the given object. + * + * @param dto The object. + * @return The list of tasks for the given object. + */ + TasksDto listTasks(T dto); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskAsyncApi.java new file mode 100644 index 0000000000..1c1bd5be91 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/TaskAsyncApi.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; + +import org.jclouds.abiquo.binders.BindLinkToPath; +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.functions.ReturnNullOn303; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.abiquo.server.core.task.TaskDto; +import com.abiquo.server.core.task.TasksDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Task API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see TaskApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +public interface TaskAsyncApi +{ + /*********************** Task ***********************/ + + /** + * @see TaskApi#getTask(RESTLink) + */ + @GET + @Consumes(TaskDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOn303.class) + ListenableFuture getTask(@BinderParam(BindLinkToPath.class) RESTLink link); + + /** + * @see TaskApi#listTasks(SingleResourceTransportDto) + */ + @GET + @Consumes(TasksDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listTasks( + @EndpointLink("tasks") @BinderParam(BindToPath.class) T dto); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateApi.java new file mode 100644 index 0000000000..8fa30ea194 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateApi.java @@ -0,0 +1,151 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.cloud.options.ConversionOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.concurrent.Timeout; + +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.abiquo.server.core.appslibrary.ConversionsDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; + +/** + * Provides synchronous access to Abiquo Apps library API. + * + * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * @see VirtualMachineTemplateAsyncApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface VirtualMachineTemplateApi +{ + /*********************** Virtual Machine Template ***********************/ + + /** + * List all virtual machine templates for an enterprise in a datacenter repository. + * + * @param enterpriseId Id of the enterprise. + * @param datacenterRepositoryId Id of the datacenter repository contaning the templates. + * @return The list of virtual machine templates for the enterprise in the datacenter + * repository. + */ + VirtualMachineTemplatesDto listVirtualMachineTemplates(Integer enterpriseId, + Integer datacenterRepositoryId); + + /** + * List all virtual machine templates for an enterprise in a datacenter repository. + * + * @param enterpriseId Id of the enterprise. + * @param datacenterRepositoryId Id of the datacenter repository contaning the templates. + * @param options The options to query the virtual machine templates. + * @return The filtered list of virtual machine templates for the enterprise in the datacenter + * repository. + */ + VirtualMachineTemplatesDto listVirtualMachineTemplates(Integer enterpriseId, + Integer datacenterRepositoryId, VirtualMachineTemplateOptions options); + + /** + * Get the given virtual machine template. + * + * @param enterpriseId Id of the enterprise. + * @param datacenterRepositoryId Id of the datacenter repository contaning the templates. + * @param enterpriseId The id of the virtual machine template. + * @return The virtual machine template or null if it does not exist. + */ + VirtualMachineTemplateDto getVirtualMachineTemplate(Integer entepriseId, + Integer datacenterRepositoryId, Integer virtualMachineTemplateId); + + /** + * Updates an existing virtual machine template. + * + * @param template The new attributes for the template. + * @return The updated template. + */ + VirtualMachineTemplateDto updateVirtualMachineTemplate(VirtualMachineTemplateDto template); + + /** + * Deletes an existing virtual machine template. + * + * @param template The virtual machine template to delete. + */ + void deleteVirtualMachineTemplate(VirtualMachineTemplateDto template); + + /** + * Creates a persistent virtual machine template from other virtual machine template. + * + * @param dcRepository The repository where the persistent virtual machine template will be + * created. + * @param options The persistent options like name, volume/tier, virtual datacenter and original + * template. + * @return Response message to the persistent request. + */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) + AcceptedRequestDto createPersistentVirtualMachineTemplate(Integer enterpriseId, + Integer datacenterRepositoryId, VirtualMachineTemplatePersistentDto persistentOptions); + + /** + * List all the conversions for a virtual machine template. + * + * @param template, The virtual machine template of the conversions. + * @return The list of conversions for the virtual machine template. + */ + ConversionsDto listConversions(VirtualMachineTemplateDto template); + + /** + * List conversions for a virtual machine template. + * + * @param template, The virtual machine template of the conversions + * @param options, Optionally filter compatible conversions with a provided hypervisor or with + * the desired state. + * @return The list of conversions for the virtual machine template with the applied constrains. + */ + ConversionsDto listConversions(VirtualMachineTemplateDto template, ConversionOptions options); + + /** + * Get the conversions for a virtual machine template and the desired target format. + * + * @param template, The virtual machine template of the conversion + * @param targetFormat The disk format type of the requested conversion + * @return The conversions for the virtual machine template with the desired target disk format + * type. + */ + ConversionDto getConversion(VirtualMachineTemplateDto template, DiskFormatType targetFormat); + + /** + * Starts a V2V conversion of the current virtual machine template, or updates a failed + * conversion. + * + * @param template The virtual machine template to convert + * @param targetFormat The requested target {@link DiskFormatType} of the conversion. + * @param conversion, the dto representing the conversion + * @return an accepted request with a link to track the progress of the conversion tasks. + */ + AcceptedRequestDto requestConversion(VirtualMachineTemplateDto template, + DiskFormatType targetFormat, ConversionDto conversion); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApi.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApi.java new file mode 100644 index 0000000000..ed3821bd3b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApi.java @@ -0,0 +1,184 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.jclouds.abiquo.binders.AppendToPath; +import org.jclouds.abiquo.binders.BindToPath; +import org.jclouds.abiquo.binders.BindToXMLPayloadAndPath; +import org.jclouds.abiquo.domain.cloud.options.ConversionOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.abiquo.functions.ReturnTaskReferenceOrNull; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.abiquo.server.core.appslibrary.ConversionsDto; +import com.abiquo.server.core.appslibrary.DatacenterRepositoryDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Abiquo Abiquo Apps library API. * @see API: + * http://community.abiquo.com/display/ABI20/API+Reference + * + * @see VirtualMachineTemplateApi + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +@Path("/admin/enterprises") +public interface VirtualMachineTemplateAsyncApi +{ + /*********************** Virtual Machine Template ***********************/ + + /** + * @see VirtualMachineTemplateApi#listVirtualMachineTemplates(Integer, Integer) + */ + @GET + @Path("/{enterprise}/datacenterrepositories/{datacenterrepository}/virtualmachinetemplates") + @Consumes(VirtualMachineTemplatesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachineTemplates( + @PathParam("enterprise") Integer enterpriseId, + @PathParam("datacenterrepository") Integer datacenterRepositoryId); + + /** + * @see VirtualMachineTemplateApi#listVirtualMachineTemplates(Integer, Integer, + * VirtualMachineTemplateOptions) + */ + @GET + @Path("/{enterprise}/datacenterrepositories/{datacenterrepository}/virtualmachinetemplates") + @Consumes(VirtualMachineTemplatesDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listVirtualMachineTemplates( + @PathParam("enterprise") Integer enterpriseId, + @PathParam("datacenterrepository") Integer datacenterRepositoryId, + VirtualMachineTemplateOptions options); + + /** + * @see VirtualMachineTemplateApi#getVirtualMachineTemplate(Integer, Integer, Integer) + */ + @GET + @Path("/{enterprise}/datacenterrepositories/{datacenterrepository}/virtualmachinetemplates/{virtualmachinetemplate}") + @Consumes(VirtualMachineTemplateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVirtualMachineTemplate( + @PathParam("enterprise") Integer enterpriseId, + @PathParam("datacenterrepository") Integer datacenterRepositoryId, + @PathParam("virtualmachinetemplate") Integer virtualMachineTemplateId); + + /** + * @see VirtualMachineTemplateApi#updateVirtualMachineTemplate(VirtualMachineTemplateDto) + */ + @PUT + @Produces(VirtualMachineTemplateDto.BASE_MEDIA_TYPE) + @Consumes(VirtualMachineTemplateDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture updateVirtualMachineTemplate( + @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) VirtualMachineTemplateDto template); + + /** + * @see VirtualMachineTemplateApi#deleteVirtualMachineTemplate(VirtualMachineTemplateDto) + */ + @DELETE + ListenableFuture deleteVirtualMachineTemplate( + @EndpointLink("edit") @BinderParam(BindToPath.class) VirtualMachineTemplateDto template); + + /** + * @see VirtualMachineTemplateApi#createPersistentVirtualMachineTemplate(DatacenterRepositoryDto, + * VirtualMachineTemplatePersistentDto) + */ + @POST + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(VirtualMachineTemplatePersistentDto.BASE_MEDIA_TYPE) + @Path("/{enterprise}/datacenterrepositories/{datacenterrepository}/virtualmachinetemplates") + @JAXBResponseParser + ListenableFuture> createPersistentVirtualMachineTemplate( + @PathParam("enterprise") Integer enterpriseId, + @PathParam("datacenterrepository") Integer datacenterRepositoryId, + @BinderParam(BindToXMLPayload.class) VirtualMachineTemplatePersistentDto persistentOptions); + + /*********************** Conversions ***********************/ + + /** + * @see VirtualMachineTemplateApi#listConversions(VirtualMachineTemplateDto) + */ + @GET + @Consumes(ConversionsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listConversions( + @EndpointLink("conversions") @BinderParam(BindToPath.class) VirtualMachineTemplateDto template); + + /** + * @see VirtualMachineTemplateApi#listConversions(VirtualMachineTemplateDto, ConversionOptions) + */ + @GET + @Consumes(ConversionsDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + ListenableFuture listConversions( + @EndpointLink("conversions") @BinderParam(BindToPath.class) final VirtualMachineTemplateDto template, + ConversionOptions options); + + /** + * @see VirtualMachineTemplateApi#getConversion(VirtualMachineTemplateDto, DiskFormatType) + */ + @GET + @Consumes(ConversionDto.BASE_MEDIA_TYPE) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getConversion( + @EndpointLink("conversions") @BinderParam(BindToPath.class) final VirtualMachineTemplateDto template, + @BinderParam(AppendToPath.class) DiskFormatType targetFormat); + + /** + * @see VirtualMachineTemplateApi#updateConversion(ConversinoDto) + */ + @PUT + @ResponseParser(ReturnTaskReferenceOrNull.class) + @Consumes(AcceptedRequestDto.BASE_MEDIA_TYPE) + @Produces(ConversionDto.BASE_MEDIA_TYPE) + ListenableFuture> requestConversion( + @EndpointLink("conversions") @BinderParam(BindToPath.class) final VirtualMachineTemplateDto template, + @BinderParam(AppendToPath.class) DiskFormatType targetFormat, + @BinderParam(BindToXMLPayload.class) ConversionDto conversion); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java new file mode 100644 index 0000000000..ab483b20ed --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java @@ -0,0 +1,241 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features.services; + +import java.util.List; + +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.domain.config.License; +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.domain.config.SystemProperty; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.EnterpriseProperties; +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.internal.BaseAdministrationService; + +import com.google.common.base.Predicate; +import com.google.inject.ImplementedBy; + +/** + * Provides high level Abiquo administration operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@ImplementedBy(BaseAdministrationService.class) +public interface AdministrationService +{ + /*********************** Datacenter ***********************/ + + /** + * Get the list of all datacenters. + */ + Iterable listDatacenters(); + + /** + * Get the list of datacenters matching the given filter. + */ + Iterable listDatacenters(final Predicate filter); + + /** + * Get the first datacenter that matches the given filter or null if none is found. + */ + Datacenter findDatacenter(final Predicate filter); + + /** + * Get the datacenter with the given id. + */ + Datacenter getDatacenter(final Integer datacenterId); + + /** + * Get the list of datacenters with the given ids. + */ + Iterable getDatacenters(final List datacenterIds); + + /*********************** Machine ***********************/ + + /** + * Get the list of all machines in the infrastructure. + */ + public Iterable listMachines(); + + /** + * Get the list of all machines in the infrastructure matching the given filter. + */ + public Iterable listMachines(Predicate filter); + + /** + * Get the first machine in the infrastructure that matches the given filter. + */ + public Machine findMachine(Predicate filter); + + /*********************** Enterprise ***********************/ + + /** + * Get the list of all enterprises. + */ + Iterable listEnterprises(); + + /** + * Get the list of enterprises matching the given filter. + */ + Iterable listEnterprises(final Predicate filter); + + /** + * Get the first enterprises that matches the given filter or null if none is + * found. + */ + Enterprise findEnterprise(final Predicate filter); + + /** + * Get the enterprise with the given id. + */ + Enterprise getEnterprise(final Integer enterpriseId); + + /*********************** Enterprise Properties ***********************/ + /** + * Get the properties of an enterprise. + */ + EnterpriseProperties getEnterpriseProperties(final Enterprise enterprise); + + /*********************** Role ***********************/ + + /** + * Get the list of global roles. + */ + Iterable listRoles(); + + /** + * Get the list of roles matching the given filter. + */ + Iterable listRoles(final Predicate filter); + + /** + * Get the first role that matches the given filter or null if none is found. + */ + Role findRole(final Predicate filter); + + /** + * Get the role with the given id. + */ + Role getRole(final Integer roleId); + + /*********************** Privilege ***********************/ + + /** + * Get the list of global privileges. + */ + Iterable listPrivileges(); + + /** + * Get the list of privileges matching the given filter. + */ + Iterable listPrivileges(final Predicate filter); + + /** + * Get the first privilege that matches the given filter or null if none is found. + */ + Privilege findPrivilege(final Predicate filter); + + /*********************** User ***********************/ + + /** + * Get the current user. + */ + User getCurrentUser(); + + /** + * Get the enterprise of the current user. + */ + Enterprise getCurrentEnterprise(); + + /*********************** License ***********************/ + + /** + * Get the list of all licenses. + */ + Iterable listLicenses(); + + /** + * Get the list of all active/inactive licenses. + * + * @param active Defines if searching for active (true) or inactive ( + * false) licenses. + */ + Iterable listLicenses(boolean active); + + /** + * Get the list of licenses matching the given filter. + */ + Iterable listLicenses(final Predicate filter); + + /** + * Get the first license that matches the given filter or null if none is found. + */ + License findLicense(final Predicate filter); + + /*********************** System Properties ***********************/ + + /** + * Get the list of system properties. + */ + Iterable listSystemProperties(); + + /** + * Get the list of system properties matching the given filter. + */ + Iterable listSystemProperties(final Predicate filter); + + /** + * Get the first system property that matches the given filter or null if none is + * found. + */ + SystemProperty findSystemProperty(final Predicate filter); + + /** + * Get the system property with the give name or null if none is found. + */ + SystemProperty getSystemProperty(String name); + + /** + * Get the list of system properties with options. + */ + Iterable listSystemProperties(String component); + + /*********************** Category ***********************/ + + /** + * Get the list of categories. + */ + Iterable listCategories(); + + /** + * Get the list of categories matching the given filter. + */ + Iterable listCategories(final Predicate filter); + + /** + * Get the first categories that matches the given filter or null if none is found. + */ + Category findCategory(final Predicate filter); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java new file mode 100644 index 0000000000..18e597cbb2 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java @@ -0,0 +1,111 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features.services; + +import java.util.List; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.internal.BaseCloudService; + +import com.google.common.base.Predicate; +import com.google.inject.ImplementedBy; + +/** + * Provides high level Abiquo cloud operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@ImplementedBy(BaseCloudService.class) +public interface CloudService +{ + /*********************** Virtual Datacenter ***********************/ + + /** + * Get the list of all virtual datacenters. + */ + Iterable listVirtualDatacenters(); + + /** + * Get the list of all virtual datacenters for a pair enterprise-datacenter. + * + * @param enterprise The given enterprise. + * @param datacenter The given datacenter. + */ + Iterable listVirtualDatacenters(final Enterprise enterprise); + + /** + * Get the list of virtual datacenters matching the given filter. + */ + Iterable listVirtualDatacenters(final Predicate filter); + + /** + * Get the first virtual datacenter that matches the given filter or null if none + * is found. + */ + VirtualDatacenter findVirtualDatacenter(final Predicate filter); + + /** + * Get the virtual datacenter with the given id. + */ + VirtualDatacenter getVirtualDatacenter(final Integer virtualDatacenterId); + + /** + * Get the list of virtual datacenter with the given ids. + */ + Iterable getVirtualDatacenters(final List virtualDatacenterIds); + + /*********************** Virtual Appliance ***********************/ + + /** + * Get the list of all virtual appliances. + */ + Iterable listVirtualAppliances(); + + /** + * Get the list of the virtual appliances matching the given filter. + */ + Iterable listVirtualAppliances(Predicate filter); + + /** + * Get the first virtual appliance that matches the given filter. + */ + VirtualAppliance findVirtualAppliance(Predicate filter); + + /*********************** Virtual Machine ***********************/ + + /** + * Get the list of all virtual machines. + */ + Iterable listVirtualMachines(); + + /** + * Get the list of the virtual machines matching the given filter. + */ + Iterable listVirtualMachines(Predicate filter); + + /** + * Get the first virtual machine that matches the given filter. + */ + VirtualMachine findVirtualMachine(Predicate filter); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/EventService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/EventService.java new file mode 100644 index 0000000000..cf25fc6130 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/EventService.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features.services; + +import org.jclouds.abiquo.domain.event.Event; +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.abiquo.internal.BaseEventService; + +import com.google.inject.ImplementedBy; + +/** + * Provides high level Abiquo event operations. + * + * @author Ignasi Barrera + * @author Vivien Mahé + */ +@ImplementedBy(BaseEventService.class) +public interface EventService +{ + /** + * Get the list of all events. + */ + Iterable listEvents(); + + /** + * Get the list of all events using filters as query params. + */ + Iterable listEvents(EventOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java new file mode 100644 index 0000000000..1706f39fde --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java @@ -0,0 +1,137 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features.services; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.events.handlers.AbstractEventHandler; +import org.jclouds.abiquo.internal.BaseMonitoringService; +import org.jclouds.abiquo.monitor.AsyncTaskMonitor; +import org.jclouds.abiquo.monitor.ConversionMonitor; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.abiquo.monitor.VirtualApplianceMonitor; +import org.jclouds.abiquo.monitor.VirtualMachineMonitor; + +import com.google.common.base.Function; +import com.google.inject.ImplementedBy; + +/** + * Utility service to monitor asynchronous operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@ImplementedBy(BaseMonitoringService.class) +public interface MonitoringService +{ + + /*************** Generic monitoring methods ***************/ + + /** + * Monitor the given objects using the given complete condition. + * + * @param completeCondition The function that will be used to decide if the asynchronous + * operations have finished. + * @param objects The objects to monitor. + */ + public void awaitCompletion(final Function completeCondition, + final T... objects); + + /** + * Monitor the given objects using the given complete condition. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param completeCondition The function that will be used to decide if the asynchronous + * operations have finished. + * @param objects The objects to monitor. + */ + public void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, + final Function completeCondition, final T... objects); + + /** + * Monitor the given objects using the given complete condition. + * + * @param completeCondition The function that will be used to decide if the asynchronous + * operations have finished. + * @param objects The objects to monitor. + */ + public void monitor(final Function completeCondition, final T... objects); + + /** + * Monitor the given objects using the given complete condition. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param completeCondition The function that will be used to decide if the asynchronous + * operations have finished. + * @param objects The objects to monitor. + */ + public void monitor(final Long maxWait, final TimeUnit timeUnit, + final Function completeCondition, final T... objects); + + /*************** Handler registration methods ***************/ + + /** + * Registers the given event handler. + * + * @param The type of event handler to register. + * @param handler The event handler to register. + */ + public > void register(T handler); + + /** + * Unregisters the given event handler. + * + * @param The type of event handler to unregister. + * @param handler The event handler to unregister. + */ + public > void unregister(T handler); + + /*************** Delegating monitors ***************/ + + /** + * Gets the virtual machine monitor service. + * + * @return The virtual machine monitor service. + */ + public VirtualMachineMonitor getVirtualMachineMonitor(); + + /** + * Gets the virtual appliance monitor service. + * + * @return The virtual appliance monitor service. + */ + public VirtualApplianceMonitor getVirtualApplianceMonitor(); + + /** + * Gets the asynchronous task monitor service. + * + * @return The asynchronous task monitor service. + */ + public AsyncTaskMonitor getAsyncTaskMonitor(); + + /** + * Gets the conversion monitor service. + * + * @return The conversion monitor service. + */ + public ConversionMonitor getConversionMonitor(); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java new file mode 100644 index 0000000000..442200787e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features.services; + +import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.internal.BasePricingService; + +import com.google.common.base.Predicate; +import com.google.inject.ImplementedBy; + +/** + * Provides high level Abiquo administration operations. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +@ImplementedBy(BasePricingService.class) +public interface PricingService +{ + + /*********************** Currency ***********************/ + + /** + * Get the list of currencies. + */ + Iterable listCurrencies(); + + /** + * Get the list of currencies matching the given filter. + */ + Iterable listCurrencies(final Predicate filter); + + /** + * Get the first currencies that matches the given filter or null if none is found. + */ + Currency findCurrency(final Predicate filter); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java new file mode 100644 index 0000000000..33b6df4eba --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java @@ -0,0 +1,143 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features.services; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.Volume; +import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.options.EnterpriseOptions; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.LogicServer; +import org.jclouds.abiquo.domain.infrastructure.ManagedRack; +import org.jclouds.abiquo.domain.infrastructure.StorageDevice; +import org.jclouds.abiquo.domain.infrastructure.StoragePool; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.domain.options.search.FilterOptions; +import org.jclouds.abiquo.internal.BaseSearchService; + +import com.google.inject.ImplementedBy; + +/** + * Provides high level Abiquo search, filter and pagination operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@ImplementedBy(BaseSearchService.class) +public interface SearchService +{ + /*********************** Enterprise ***********************/ + + /** + * Get the list of filtered enterprises. + * + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchEnterprises(final EnterpriseOptions options); + + /** + * Get the list of filtered enterprises for a datacenter. + * + * @param datacenter The given datacenter. + * @param options The set of filtering and pagination options of the search. + * @see API: http://community.abiquo.com/display/ABI20/Datacenter+Resource#DatacenterResource- + * Retrievealistofenterprisesusingdatacenter + */ + Iterable searchEnterprisesUsingDatacenter(final Datacenter datacenter, + final EnterpriseOptions options); + + /*********************** Volume ***********************/ + + /** + * Get the list of filtered volumes for a virtual datacenter. + * + * @param virtualDatacenter The given virtual datacenter. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchVolumes(final VirtualDatacenter virtualDatacenter, + final VolumeOptions options); + + /*********************** Storage Pool ***********************/ + + /** + * Get the list of filtered storage pools for a storage device. + * + * @param device The given storage device. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchStoragePools(final StorageDevice device, + final StoragePoolOptions options); + + /*********************** Private IPs ***********************/ + + /** + * Get the list of filtered ips for a private network. + * + * @param network The given private network. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchPrivateIps(final PrivateNetwork network, final IpOptions options); + + /*********************** Public IPs ***********************/ + + /** + * Get the list of filtered public ips to purchase by a virtual datacenter. + * + * @param virtualDatacenter The given virtual datacenter. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchPublicIpsToPurchase(final VirtualDatacenter virtualDatacenter, + final IpOptions options); + + /** + * Get the list of filtered purchased public ips by a virtual datacenter. + * + * @param virtualDatacenter The given virtual datacenter. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchPurchasedPublicIps(final VirtualDatacenter virtualDatacenter, + final IpOptions options); + + /*********************** Logic Server ***********************/ + + /** + * Get the list of service profiles for managed rack. + * + * @param managedRack The given rack. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchServiceProfiles(final ManagedRack rack, final FilterOptions options); + + /** + * Get the list of service profile templates for managed rack. + * + * @param managedRack The given rack. + * @param options The set of filtering and pagination options of the search. + */ + Iterable searchServiceProfileTemplates(final ManagedRack rack, + final FilterOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeType.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeType.java new file mode 100644 index 0000000000..e611341f36 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeType.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.rest.annotations.ApiVersion; + +import com.google.common.base.Function; + +/** + * Appends the Api version to the given mime type. + * + * @author Ignasi Barrera + */ +@Singleton +public class AppendApiVersionToAbiquoMimeType implements Function +{ + /** The prefix for Abiquo custom media types. */ + private static final String ABIQUO_MIME_TYPE_PREFIX = "application/vnd.abiquo."; + + /** The version to append to media types without version. */ + protected String apiVersion; + + @Inject + public AppendApiVersionToAbiquoMimeType(@ApiVersion final String apiVersion) + { + super(); + this.apiVersion = checkNotNull(apiVersion, "apiVersion"); + } + + @Override + public String apply(final String input) + { + MediaType mediaType = MediaType.valueOf(checkNotNull(input, "input")); + if (isAbiquoMimeType(input) && !mediaType.getParameters().containsKey("version")) + { + return mediaType.toString() + ";version=" + apiVersion; + } + else + { + return mediaType.toString(); + } + } + + private static boolean isAbiquoMimeType(final String mimeType) + { + return mimeType.startsWith(ABIQUO_MIME_TYPE_PREFIX); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ParseErrors.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ParseErrors.java new file mode 100644 index 0000000000..52a31ff8fb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ParseErrors.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.transport.error.ErrorsDto; +import com.google.inject.TypeLiteral; + +/** + * Parses a errors object. + * + * @author Ignasi Barrera + */ +@Singleton +public class ParseErrors extends ParseXMLWithJAXB +{ + @Inject + public ParseErrors(final XMLParser xml, final TypeLiteral type) + { + super(xml, type); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xx.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xx.java new file mode 100644 index 0000000000..c755d03b9b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xx.java @@ -0,0 +1,63 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * Return an Abiquo Exception on not found errors. + * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnAbiquoExceptionOnNotFoundOr4xx implements Function +{ + @Override + public Object apply(final Exception from) + { + Throwable exception = + Iterables.find(Throwables.getCausalChain(from), isNotFoundAndHasAbiquoException(from), + null); + + throw Throwables.propagate(exception == null ? from : (AbiquoException) exception + .getCause()); + } + + private static Predicate isNotFoundAndHasAbiquoException(final Throwable exception) + { + return new Predicate() + { + @Override + public boolean apply(final Throwable input) + { + return input instanceof ResourceNotFoundException + && input.getCause() instanceof AbiquoException; + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailable.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailable.java new file mode 100644 index 0000000000..b1babe8543 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailable.java @@ -0,0 +1,87 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * Return false on service error exceptions. + * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnFalseIfNotAvailable implements Function +{ + @Override + public Object apply(final Exception from) + { + Throwable exception = + Iterables.find(Throwables.getCausalChain(from), isNotAvailableException(from), null); + + if (exception != null) + { + if (exception instanceof HttpResponseException) + { + HttpResponseException responseException = (HttpResponseException) exception; + HttpResponse response = responseException.getResponse(); + + if (response != null && response.getStatusCode() >= 500 + && response.getStatusCode() < 600) + { + return false; + } + } + else + { + // Will enter here when exception is a ResourceNotFoundException + return false; + } + } + + throw Throwables.propagate(from); + } + + private static Predicate isNotAvailableException(final Throwable exception) + { + return new Predicate() + { + @Override + public boolean apply(final Throwable input) + { + boolean notAvailable = + input instanceof HttpResponseException + && ((HttpResponseException) input).getResponse() != null; + + notAvailable |= input instanceof ResourceNotFoundException; + + return notAvailable; + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseOn5xx.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseOn5xx.java new file mode 100644 index 0000000000..150b8c45bd --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnFalseOn5xx.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * Return false on service error exceptions. + * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnFalseOn5xx implements Function +{ + @Override + public Object apply(final Exception from) + { + Throwable exception = + Iterables.find(Throwables.getCausalChain(from), hasResponse(from), null); + + if (exception != null) + { + HttpResponseException responseException = (HttpResponseException) exception; + HttpResponse response = responseException.getResponse(); + + if (response != null && response.getStatusCode() >= 500 + && response.getStatusCode() < 600) + { + return false; + } + } + + throw Throwables.propagate(from); + } + + private static Predicate hasResponse(final Throwable exception) + { + return new Predicate() + { + @Override + public boolean apply(final Throwable input) + { + return input instanceof HttpResponseException + && ((HttpResponseException) input).getResponse() != null; + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnMovedResource.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnMovedResource.java new file mode 100644 index 0000000000..ec2bc2421b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnMovedResource.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * Return false on service error exceptions. + * + * @author Ignasi Barrera + */ +public abstract class ReturnMovedResource implements Function +{ + + @Override + public T apply(final Exception from) + { + Throwable exception = + Iterables.find(Throwables.getCausalChain(from), isMovedException(from), null); + + if (exception != null) + { + HttpResponseException responseException = (HttpResponseException) exception; + HttpResponse response = responseException.getResponse(); + + return getMovedEntity(response); + } + + throw Throwables.propagate(from); + } + + protected abstract T getMovedEntity(HttpResponse response); + + private static Predicate isMovedException(final Throwable exception) + { + return new Predicate() + { + @Override + public boolean apply(final Throwable input) + { + if (input instanceof HttpResponseException) + { + HttpResponse response = ((HttpResponseException) input).getResponse(); + return response != null + && response.getStatusCode() == Status.MOVED_PERMANENTLY.getStatusCode(); + } + + return false; + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnNullOn303.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnNullOn303.java new file mode 100644 index 0000000000..630d6f3067 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnNullOn303.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import javax.inject.Singleton; +import javax.ws.rs.core.Response.Status; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * Return null on 303 response codes when requesting a task. + * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnNullOn303 implements Function +{ + @Override + public Object apply(final Exception from) + { + Throwable exception = + Iterables.find(Throwables.getCausalChain(from), hasResponse(from), null); + + if (exception != null) + { + HttpResponseException responseException = (HttpResponseException) exception; + HttpResponse response = responseException.getResponse(); + + if (response != null && response.getStatusCode() == Status.SEE_OTHER.getStatusCode()) + { + return null; + } + } + + throw Throwables.propagate(from); + } + + private static Predicate hasResponse(final Throwable exception) + { + return new Predicate() + { + @Override + public boolean apply(final Throwable input) + { + return input instanceof HttpResponseException + && ((HttpResponseException) input).getResponse() != null; + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNull.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNull.java new file mode 100644 index 0000000000..ee5c8bf5b1 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNull.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.jclouds.http.HttpUtils.releasePayload; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.ws.rs.core.Response.Status; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.transport.AcceptedRequestDto; +import com.google.inject.TypeLiteral; + +/** + * Return an {@link AcceptedRequestDto} representing the asynchronous task or null if + * the operation completed synchronously. + *

+ * Operations that generate asynchronous tasks will return one of the following: + *

    + *
  • 204 if the operation completed synchronously
  • + *
  • 202 with the asynchronous task reference in the body if the operation has been submitted and + * will be executed asynchronously
  • + *
+ * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnTaskReferenceOrNull extends ParseXMLWithJAXB> +{ + @Inject + public ReturnTaskReferenceOrNull(final XMLParser xml, + final TypeLiteral> type) + { + super(xml, type); + } + + @Override + public AcceptedRequestDto apply(final HttpResponse from) + { + if (from.getStatusCode() == Status.NO_CONTENT.getStatusCode()) + { + releasePayload(from); + return null; + } + else + { + return super.apply(from); + } + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMoveVolumeReference.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMoveVolumeReference.java new file mode 100644 index 0000000000..41fb84b958 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMoveVolumeReference.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.cloud; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.xml.XMLParser; + +import com.abiquo.server.core.infrastructure.storage.MovedVolumeDto; +import com.google.inject.TypeLiteral; + +/** + * Return an {@link MovedVolumeDto} representing the reference to a moved resource. + * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnMoveVolumeReference extends ParseXMLWithJAXB +{ + @Inject + public ReturnMoveVolumeReference(final XMLParser xml, final TypeLiteral type) + { + super(xml, type); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolume.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolume.java new file mode 100644 index 0000000000..78ed3f1e07 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolume.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.cloud; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.functions.ReturnMovedResource; +import org.jclouds.http.HttpResponse; + +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Return false on service error exceptions. + * + * @author Ignasi Barrera + */ +@Singleton +public class ReturnMovedVolume extends ReturnMovedResource +{ + private ReturnMoveVolumeReference parser; + + @Inject + public ReturnMovedVolume(final ReturnMoveVolumeReference parser) + { + super(); + this.parser = parser; + } + + @Override + protected VolumeManagementDto getMovedEntity(final HttpResponse response) + { + return parser.apply(response).getVolume(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseId.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseId.java new file mode 100644 index 0000000000..ca00e58b36 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseId.java @@ -0,0 +1,47 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.enterprise; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.google.common.base.Function; + +/** + * Parses a {@link EnterpriseDto} object to extract its id. + * + * @author Francesc Montserrat + */ +@Singleton +public class ParseEnterpriseId implements Function +{ + @Override + public String apply(final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof EnterpriseDto, + "This parser is only valid for EnterpriseDto objects"); + + return ((EnterpriseDto) input).getId().toString(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterId.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterId.java new file mode 100644 index 0000000000..423575565c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterId.java @@ -0,0 +1,47 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.infrastructure; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.google.common.base.Function; + +/** + * Parses a {@link DatacenterDto} object to extract its id. + * + * @author Francesc Montserrat + */ +@Singleton +public class ParseDatacenterId implements Function +{ + @Override + public String apply(final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof DatacenterDto, + "This parser is only valid for DatacenterDto objects"); + + return ((DatacenterDto) input).getId().toString(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineId.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineId.java new file mode 100644 index 0000000000..54d1ef693e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineId.java @@ -0,0 +1,47 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.infrastructure; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import com.abiquo.server.core.infrastructure.MachineDto; +import com.google.common.base.Function; + +/** + * Parses a {@link MachineDto} object to extract its id. + * + * @author Ignasi Barrera + */ +@Singleton +public class ParseMachineId implements Function +{ + @Override + public String apply(final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof MachineDto, + "This parser is only valid for MachineDto objects"); + + return ((MachineDto) input).getId().toString(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceType.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceType.java new file mode 100644 index 0000000000..c30891c3c9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceType.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.infrastructure; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import com.abiquo.model.enumerator.RemoteServiceType; +import com.google.common.base.Function; + +/** + * Parses a {@link ParseRemoteServiceType} object to extract its type in the format that the API + * expects it. + * + * @author Francesc Montserrat + */ +@Singleton +public class ParseRemoteServiceType implements Function +{ + @Override + public String apply(final Object input) + { + checkArgument(checkNotNull(input, "input") instanceof RemoteServiceType, + "This parser is only valid for RemoteServiceType objects"); + + return ((RemoteServiceType) input).name().replaceAll("_", "").toLowerCase(); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/handlers/AbiquoErrorHandler.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/handlers/AbiquoErrorHandler.java new file mode 100644 index 0000000000..22aa74676f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/handlers/AbiquoErrorHandler.java @@ -0,0 +1,137 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.handlers; + +import static javax.ws.rs.core.Response.Status.fromStatusCode; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.functions.ParseErrors; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ResourceNotFoundException; + +import com.abiquo.model.transport.error.ErrorsDto; +import com.google.common.io.Closeables; + +/** + * Parse Abiquo API errors and set the appropriate exception. + * + * @author Ignasi Barrera + */ +@Singleton +public class AbiquoErrorHandler implements HttpErrorHandler +{ + /** The error parser. */ + private ParseErrors errorParser; + + @Inject + AbiquoErrorHandler(final ParseErrors errorParser) + { + super(); + this.errorParser = errorParser; + } + + @Override + public void handleError(final HttpCommand command, final HttpResponse response) + { + Exception exception = null; + String defaultMessage = + String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), + response.getStatusLine()); + + try + { + switch (response.getStatusCode()) + { + case 401: + case 403: + // Autorization exceptions do not return an errors DTO, so we encapsulate a + // generic exception + exception = + new AuthorizationException(defaultMessage, + new HttpResponseException(command, response, defaultMessage)); + break; + case 404: + exception = + new ResourceNotFoundException(defaultMessage, getExceptionToPropagate( + command, response, defaultMessage)); + break; + case 301: + // Moved resources in Abiquo should be handled with the ReturnMovedResource + // exception parser to return the moved entity. + exception = new HttpResponseException(command, response, defaultMessage); + break; + default: + exception = getExceptionToPropagate(command, response, defaultMessage); + break; + } + } + finally + { + if (response.getPayload() != null) + { + Closeables.closeQuietly(response.getPayload().getInput()); + } + command.setException(exception); + } + } + + private Exception getExceptionToPropagate(final HttpCommand command, + final HttpResponse response, final String defaultMessage) + { + Exception exception = null; + + if (hasPayload(response)) + { + try + { + ErrorsDto errors = errorParser.apply(response); + exception = new AbiquoException(fromStatusCode(response.getStatusCode()), errors); + } + catch (Exception ex) + { + // If it is not an Abiquo Exception (can not be unmarshalled), propagate a standard + // HttpResponseException + exception = new HttpResponseException(command, response, defaultMessage); + } + } + else + { + // If it is not an Abiquo Exception (there is not an errors xml in the payload) + // propagate a standard HttpResponseException + exception = new HttpResponseException(command, response, defaultMessage); + } + + return exception; + } + + private static boolean hasPayload(final HttpResponse response) + { + return response.getPayload() != null && response.getPayload().getContentMetadata() != null + && response.getPayload().getContentMetadata().getContentLength() != null + && response.getPayload().getContentMetadata().getContentLength() > 0L; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java new file mode 100644 index 0000000000..4be0049037 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java @@ -0,0 +1,100 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.http.filters; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.reference.AbiquoConstants.CREDENTIAL_IS_TOKEN; + +import java.io.UnsupportedEncodingException; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.HttpException; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.rest.annotations.Credential; +import org.jclouds.rest.annotations.Identity; + +import com.google.common.annotations.VisibleForTesting; + +/** + * Authenticates using Basic Authentication or a generated token from previous API sessions. + * + * @author Ignasi Barrera + */ +@Singleton +public class AbiquoAuthentication implements HttpRequestFilter +{ + /** The name of the authentication token. */ + public static final String AUTH_TOKEN_NAME = "auth"; + + protected String identity; + + protected String credential; + + protected boolean credentialIsToken; + + @Inject + public AbiquoAuthentication(@Identity final String identity, + @Credential final String credential, + @Named(CREDENTIAL_IS_TOKEN) final String credentialIsToken) + { + this.identity = checkNotNull(identity, "identity"); + this.credential = checkNotNull(credential, "credential"); + this.credentialIsToken = Boolean.valueOf(credentialIsToken); + } + + @Override + public HttpRequest filter(final HttpRequest request) throws HttpException + { + try + { + String header = + credentialIsToken ? tokenAuth(credential) : basicAuth(identity, credential); + return request + .toBuilder() + .replaceHeader(credentialIsToken ? HttpHeaders.COOKIE : HttpHeaders.AUTHORIZATION, + header).build(); + } + catch (UnsupportedEncodingException ex) + { + throw new HttpException(ex); + } + } + + @VisibleForTesting + static String basicAuth(final String user, final String password) + throws UnsupportedEncodingException + { + return "Basic " + + CryptoStreams.base64(String.format("%s:%s", checkNotNull(user, "user"), + checkNotNull(password, "password")).getBytes("UTF-8")); + } + + @VisibleForTesting + static String tokenAuth(final String token) + { + return AUTH_TOKEN_NAME + "=" + checkNotNull(token, "token"); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaType.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaType.java new file mode 100644 index 0000000000..6a6ba06c59 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaType.java @@ -0,0 +1,85 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.http.filters; + +import java.util.Collection; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.functions.AppendApiVersionToAbiquoMimeType; +import org.jclouds.http.HttpException; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.Iterables; +import com.google.common.net.HttpHeaders; + +/** + * Appends the api version to the Abiquo mime types to ensure the input and output of api calls will + * be in the desired format. + * + * @author Ignasi Barrera + */ +@Singleton +public class AppendApiVersionToMediaType implements HttpRequestFilter +{ + /** The function used to append the version to media types. */ + private AppendApiVersionToAbiquoMimeType versionAppender; + + @Inject + public AppendApiVersionToMediaType(final AppendApiVersionToAbiquoMimeType versionAppender) + { + super(); + this.versionAppender = versionAppender; + } + + @Override + public HttpRequest filter(final HttpRequest request) throws HttpException + { + HttpRequest requestWithVersionInMediaTypes = appendVersionToNonPayloadHeaders(request); + return appendVersionToPayloadHeaders(requestWithVersionInMediaTypes); + } + + @VisibleForTesting + HttpRequest appendVersionToNonPayloadHeaders(final HttpRequest request) + { + Collection accept = request.getHeaders().get(HttpHeaders.ACCEPT); + return accept.isEmpty() ? request : request + .toBuilder() + .replaceHeader(HttpHeaders.ACCEPT, + Iterables.toArray(Iterables.transform(accept, versionAppender), String.class)) + .build(); + } + + @VisibleForTesting + HttpRequest appendVersionToPayloadHeaders(final HttpRequest request) + { + if (request.getPayload() != null) + { + String contentTypeWithVersion = + versionAppender.apply(request.getPayload().getContentMetadata().getContentType()); + request.getPayload().getContentMetadata().setContentType(contentTypeWithVersion); + } + + return request; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java new file mode 100644 index 0000000000..837bb84b3b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java @@ -0,0 +1,125 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.Context; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.abiquo.features.services.AdministrationService; +import org.jclouds.abiquo.features.services.CloudService; +import org.jclouds.abiquo.features.services.EventService; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.features.services.PricingService; +import org.jclouds.abiquo.features.services.SearchService; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.Utils; +import org.jclouds.compute.internal.ComputeServiceContextImpl; +import org.jclouds.location.Provider; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; + +import com.google.common.reflect.TypeToken; + +/** + * Abiquo {@link RestContextImpl} implementation to expose high level Abiquo functionalities. + * + * @author Ignasi Barrera + */ +@Singleton +public class AbiquoContextImpl extends ComputeServiceContextImpl implements AbiquoContext +{ + private final AdministrationService administrationService; + + private final CloudService cloudService; + + private final SearchService searchService; + + private final MonitoringService monitoringService; + + private final EventService eventService; + + private final PricingService pricingService; + + @Inject + public AbiquoContextImpl(@Provider final Context wrapped, + @Provider final TypeToken< ? extends Context> wrappedType, + final ComputeService computeService, final Utils utils, + final RestContext providerSpecificContext, + final AdministrationService administrationService, final CloudService cloudService, + final SearchService searchService, final MonitoringService monitoringService, + final EventService eventService, final PricingService pricingService) + { + super(wrapped, wrappedType, computeService, utils); + this.administrationService = checkNotNull(administrationService, "administrationService"); + this.cloudService = checkNotNull(cloudService, "cloudService"); + this.searchService = checkNotNull(searchService, "searchService"); + this.monitoringService = checkNotNull(monitoringService, "monitoringService"); + this.eventService = checkNotNull(eventService, "eventService"); + this.pricingService = checkNotNull(pricingService, "pricingService"); + } + + @Override + public RestContext getApiContext() + { + return unwrap(); + } + + @Override + public AdministrationService getAdministrationService() + { + return administrationService; + } + + @Override + public CloudService getCloudService() + { + return cloudService; + } + + @Override + public SearchService getSearchService() + { + return searchService; + } + + @Override + public MonitoringService getMonitoringService() + { + return monitoringService; + } + + @Override + public EventService getEventService() + { + return eventService; + } + + @Override + public PricingService getPricingService() + { + return pricingService; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java new file mode 100644 index 0000000000..144efa4e81 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java @@ -0,0 +1,364 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.domain.config.License; +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.domain.config.SystemProperty; +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.EnterpriseProperties; +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.features.services.AdministrationService; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.strategy.admin.ListRoles; +import org.jclouds.abiquo.strategy.config.ListCategories; +import org.jclouds.abiquo.strategy.config.ListLicenses; +import org.jclouds.abiquo.strategy.config.ListPrivileges; +import org.jclouds.abiquo.strategy.config.ListProperties; +import org.jclouds.abiquo.strategy.enterprise.ListEnterprises; +import org.jclouds.abiquo.strategy.infrastructure.ListDatacenters; +import org.jclouds.abiquo.strategy.infrastructure.ListMachines; +import org.jclouds.collect.Memoized; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; + +/** + * Provides high level Abiquo administration operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class BaseAdministrationService implements AdministrationService +{ + @VisibleForTesting + protected RestContext context; + + @VisibleForTesting + protected final ListDatacenters listDatacenters; + + @VisibleForTesting + protected final ListMachines listMachines; + + @VisibleForTesting + protected final ListEnterprises listEnterprises; + + @VisibleForTesting + protected final ListRoles listRoles; + + @VisibleForTesting + protected final ListLicenses listLicenses; + + @VisibleForTesting + protected final ListPrivileges listPrivileges; + + @VisibleForTesting + protected final ListProperties listProperties; + + @VisibleForTesting + protected final ListCategories listCategories; + + @VisibleForTesting + protected final Supplier currentUser; + + @VisibleForTesting + protected final Supplier currentEnterprise; + + @Inject + protected BaseAdministrationService(final RestContext context, + final ListDatacenters listDatacenters, final ListMachines listMachines, + final ListEnterprises listEnterprises, final ListRoles listRoles, + final ListLicenses listLicenses, final ListPrivileges listPrivileges, + final ListProperties listProperties, final ListCategories listCategories, + @Memoized final Supplier currentUser, + @Memoized final Supplier currentEnterprise) + { + this.context = checkNotNull(context, "context"); + this.listDatacenters = checkNotNull(listDatacenters, "listDatacenters"); + this.listMachines = checkNotNull(listMachines, "listMachines"); + this.listEnterprises = checkNotNull(listEnterprises, "listEnterprises"); + this.listRoles = checkNotNull(listRoles, "listRoles"); + this.listLicenses = checkNotNull(listLicenses, "listLicenses"); + this.listPrivileges = checkNotNull(listPrivileges, "listPrivileges"); + this.listProperties = checkNotNull(listProperties, "listProperties"); + this.listCategories = checkNotNull(listCategories, "listCategories"); + this.currentUser = checkNotNull(currentUser, "currentUser"); + this.currentEnterprise = checkNotNull(currentEnterprise, "currentEnterprise"); + } + + /*********************** Datacenter ********************** */ + + @Override + public Iterable listDatacenters() + { + return listDatacenters.execute(); + } + + @Override + public Iterable listDatacenters(final Predicate filter) + { + return listDatacenters.execute(filter); + } + + @Override + public Datacenter getDatacenter(final Integer datacenterId) + { + DatacenterDto datacenter = + context.getApi().getInfrastructureApi().getDatacenter(datacenterId); + return wrap(context, Datacenter.class, datacenter); + } + + @Override + public Datacenter findDatacenter(final Predicate filter) + { + return Iterables.getFirst(listDatacenters(filter), null); + } + + @Override + public Iterable getDatacenters(final List datacenterIds) + { + return listDatacenters.execute(datacenterIds); + } + + /*********************** Machine ***********************/ + + @Override + public Iterable listMachines() + { + return listMachines.execute(); + } + + @Override + public Iterable listMachines(final Predicate filter) + { + return listMachines.execute(filter); + } + + @Override + public Machine findMachine(final Predicate filter) + { + return Iterables.getFirst(listMachines(filter), null); + } + + /*********************** Enterprise ***********************/ + + @Override + public Iterable listEnterprises() + { + return listEnterprises.execute(); + } + + @Override + public Iterable listEnterprises(final Predicate filter) + { + return listEnterprises.execute(filter); + } + + @Override + public Enterprise findEnterprise(final Predicate filter) + { + return Iterables.getFirst(listEnterprises(filter), null); + } + + @Override + public Enterprise getEnterprise(final Integer enterpriseId) + { + EnterpriseDto enterprise = + context.getApi().getEnterpriseApi().getEnterprise(enterpriseId); + return wrap(context, Enterprise.class, enterprise); + } + + /*********************** Enterprise Properties ***********************/ + + @Override + public EnterpriseProperties getEnterpriseProperties(final Enterprise enterprise) + { + checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + Enterprise.class); + + EnterprisePropertiesDto properties = + context.getApi().getEnterpriseApi().getEnterpriseProperties(enterprise.unwrap()); + return wrap(context, EnterpriseProperties.class, properties); + } + + /*********************** Role ********************** */ + + @Override + public Iterable listRoles() + { + return listRoles.execute(); + } + + @Override + public Iterable listRoles(final Predicate filter) + { + return listRoles.execute(filter); + } + + @Override + public Role findRole(final Predicate filter) + { + return Iterables.getFirst(listRoles(filter), null); + } + + @Override + public Role getRole(final Integer roleId) + { + RoleDto role = context.getApi().getAdminApi().getRole(roleId); + return wrap(context, Role.class, role); + } + + /*********************** Privilege ***********************/ + + @Override + public Privilege findPrivilege(final Predicate filter) + { + return Iterables.getFirst(listPrivileges(filter), null); + } + + @Override + public Iterable listPrivileges() + { + return listPrivileges.execute(); + } + + @Override + public Iterable listPrivileges(final Predicate filter) + { + return listPrivileges.execute(filter); + } + + /*********************** User ***********************/ + + @Override + public User getCurrentUser() + { + return currentUser.get(); + } + + @Override + public Enterprise getCurrentEnterprise() + { + return currentEnterprise.get(); + } + + /*********************** License ***********************/ + + @Override + public Iterable listLicenses() + { + return listLicenses.execute(); + } + + @Override + public Iterable listLicenses(final boolean active) + { + LicenseOptions options = LicenseOptions.builder().active(active).build(); + return listLicenses.execute(options); + } + + @Override + public Iterable listLicenses(final Predicate filter) + { + return listLicenses.execute(filter); + } + + @Override + public License findLicense(final Predicate filter) + { + return Iterables.getFirst(listLicenses(filter), null); + } + + /*********************** System Properties ***********************/ + + @Override + public Iterable listSystemProperties() + { + return listProperties.execute(); + } + + @Override + public Iterable listSystemProperties(final Predicate filter) + { + return listProperties.execute(filter); + } + + @Override + public SystemProperty findSystemProperty(final Predicate filter) + { + return Iterables.getFirst(listSystemProperties(filter), null); + } + + @Override + public SystemProperty getSystemProperty(final String name) + { + PropertyOptions options = PropertyOptions.builder().name(name).build(); + return Iterables.getFirst(listProperties.execute(options), null); + } + + @Override + public Iterable listSystemProperties(final String component) + { + PropertyOptions options = PropertyOptions.builder().component(component).build(); + return listProperties.execute(options); + } + + @Override + public Category findCategory(final Predicate filter) + { + return Iterables.getFirst(listCategories(filter), null); + } + + @Override + public Iterable listCategories() + { + return listCategories.execute(); + } + + @Override + public Iterable listCategories(final Predicate filter) + { + return listCategories.execute(filter); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java new file mode 100644 index 0000000000..b3ba3136b9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java @@ -0,0 +1,171 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.features.services.CloudService; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.strategy.cloud.ListVirtualAppliances; +import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters; +import org.jclouds.abiquo.strategy.cloud.ListVirtualMachines; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +/** + * Provides high level Abiquo cloud operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class BaseCloudService implements CloudService +{ + @VisibleForTesting + protected RestContext context; + + @VisibleForTesting + protected final ListVirtualDatacenters listVirtualDatacenters; + + @VisibleForTesting + protected ListVirtualAppliances listVirtualAppliances; + + @VisibleForTesting + protected ListVirtualMachines listVirtualMachines; + + @Inject + protected BaseCloudService(final RestContext context, + final ListVirtualDatacenters listVirtualDatacenters, + final ListVirtualAppliances listVirtualAppliances, + final ListVirtualMachines listVirtualMachines) + { + this.context = checkNotNull(context, "context"); + this.listVirtualDatacenters = + checkNotNull(listVirtualDatacenters, "listVirtualDatacenters"); + this.listVirtualAppliances = checkNotNull(listVirtualAppliances, "listVirtualAppliances"); + this.listVirtualMachines = checkNotNull(listVirtualMachines, "listVirtualMachines"); + } + + /*********************** Virtual Datacenter ********************** */ + + @Override + public Iterable listVirtualDatacenters() + { + return listVirtualDatacenters.execute(); + } + + @Override + public Iterable listVirtualDatacenters(final Enterprise enterprise) + { + checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); + checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + + Enterprise.class); + + VirtualDatacenterOptions options = + VirtualDatacenterOptions.builder().enterpriseId(enterprise.getId()).build(); + + return listVirtualDatacenters.execute(options); + } + + @Override + public Iterable listVirtualDatacenters( + final Predicate filter) + { + return listVirtualDatacenters.execute(filter); + } + + @Override + public VirtualDatacenter getVirtualDatacenter(final Integer virtualDatacenterId) + { + VirtualDatacenterDto virtualDatacenter = + context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); + return wrap(context, VirtualDatacenter.class, virtualDatacenter); + } + + @Override + public Iterable getVirtualDatacenters( + final List virtualDatacenterIds) + { + return listVirtualDatacenters.execute(virtualDatacenterIds); + } + + @Override + public VirtualDatacenter findVirtualDatacenter(final Predicate filter) + { + return Iterables.getFirst(listVirtualDatacenters(filter), null); + } + + /*********************** Virtual Appliance ********************** */ + + @Override + public Iterable listVirtualAppliances() + { + return listVirtualAppliances.execute(); + } + + @Override + public Iterable listVirtualAppliances(final Predicate filter) + { + return listVirtualAppliances.execute(filter); + } + + @Override + public VirtualAppliance findVirtualAppliance(final Predicate filter) + { + return Iterables.getFirst(listVirtualAppliances(filter), null); + } + + /*********************** Virtual Machine ********************** */ + + @Override + public Iterable listVirtualMachines() + { + return listVirtualMachines.execute(); + } + + @Override + public Iterable listVirtualMachines(final Predicate filter) + { + return listVirtualMachines.execute(filter); + } + + @Override + public VirtualMachine findVirtualMachine(final Predicate filter) + { + return Iterables.getFirst(listVirtualMachines(filter), null); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseEventService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseEventService.java new file mode 100644 index 0000000000..2447cf5d65 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseEventService.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.event.Event; +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.abiquo.features.services.EventService; +import org.jclouds.abiquo.strategy.event.ListEvents; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.VisibleForTesting; + +/** + * Provides high level Abiquo event operations. + * + * @author Ignasi Barrera + * @author Vivien Mahé + */ +@Singleton +public class BaseEventService implements EventService +{ + @VisibleForTesting + protected RestContext context; + + @VisibleForTesting + protected final ListEvents listEvents; + + @Inject + protected BaseEventService(final RestContext context, + final ListEvents listEvents) + { + this.context = checkNotNull(context, "context"); + this.listEvents = checkNotNull(listEvents, "listEvents"); + } + + @Override + public Iterable listEvents() + { + return listEvents.execute(); + } + + @Override + public Iterable listEvents(final EventOptions options) + { + return listEvents.execute(options); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java new file mode 100644 index 0000000000..cd38b8e64f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java @@ -0,0 +1,335 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; + +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.events.handlers.AbstractEventHandler; +import org.jclouds.abiquo.events.handlers.BlockingEventHandler; +import org.jclouds.abiquo.events.monitor.CompletedEvent; +import org.jclouds.abiquo.events.monitor.FailedEvent; +import org.jclouds.abiquo.events.monitor.TimeoutEvent; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.AsyncTaskMonitor; +import org.jclouds.abiquo.monitor.ConversionMonitor; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.abiquo.monitor.VirtualApplianceMonitor; +import org.jclouds.abiquo.monitor.VirtualMachineMonitor; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; +import com.google.common.eventbus.EventBus; +import com.google.inject.Inject; + +/** + * Utility service to monitor asynchronous operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class BaseMonitoringService implements MonitoringService +{ + @VisibleForTesting + protected RestContext context; + + /** The scheduler used to perform monitoring tasks. */ + @VisibleForTesting + protected ScheduledExecutorService scheduler; + + @VisibleForTesting + protected Long pollingDelay; + + /** + * The event bus used to dispatch monitoring events. + *

+ * A sync bus is used by default, to prevent deadlocks when using the + * {@link BlockingEventHandler}. + */ + @VisibleForTesting + protected EventBus eventBus; + + @Resource + private Logger logger = Logger.NULL; + + @Inject + public BaseMonitoringService(final RestContext context, + @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, + @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus) + { + this.context = checkNotNull(context, "context"); + this.scheduler = checkNotNull(scheduler, "scheduler"); + this.pollingDelay = checkNotNull(pollingDelay, "pollingDelay"); + this.eventBus = checkNotNull(eventBus, "eventBus"); + } + + /*************** Generic monitoring methods ***************/ + + @Override + public void awaitCompletion(final Function completeCondition, + final T... objects) + { + awaitCompletion(null, null, completeCondition, objects); + } + + @Override + public void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, + final Function completeCondition, final T... objects) + { + checkNotNull(completeCondition, "completeCondition"); + + if (objects != null && objects.length > 0) + { + BlockingEventHandler blockingHandler = new BlockingEventHandler(logger, objects); + register(blockingHandler); + + monitor(maxWait, timeUnit, completeCondition, objects); + blockingHandler.lock(); + + unregister(blockingHandler); + } + } + + @Override + public void monitor(final Function completeCondition, final T... objects) + { + monitor(null, null, completeCondition, objects); + } + + @Override + public void monitor(final Long maxWait, final TimeUnit timeUnit, + final Function completeCondition, final T... objects) + { + checkNotNull(completeCondition, "completeCondition"); + if (maxWait != null) + { + checkNotNull(timeUnit, "timeUnit"); + } + + if (objects != null && objects.length > 0) + { + for (T object : objects) + { + AsyncMonitor monitor = new AsyncMonitor(object, completeCondition); + monitor.startMonitoring(maxWait); + } + } + } + + @Override + public > void register(final T handler) + { + logger.debug("registering event handler %s", handler); + eventBus.register(handler); + } + + @Override + public > void unregister(final T handler) + { + logger.debug("unregistering event handler %s", handler); + eventBus.unregister(handler); + } + + /*************** Delegating monitors ***************/ + + @Override + public VirtualMachineMonitor getVirtualMachineMonitor() + { + return checkNotNull( + context.getUtils().getInjector().getInstance(VirtualMachineMonitor.class), + "virtualMachineMonitor"); + } + + @Override + public VirtualApplianceMonitor getVirtualApplianceMonitor() + { + return checkNotNull( + context.getUtils().getInjector().getInstance(VirtualApplianceMonitor.class), + "virtualApplianceMonitor"); + } + + @Override + public AsyncTaskMonitor getAsyncTaskMonitor() + { + return checkNotNull(context.getUtils().getInjector().getInstance(AsyncTaskMonitor.class), + "asyncTaskMonitor"); + } + + @Override + public ConversionMonitor getConversionMonitor() + { + return checkNotNull(context.getUtils().getInjector().getInstance(ConversionMonitor.class), + "conversionMonitor"); + } + + /** + * Performs the periodical monitoring tasks. + * + * @author Ignasi Barrera + * @param The type of the object being monitored. + */ + @VisibleForTesting + class AsyncMonitor implements Runnable + { + /** The object being monitored. */ + private T monitoredObject; + + /** The function used to monitor the target object. */ + private Function completeCondition; + + /** + * The future representing the monitoring job. Needed to be able to cancel it when monitor + * finishes. + */ + private Future< ? > future; + + /** The timeout for this monitor. */ + private Long timeout; + + public AsyncMonitor(final T monitoredObject, + final Function completeCondition) + { + super(); + this.monitoredObject = checkNotNull(monitoredObject, "monitoredObject"); + this.completeCondition = checkNotNull(completeCondition, "completeCondition"); + } + + /** + * Starts the monitoring job with the given timeout. + * + * @param maxWait The timeout. + */ + public void startMonitoring(final Long maxWait) + { + future = + scheduler.scheduleWithFixedDelay(this, 0L, pollingDelay, TimeUnit.MILLISECONDS); + timeout = maxWait == null ? null : System.currentTimeMillis() + maxWait; + logger.debug("started monitor job for %s with %s timeout", monitoredObject, + timeout == null ? "no" : String.valueOf(timeout)); + } + + /** + * Stops the monitoring job, if running. + */ + public void stopMonitoring() + { + logger.debug("stopping monitor job for %s", monitoredObject); + + try + { + if (future != null && !future.isCancelled() && !future.isDone()) + { + // Do not force future cancel. Let it finish gracefully + logger.debug("cancelling future"); + future.cancel(false); + } + } + catch (Exception ex) + { + logger.warn(ex, "failed to stop monitor job for %s", monitoredObject); + } + } + + /** + * Checks if the monitor has timed out. + */ + public boolean isTimeout() + { + return timeout != null && timeout < System.currentTimeMillis(); + } + + @Override + public void run() + { + // Do not use Thread.interrupted() since it will clear the interrupted flag + // and subsequent calls to it may not return the appropriate value + if (Thread.currentThread().isInterrupted()) + { + // If the thread as already been interrupted, just stop monitoring the task and + // return + stopMonitoring(); + return; + } + + MonitorStatus status = completeCondition.apply(monitoredObject); + logger.debug("monitored object %s status %s", monitoredObject, status.name()); + + switch (status) + { + case DONE: + stopMonitoring(); + logger.debug("publishing COMPLETED event"); + eventBus.post(new CompletedEvent(monitoredObject)); + break; + case FAILED: + stopMonitoring(); + logger.debug("publishing FAILED event"); + eventBus.post(new FailedEvent(monitoredObject)); + break; + case CONTINUE: + default: + if (isTimeout()) + { + logger.warn("monitor for object %s timed out. Shutting down monitor.", + monitoredObject); + stopMonitoring(); + logger.debug("publishing TIMEOUT event"); + eventBus.post(new TimeoutEvent(monitoredObject)); + } + break; + } + } + + public T getMonitoredObject() + { + return monitoredObject; + } + + public Function getCompleteCondition() + { + return completeCondition; + } + + public Future< ? > getFuture() + { + return future; + } + + public Long getTimeout() + { + return timeout; + } + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java new file mode 100644 index 0000000000..c879374a7f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java @@ -0,0 +1,80 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.features.services.PricingService; +import org.jclouds.abiquo.strategy.config.ListCurrencies; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +/** + * Provides high level Abiquo administration operations. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +@Singleton +public class BasePricingService implements PricingService +{ + @VisibleForTesting + protected RestContext context; + + @VisibleForTesting + protected final ListCurrencies listCurrencies; + + @Inject + protected BasePricingService(final RestContext context, + final ListCurrencies listCurrencies) + { + this.context = checkNotNull(context, "context"); + this.listCurrencies = checkNotNull(listCurrencies, "listCurrencies"); + } + + /*********************** Currency ********************** */ + + @Override + public Iterable listCurrencies() + { + return listCurrencies.execute(); + } + + @Override + public Iterable listCurrencies(final Predicate filter) + { + return listCurrencies.execute(filter); + } + + @Override + public Currency findCurrency(final Predicate filter) + { + return Iterables.getFirst(listCurrencies(filter), null); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java new file mode 100644 index 0000000000..57d8c6694d --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java @@ -0,0 +1,182 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.Volume; +import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.options.EnterpriseOptions; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.LogicServer; +import org.jclouds.abiquo.domain.infrastructure.ManagedRack; +import org.jclouds.abiquo.domain.infrastructure.StorageDevice; +import org.jclouds.abiquo.domain.infrastructure.StoragePool; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.domain.options.search.FilterOptions; +import org.jclouds.abiquo.features.services.SearchService; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.google.common.annotations.VisibleForTesting; + +/** + * Provides high level Abiquo search, filter and pagination operations. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class BaseSearchService implements SearchService +{ + @VisibleForTesting + protected RestContext context; + + @Inject + protected BaseSearchService(final RestContext context) + { + this.context = checkNotNull(context, "context"); + } + + /*********************** Enterprise ***********************/ + + @Override + public Iterable searchEnterprises(final EnterpriseOptions options) + { + List enterprises = + context.getApi().getEnterpriseApi().listEnterprises(options).getCollection(); + + return wrap(context, Enterprise.class, enterprises); + } + + @Override + public Iterable searchEnterprisesUsingDatacenter(final Datacenter datacenter, + final EnterpriseOptions options) + { + List enterprises = + context.getApi().getEnterpriseApi().listEnterprises(datacenter.unwrap(), options) + .getCollection(); + + return wrap(context, Enterprise.class, enterprises); + } + + /*********************** Volume ********************** */ + + @Override + public Iterable searchVolumes(final VirtualDatacenter virtualDatacenter, + final VolumeOptions options) + { + List volumes = + context.getApi().getCloudApi().listVolumes(virtualDatacenter.unwrap(), options) + .getCollection(); + + return wrap(context, Volume.class, volumes); + } + + /*********************** Storage Pool ***********************/ + + @Override + public List searchStoragePools(final StorageDevice device, + final StoragePoolOptions options) + { + List pools = + context.getApi().getInfrastructureApi().listStoragePools(device.unwrap(), options) + .getCollection(); + + return wrap(context, StoragePool.class, pools); + } + + /*********************** Private Network ***********************/ + + @Override + public Iterable searchPrivateIps(final PrivateNetwork network, + final IpOptions options) + { + List ips = + context.getApi().getCloudApi().listPrivateNetworkIps(network.unwrap(), options) + .getCollection(); + + return wrap(context, PrivateIp.class, ips); + } + + @Override + public Iterable searchPublicIpsToPurchase(final VirtualDatacenter virtualDatacenter, + final IpOptions options) + { + List ips = + context.getApi().getCloudApi() + .listAvailablePublicIps(virtualDatacenter.unwrap(), options).getCollection(); + + return wrap(context, PublicIp.class, ips); + } + + @Override + public Iterable searchPurchasedPublicIps(final VirtualDatacenter virtualDatacenter, + final IpOptions options) + { + List ips = + context.getApi().getCloudApi() + .listPurchasedPublicIps(virtualDatacenter.unwrap(), options).getCollection(); + + return wrap(context, PublicIp.class, ips); + } + + @Override + public Iterable searchServiceProfiles(final ManagedRack rack, + final FilterOptions options) + { + List profiles = + context.getApi().getInfrastructureApi().listServiceProfiles(rack.unwrap(), options) + .getCollection(); + + return wrap(context, LogicServer.class, profiles); + } + + @Override + public Iterable searchServiceProfileTemplates(final ManagedRack rack, + final FilterOptions options) + { + List profiles = + context.getApi().getInfrastructureApi() + .listServiceProfileTemplates(rack.unwrap(), options).getCollection(); + + return wrap(context, LogicServer.class, profiles); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/AsyncTaskMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/AsyncTaskMonitor.java new file mode 100644 index 0000000000..d9b7c7fcff --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/AsyncTaskMonitor.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.internal.BaseAsyncTaskMonitor; + +import com.google.inject.ImplementedBy; + +/** + * {@link VirtualMachine} monitoring features. + * + * @author Ignasi Barrera + */ +@ImplementedBy(BaseAsyncTaskMonitor.class) +public interface AsyncTaskMonitor extends MonitoringService +{ + /** + * Monitor the given {@link AsyncTask}s and block until they finishe. + * + * @param tasks The {@link AsyncTask}s to monitor. + */ + void awaitCompletion(final AsyncTask... tasks); + + /** + * Monitor the given {@link AsyncTask}s and populate an event when they finish. + * + * @param tasks The {@link AsyncTask}s to monitor. + */ + public void monitor(final AsyncTask... tasks); + + /** + * Monitor the given {@link AsyncTask}s and block until they finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param tasks The {@link AsyncTask}s to monitor. + */ + void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, final AsyncTask... tasks); + + /** + * Monitor the given {@link AsyncTask}s and populate an event when they finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param tasks The {@link AsyncTask}s to monitor. + */ + public void monitor(final Long maxWait, final TimeUnit timeUnit, final AsyncTask... tasks); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java new file mode 100644 index 0000000000..5910cfe952 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.internal.BaseConversionMonitor; + +import com.google.inject.ImplementedBy; + +/** + * {@link Conversion} monitoring features. + * + * @author Sergi Castro + */ +@ImplementedBy(BaseConversionMonitor.class) +public interface ConversionMonitor extends MonitoringService +{ + /** + * Monitor the given {@link Conversion}s and block until they finishes. + * + * @param conversions The {@link Conversion}s to monitor. + */ + void awaitCompletion(final Conversion... conversions); + + /** + * Monitor the given {@link Conversion}s and populate an event when they finish. + * + * @param conversions The {@link Conversion}s to monitor. + */ + public void monitor(final Conversion... conversions); + + /** + * Monitor the given {@link Conversion}s and block until they finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param conversions The {@link Conversion}s to monitor. + */ + void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, + final Conversion... conversions); + + /** + * Monitor the given {@link Conversion}s and populate an event when they finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param conversions The {@link Conversion}s to monitor. + */ + public void monitor(final Long maxWait, final TimeUnit timeUnit, + final Conversion... conversions); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java new file mode 100644 index 0000000000..b5351648dd --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor; + +/** + * Represents the states of a running monitor. + * + * @author Serafin Sedano + */ +public enum MonitorStatus +{ + /** The monitoring job has finished. */ + DONE, + + /** The monitoring job has finished and the result is not the expected one. */ + FAILED, + + /** The monitoring job must continue. */ + CONTINUE +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java new file mode 100644 index 0000000000..b6088af4cd --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java @@ -0,0 +1,107 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.internal.BaseVirtualApplianceMonitor; + +import com.google.inject.ImplementedBy; + +/** + * {@link VirtualAppliance} monitoring features. + * + * @author Ignasi Barrera + */ +@ImplementedBy(BaseVirtualApplianceMonitor.class) +public interface VirtualApplianceMonitor extends MonitoringService +{ + /** + * Monitor the given {@link VirtualAppliance}s and block until the deploy finishes. + * + * @param vapp The {@link VirtualAppliance}s to monitor. + */ + void awaitCompletionDeploy(final VirtualAppliance... vapp); + + /** + * Monitor the given {@link VirtualAppliance}s and populate an event when the deploy finishes. + * + * @param VirtualAppliance The {@link VirtualAppliance}s to monitor. + */ + public void monitorDeploy(final VirtualAppliance... vapps); + + /** + * Monitor the given {@link VirtualAppliance}s and block until the deploy finishes. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vapp The {@link VirtualAppliance}s to monitor. + */ + void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapp); + + /** + * Monitor the given {@link VirtualAppliance}s and populate an event when deploy finishes. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vapps The {@link VirtualAppliance}s to monitor. + */ + public void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapps); + + /** + * Monitor the given {@link VirtualAppliance}s and block until the undeploy finishes. + * + * @param vapp The {@link VirtualAppliance}s to monitor. + */ + void awaitCompletionUndeploy(final VirtualAppliance... vapp); + + /** + * Monitor the given {@link VirtualAppliance}s and call populate an event when undeploy + * finishes. + * + * @param vapps The {@link VirtualAppliance}s to monitor. + */ + public void monitorUndeploy(final VirtualAppliance... vapps); + + /** + * Monitor the given {@link VirtualAppliance}s and blocks until the undeploy finishes. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vapp The {@link VirtualAppliance}s to monitor. + */ + void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapp); + + /** + * Monitor the given {@link VirtualAppliance}s and populate an event when undeploy finishes. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param callback The callback. + * @param vapps The {@link VirtualAppliance}s to monitor. + */ + public void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapps); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java new file mode 100644 index 0000000000..74d488e051 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java @@ -0,0 +1,144 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.internal.BaseVirtualMachineMonitor; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.inject.ImplementedBy; + +/** + * {@link VirtualMachine} monitoring features. + * + * @author Ignasi Barrera + */ +@ImplementedBy(BaseVirtualMachineMonitor.class) +public interface VirtualMachineMonitor extends MonitoringService +{ + /** + * Monitor the given {@link VirtualMachine}s and block until all deploys finish. + * + * @param vm The {@link VirtualMachine}s to monitor. + */ + void awaitCompletionDeploy(final VirtualMachine... vm); + + /** + * Monitor the given {@link VirtualMachine}s and populate an event when all deploys finish. + * + * @param vms The {@link VirtualMachine}s to monitor. + */ + public void monitorDeploy(final VirtualMachine... vms); + + /** + * Monitor the given {@link VirtualMachine}s and block until all deploys finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vm The {@link VirtualMachine}s to monitor. + */ + void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vm); + + /** + * Monitor the given {@link VirtualMachine}s and populate an event when all deploys finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vms The {@link VirtualMachine}s to monitor. + */ + public void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vms); + + /** + * Monitor the given {@link VirtualMachine}s and block until all undeploys finish. + * + * @param vm The {@link VirtualMachine}s to monitor. + */ + void awaitCompletionUndeploy(final VirtualMachine... vm); + + /** + * Monitor the given {@link VirtualMachine}s and populate an event when all undeploys finish. + * + * @param vms The {@link VirtualMachine}s to monitor. + */ + public void monitorUndeploy(final VirtualMachine... vms); + + /** + * Monitor the given {@link VirtualMachine}s and blocks until all undeploys finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vm The {@link VirtualMachine}s to monitor. + */ + void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vm); + + /** + * Monitor the given {@link VirtualMachine}s and populate an event when all undeploys finish. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param callback The callback. + * @param vms The {@link VirtualMachine}s to monitor. + */ + public void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vms); + + /** + * Monitor the given {@link VirtualMachine}s and block until it is in the given state. + * + * @param vm The {@link VirtualMachine}s to monitor. + */ + void awaitState(VirtualMachineState state, final VirtualMachine... vm); + + /** + * Monitor the given {@link VirtualMachine}s and populate an event when it is in the given + * state. + * + * @param vms The {@link VirtualMachine}s to monitor. + */ + public void monitorState(VirtualMachineState state, final VirtualMachine... vms); + + /** + * Monitor the given {@link VirtualMachine}s and block until it is in the given state. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param vm The {@link VirtualMachine}s to monitor. + */ + void awaitState(final Long maxWait, final TimeUnit timeUnit, VirtualMachineState state, + final VirtualMachine... vm); + + /** + * Monitor the given {@link VirtualMachine}s and populate an event when it is in the given + * state. + * + * @param maxWait The maximum time to wait. + * @param timeUnit The time unit for the maxWait parameter. + * @param callback The callback. + * @param vms The {@link VirtualMachine}s to monitor. + */ + public void monitorState(final Long maxWait, final TimeUnit timeUnit, + VirtualMachineState state, final VirtualMachine... vms); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java new file mode 100644 index 0000000000..5e18eb2d94 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; + +import com.google.common.base.Function; + +/** + * This class takes care of monitoring {@link AsyncTask} jobs. + * + * @author Ignasi Barrera + */ +@Singleton +public class AsyncTaskStatusMonitor implements Function +{ + @Resource + protected Logger logger = Logger.NULL; + + @Override + public MonitorStatus apply(final AsyncTask asyncTask) + { + checkNotNull(asyncTask, "asyncTask"); + + try + { + asyncTask.refresh(); + + switch (asyncTask.getState()) + { + case ABORTED: + case FINISHED_UNSUCCESSFULLY: + return MonitorStatus.FAILED; + case FINISHED_SUCCESSFULLY: + return MonitorStatus.DONE; + case STARTED: + case PENDING: + return MonitorStatus.CONTINUE; + default: + throw new IllegalStateException("Unsupported task status"); + } + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + asyncTask, getClass().getName()); + + return MonitorStatus.CONTINUE; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java new file mode 100644 index 0000000000..a97e38ecb5 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; + +import com.google.common.base.Function; + +/** + * This class takes care of monitoring {@link Conversion} jobs. + * + * @author Sergi Castro + */ +@Singleton +public class ConversionStatusMonitor implements Function +{ + @Resource + protected Logger logger = Logger.NULL; + + @Override + public MonitorStatus apply(final Conversion conversion) + { + checkNotNull(conversion, "conversion"); + + try + { + conversion.refresh(); + + switch (conversion.getState()) + { + case ENQUEUED: + return MonitorStatus.CONTINUE; + case FAILED: + return MonitorStatus.FAILED; + case FINISHED: + return MonitorStatus.DONE; + default: + throw new IllegalStateException("Unsupported conversion status"); + } + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + conversion, getClass().getName()); + + return MonitorStatus.CONTINUE; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java new file mode 100644 index 0000000000..d02f925948 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; + +import com.abiquo.server.core.cloud.VirtualApplianceState; +import com.google.common.base.Function; + +/** + * This class takes care of monitoring the a deploy of a {@link VirtualAppliance}. + * + * @author Serafin Sedano + */ +@Singleton +public class VirtualApplianceDeployMonitor implements Function +{ + @Resource + protected Logger logger = Logger.NULL; + + @Override + public MonitorStatus apply(final VirtualAppliance virtualAppliance) + { + checkNotNull(virtualAppliance, "virtualAppliance"); + + try + { + VirtualApplianceState state = virtualAppliance.getState(); + + switch (state) + { + case UNKNOWN: + case NEEDS_SYNC: + case NOT_DEPLOYED: + return MonitorStatus.FAILED; + case DEPLOYED: + return MonitorStatus.DONE; + case LOCKED: + default: + return MonitorStatus.CONTINUE; + } + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + virtualAppliance, getClass().getName()); + + return MonitorStatus.CONTINUE; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java new file mode 100644 index 0000000000..4951a4fa6f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; +import org.jclouds.rest.ResourceNotFoundException; + +import com.abiquo.server.core.cloud.VirtualApplianceState; +import com.google.common.base.Function; + +/** + * This class takes care of monitoring the a undeploy of a {@link VirtualAppliance}. + * + * @author Serafin Sedano + */ +@Singleton +public class VirtualApplianceUndeployMonitor implements Function +{ + @Resource + protected Logger logger = Logger.NULL; + + @Override + public MonitorStatus apply(final VirtualAppliance virtualAppliance) + { + checkNotNull(virtualAppliance, "virtualAppliance"); + + try + { + VirtualApplianceState state = virtualAppliance.getState(); + + switch (state) + { + case DEPLOYED: + case UNKNOWN: + case NEEDS_SYNC: + return MonitorStatus.FAILED; + case NOT_DEPLOYED: + return MonitorStatus.DONE; + case LOCKED: + default: + return MonitorStatus.CONTINUE; + } + } + catch (ResourceNotFoundException nfe) + { + logger.warn("virtual appliance %s not found, assuming it was undeployed successfully, " + + "stop monitor with DONE", virtualAppliance); + return MonitorStatus.DONE; + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + virtualAppliance, getClass().getName()); + + return MonitorStatus.CONTINUE; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java new file mode 100644 index 0000000000..0befb07d30 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Function; +import com.google.inject.Singleton; + +/** + * This class takes care of monitoring the a deploy of a {@link VirtualMachine}. + * + * @author Serafin Sedano + * @see MonitoringService + */ +@Singleton +public class VirtualMachineDeployMonitor implements Function +{ + @Resource + private Logger logger = Logger.NULL; + + @Override + public MonitorStatus apply(final VirtualMachine virtualMachine) + { + checkNotNull(virtualMachine, "virtualMachine"); + + try + { + VirtualMachineState state = virtualMachine.getState(); + + switch (state) + { + case NOT_ALLOCATED: + case UNKNOWN: + return MonitorStatus.FAILED; + case ON: + return MonitorStatus.DONE; + default: + return MonitorStatus.CONTINUE; + } + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + virtualMachine, getClass().getName()); + + return MonitorStatus.CONTINUE; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java new file mode 100644 index 0000000000..869b959afb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Function; + +/** + * This class takes care of monitoring the state of a {@link VirtualMachine}. + * + * @author Ignasi Barrera + * @see MonitoringService + */ +public class VirtualMachineStateMonitor implements Function +{ + @Resource + private Logger logger = Logger.NULL; + + private VirtualMachineState expectedState; + + public VirtualMachineStateMonitor(final VirtualMachineState expectedState) + { + super(); + this.expectedState = checkNotNull(expectedState, "expectedState"); + } + + @Override + public MonitorStatus apply(final VirtualMachine virtualMachine) + { + checkNotNull(virtualMachine, "virtualMachine"); + + try + { + VirtualMachineState state = virtualMachine.getState(); + return state == expectedState ? MonitorStatus.DONE : MonitorStatus.CONTINUE; + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + virtualMachine, getClass().getName()); + + return MonitorStatus.CONTINUE; + + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java new file mode 100644 index 0000000000..b82006cecb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java @@ -0,0 +1,85 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.logging.Logger; +import org.jclouds.rest.ResourceNotFoundException; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Function; + +/** + * This class takes care of monitoring the a undeploy of a {@link VirtualMachine}. + * + * @author Serafin Sedano + */ +@Singleton +public class VirtualMachineUndeployMonitor implements Function +{ + @Resource + protected Logger logger = Logger.NULL; + + @Override + public MonitorStatus apply(final VirtualMachine virtualMachine) + { + checkNotNull(virtualMachine, "virtualMachine"); + + try + { + VirtualMachineState state = virtualMachine.getState(); + + // This state may be reached if the undeploy process fails and a rollback is done + if (state.existsInHypervisor()) + { + return MonitorStatus.FAILED; + } + + switch (state) + { + case UNKNOWN: + return MonitorStatus.FAILED; + case NOT_ALLOCATED: + return MonitorStatus.DONE; + default: + return MonitorStatus.CONTINUE; + } + } + catch (ResourceNotFoundException nfe) + { + logger.warn("virtual machine %s not found, assuming it was undeployed successfully, " + + "stop monitor with DONE", virtualMachine); + return MonitorStatus.DONE; + } + catch (Exception ex) + { + logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", + virtualMachine, getClass().getName()); + + return MonitorStatus.CONTINUE; + } + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java new file mode 100644 index 0000000000..00cb30a264 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java @@ -0,0 +1,91 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.internal.BaseMonitoringService; +import org.jclouds.abiquo.monitor.AsyncTaskMonitor; +import org.jclouds.abiquo.monitor.functions.AsyncTaskStatusMonitor; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.eventbus.EventBus; + +/** + * Default monitor for {@link AsyncTask} objects. + * + * @author Ignasi Barrera + */ +@Singleton +public class BaseAsyncTaskMonitor extends BaseMonitoringService implements AsyncTaskMonitor +{ + + @VisibleForTesting + protected AsyncTaskStatusMonitor taskMonitor; + + @Inject + public BaseAsyncTaskMonitor(final RestContext context, + @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, + @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, + final AsyncTaskStatusMonitor monitor) + { + super(context, scheduler, pollingDelay, eventBus); + this.taskMonitor = checkNotNull(monitor, "monitor"); + } + + @Override + public void awaitCompletion(final AsyncTask... tasks) + { + awaitCompletion(taskMonitor, tasks); + } + + @Override + public void monitor(final AsyncTask... tasks) + { + monitor(taskMonitor, tasks); + } + + @Override + public void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, + final AsyncTask... tasks) + { + awaitCompletion(maxWait, timeUnit, taskMonitor, tasks); + } + + @Override + public void monitor(final Long maxWait, final TimeUnit timeUnit, final AsyncTask... tasks) + { + monitor(maxWait, timeUnit, taskMonitor, tasks); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java new file mode 100644 index 0000000000..a31ed41db5 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java @@ -0,0 +1,92 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.internal.BaseMonitoringService; +import org.jclouds.abiquo.monitor.ConversionMonitor; +import org.jclouds.abiquo.monitor.functions.ConversionStatusMonitor; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.eventbus.EventBus; + +/** + * Default monitor for {@link Conversion} objects. + * + * @author Sergi Castro + */ +@Singleton +public class BaseConversionMonitor extends BaseMonitoringService implements ConversionMonitor +{ + + @VisibleForTesting + protected ConversionStatusMonitor conversionMonitor; + + @Inject + public BaseConversionMonitor(final RestContext context, + @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, + @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, + final ConversionStatusMonitor monitor) + { + super(context, scheduler, pollingDelay, eventBus); + this.conversionMonitor = checkNotNull(monitor, "monitor"); + } + + @Override + public void awaitCompletion(final Conversion... conversions) + { + awaitCompletion(conversionMonitor, conversions); + } + + @Override + public void monitor(final Conversion... conversions) + { + monitor(conversionMonitor, conversions); + } + + @Override + public void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, + final Conversion... conversions) + { + awaitCompletion(maxWait, timeUnit, conversionMonitor, conversions); + } + + @Override + public void monitor(final Long maxWait, final TimeUnit timeUnit, + final Conversion... conversions) + { + monitor(maxWait, timeUnit, conversionMonitor, conversions); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java new file mode 100644 index 0000000000..a561352aaa --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java @@ -0,0 +1,123 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.internal.BaseMonitoringService; +import org.jclouds.abiquo.monitor.VirtualApplianceMonitor; +import org.jclouds.abiquo.monitor.functions.VirtualApplianceDeployMonitor; +import org.jclouds.abiquo.monitor.functions.VirtualApplianceUndeployMonitor; +import org.jclouds.rest.RestContext; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.eventbus.EventBus; + +/** + * Default monitor for {@link VirtualAppliance} objects. + * + * @author Ignasi Barrera + */ +@Singleton +public class BaseVirtualApplianceMonitor extends BaseMonitoringService implements + VirtualApplianceMonitor +{ + @VisibleForTesting + protected VirtualApplianceDeployMonitor deployMonitor; + + @VisibleForTesting + protected VirtualApplianceUndeployMonitor undeployMonitor; + + @Inject + public BaseVirtualApplianceMonitor(final RestContext context, + @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, + @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, + final VirtualApplianceDeployMonitor deployMonitor, + final VirtualApplianceUndeployMonitor undeployMonitor) + { + super(context, scheduler, pollingDelay, eventBus); + this.deployMonitor = checkNotNull(deployMonitor, "deployMonitor"); + this.undeployMonitor = checkNotNull(undeployMonitor, "undeployMonitor"); + } + + @Override + public void awaitCompletionDeploy(final VirtualAppliance... vapps) + { + awaitCompletion(deployMonitor, vapps); + } + + @Override + public void monitorDeploy(final VirtualAppliance... vapps) + { + monitor(deployMonitor, vapps); + } + + @Override + public void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapps) + { + awaitCompletion(maxWait, timeUnit, deployMonitor, vapps); + } + + @Override + public void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapps) + { + monitor(maxWait, timeUnit, deployMonitor, vapps); + } + + @Override + public void awaitCompletionUndeploy(final VirtualAppliance... vapps) + { + awaitCompletion(undeployMonitor, vapps); + } + + @Override + public void monitorUndeploy(final VirtualAppliance... vapps) + { + monitor(undeployMonitor, vapps); + } + + @Override + public void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapps) + { + awaitCompletion(maxWait, timeUnit, undeployMonitor, vapps); + } + + @Override + public void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualAppliance... vapps) + { + monitor(maxWait, timeUnit, undeployMonitor, vapps); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java new file mode 100644 index 0000000000..1cc6e0cb35 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java @@ -0,0 +1,151 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.internal.BaseMonitoringService; +import org.jclouds.abiquo.monitor.VirtualMachineMonitor; +import org.jclouds.abiquo.monitor.functions.VirtualMachineDeployMonitor; +import org.jclouds.abiquo.monitor.functions.VirtualMachineStateMonitor; +import org.jclouds.abiquo.monitor.functions.VirtualMachineUndeployMonitor; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.eventbus.EventBus; + +/** + * Default monitor for {@link VirtualMachine} objects. + * + * @author Ignasi Barrera + */ +@Singleton +public class BaseVirtualMachineMonitor extends BaseMonitoringService implements + VirtualMachineMonitor +{ + @VisibleForTesting + protected VirtualMachineDeployMonitor deployMonitor; + + @VisibleForTesting + protected VirtualMachineUndeployMonitor undeployMonitor; + + @Inject + public BaseVirtualMachineMonitor(final RestContext context, + @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, + @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, + final VirtualMachineDeployMonitor deployMonitor, + final VirtualMachineUndeployMonitor undeployMonitor) + { + super(context, scheduler, pollingDelay, eventBus); + this.deployMonitor = checkNotNull(deployMonitor, "deployMonitor"); + this.undeployMonitor = checkNotNull(undeployMonitor, "undeployMonitor"); + } + + @Override + public void awaitCompletionDeploy(final VirtualMachine... vms) + { + awaitCompletion(deployMonitor, vms); + } + + @Override + public void monitorDeploy(final VirtualMachine... vms) + { + monitor(deployMonitor, vms); + } + + @Override + public void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vms) + { + awaitCompletion(maxWait, timeUnit, deployMonitor, vms); + } + + @Override + public void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vms) + { + monitor(maxWait, timeUnit, deployMonitor, vms); + } + + @Override + public void awaitCompletionUndeploy(final VirtualMachine... vms) + { + awaitCompletion(undeployMonitor, vms); + } + + @Override + public void monitorUndeploy(final VirtualMachine... vms) + { + monitor(undeployMonitor, vms); + } + + @Override + public void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vms) + { + awaitCompletion(maxWait, timeUnit, undeployMonitor, vms); + } + + @Override + public void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachine... vms) + { + monitor(maxWait, timeUnit, undeployMonitor, vms); + } + + @Override + public void awaitState(final VirtualMachineState state, final VirtualMachine... vms) + { + awaitCompletion(new VirtualMachineStateMonitor(state), vms); + } + + @Override + public void monitorState(final VirtualMachineState state, final VirtualMachine... vms) + { + monitor(new VirtualMachineStateMonitor(state), vms); + } + + @Override + public void awaitState(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachineState state, final VirtualMachine... vms) + { + awaitCompletion(maxWait, timeUnit, new VirtualMachineStateMonitor(state), vms); + } + + @Override + public void monitorState(final Long maxWait, final TimeUnit timeUnit, + final VirtualMachineState state, final VirtualMachine... vms) + { + monitor(maxWait, timeUnit, new VirtualMachineStateMonitor(state), vms); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java new file mode 100644 index 0000000000..33000480bd --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java @@ -0,0 +1,49 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import com.abiquo.model.transport.error.ErrorDto; +import com.google.common.base.Predicate; + +/** + * Container for {@link ErrorDto} filters. + * + * @author Ignasi Barrera + */ +public class ErrorPredicates +{ + public static Predicate code(final String... codes) + { + checkNotNull(codes, "codes must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final ErrorDto error) + { + return Arrays.asList(codes).contains(error.getCode()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java new file mode 100644 index 0000000000..e10be2952b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import com.abiquo.model.rest.RESTLink; +import com.google.common.base.Predicate; + +/** + * Container for {@link RESTLink} filters. + * + * @author Ignasi Barrera + */ +public class LinkPredicates +{ + public static Predicate rel(final String... rels) + { + checkNotNull(rels, "rels must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final RESTLink link) + { + return Arrays.asList(rels).contains(link.getRel()); + } + }; + } + + public static Predicate isNic() + { + return new Predicate() + { + @Override + public boolean apply(final RESTLink link) + { + return link.getRel().matches("^nic[0-9]+$"); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java new file mode 100644 index 0000000000..69594942ee --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java @@ -0,0 +1,98 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.enumerator.HypervisorType; +import com.google.common.base.Predicate; + +/** + * Container for {@link VirtualMachineTemplate} filters. + * + * @author Francesc Montserrat + */ +public class ConversionPredicates +{ + + public static Predicate sourceFormat(final DiskFormatType... formats) + { + checkNotNull(formats, "formats must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Conversion conversion) + { + return Arrays.asList(formats).contains(conversion.getSourceFormat()); + } + }; + } + + public static Predicate targetFormat(final DiskFormatType... formats) + { + checkNotNull(formats, "formats must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Conversion conversion) + { + return Arrays.asList(formats).contains(conversion.getTargetFormat()); + } + }; + } + + public static Predicate state(final ConversionState... states) + { + checkNotNull(states, "states must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Conversion conversion) + { + return Arrays.asList(states).contains(conversion.getState()); + } + }; + } + + public static Predicate compatible(final HypervisorType type) + { + checkNotNull(type, "type must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Conversion conversion) + { + return type.isCompatible(conversion.getTargetFormat()); + } + }; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java new file mode 100644 index 0000000000..426f2f77d9 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; + +import com.google.common.base.Predicate; + +/** + * Container for {@link VirtualAppliance} filters. + * + * @author Serafín Sedano + */ +public class VirtualAppliancePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualAppliance virtualAppliance) + { + return Arrays.asList(names).contains(virtualAppliance.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java new file mode 100644 index 0000000000..d515db40d4 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java @@ -0,0 +1,104 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.transform; + +import java.util.Arrays; +import java.util.List; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.reference.rest.ParentLinkName; + +import com.abiquo.model.enumerator.HypervisorType; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; + +/** + * Container for {@link VirtualDatacenter} filters. + * + * @author Ignasi Barrera + */ +public class VirtualDatacenterPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualDatacenter virtualDatacenter) + { + return Arrays.asList(names).contains(virtualDatacenter.getName()); + } + }; + } + + public static Predicate type(final HypervisorType... types) + { + checkNotNull(types, "types must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualDatacenter virtualDatacenter) + { + return Arrays.asList(types).contains(virtualDatacenter.getHypervisorType()); + } + }; + } + + public static Predicate datacenter(final Datacenter... datacenters) + { + checkNotNull(datacenters, "datacenters must be defined"); + + final List ids = + Lists.newArrayList(transform(Arrays.asList(datacenters), + new Function() + { + @Override + public Integer apply(final Datacenter input) + { + return input.getId(); + } + })); + + return new Predicate() + { + @Override + public boolean apply(final VirtualDatacenter virtualDatacenter) + { + // Avoid using the getDatacenter() method since it will generate an unnecessary API + // call. We can get the ID from the datacenter link. + Integer datacenterId = + checkNotNull(virtualDatacenter.unwrap() + .getIdFromLink(ParentLinkName.DATACENTER), + ValidationErrors.MISSING_REQUIRED_LINK); + + return ids.contains(datacenterId); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java new file mode 100644 index 0000000000..34ae673fd4 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java @@ -0,0 +1,80 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Predicate; + +/** + * Container for {@link VirtualMachine} filters. + * + * @author Ignasi Barrera + */ +public class VirtualMachinePredicates +{ + public static Predicate internalName(final String... internalName) + { + checkNotNull(internalName, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachine virtualMachine) + { + return Arrays.asList(internalName).contains(virtualMachine.getInternalName()); + } + }; + } + + public static Predicate nameLabel(final String... nameLabels) + { + checkNotNull(nameLabels, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachine virtualMachine) + { + return Arrays.asList(nameLabels).contains(virtualMachine.getNameLabel()); + } + }; + } + + public static Predicate state(final VirtualMachineState... states) + { + checkNotNull(states, "states must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachine virtualMachine) + { + // The getState() method will generate an API call + return Arrays.asList(states).contains(virtualMachine.getState()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java new file mode 100644 index 0000000000..a90c54e274 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java @@ -0,0 +1,94 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; + +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.enumerator.HypervisorType; +import com.google.common.base.Predicate; + +/** + * Container for {@link VirtualMachineTemplate} filters. + * + * @author Francesc Montserrat + */ +public class VirtualMachineTemplatePredicates +{ + public static Predicate id(final Integer... ids) + { + checkNotNull(ids, "ids must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachineTemplate template) + { + return Arrays.asList(ids).contains(template.getId()); + } + }; + } + + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachineTemplate template) + { + return Arrays.asList(names).contains(template.getName()); + } + }; + } + + public static Predicate diskFormat(final DiskFormatType... formats) + { + checkNotNull(formats, "formats must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachineTemplate template) + { + return Arrays.asList(formats).contains(template.getDiskFormatType()); + } + }; + } + + public static Predicate compatible(final HypervisorType type) + { + checkNotNull(type, "type must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final VirtualMachineTemplate template) + { + return type.isCompatible(template.getDiskFormatType()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java new file mode 100644 index 0000000000..b85ef9f428 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java @@ -0,0 +1,89 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.cloud; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.cloud.Volume; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + +/** + * Container for {@link Volume} filters. + * + * @author Ignasi Barrera + */ +public class VolumePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Volume volume) + { + return Arrays.asList(names).contains(volume.getName()); + } + }; + } + + public static Predicate greaterThan(final long sizeInMb) + { + checkNotNull(sizeInMb, "sizeInMb must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Volume volume) + { + return volume.getSizeInMB() > sizeInMb; + } + }; + } + + public static Predicate greaterThanOrEqual(final long sizeInMb) + { + checkNotNull(sizeInMb, "sizeInMb must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Volume volume) + { + return volume.getSizeInMB() >= sizeInMb; + } + }; + } + + public static Predicate lesserThan(final long sizeInMb) + { + return Predicates.not(greaterThanOrEqual(sizeInMb)); + } + + public static Predicate lesserThanOrEquals(final long sizeInMb) + { + return Predicates.not(greaterThan(sizeInMb)); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java new file mode 100644 index 0000000000..04bed94d9c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.config.Category; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Category} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class CategoryPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Category category) + { + return Arrays.asList(names).contains(category.getName()); + } + }; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java new file mode 100644 index 0000000000..4261dfb014 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CurrencyPredicates.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.config.Currency; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Currency} filters. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +public class CurrencyPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Currency currency) + { + return Arrays.asList(names).contains(currency.getName()); + } + }; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java new file mode 100644 index 0000000000..d99705f8a6 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java @@ -0,0 +1,64 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.config.License; + +import com.google.common.base.Predicate; + +/** + * Container for {@link License} filters. + * + * @author Ignasi Barrera + */ +public class LicensePredicates +{ + public static Predicate customer(final String... customerIds) + { + checkNotNull(customerIds, "customers must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final License license) + { + return Arrays.asList(customerIds).contains(license.getCustomerId()); + } + }; + } + + public static Predicate code(final String... codes) + { + checkNotNull(codes, "customers must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final License license) + { + return Arrays.asList(codes).contains(license.getCode()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java new file mode 100644 index 0000000000..20f9ca846b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.config.Privilege; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Privilege} filters. + * + * @author Ignasi Barrera + */ +public class PrivilegePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Privilege privilege) + { + return Arrays.asList(names).contains(privilege.getName()); + } + }; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java new file mode 100644 index 0000000000..b5fc62de2a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.config.SystemProperty; + +import com.google.common.base.Predicate; + +/** + * Container for {@link SystemProperty} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class SystemPropertyPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final SystemProperty property) + { + return Arrays.asList(names).contains(property.getName()); + } + }; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java new file mode 100644 index 0000000000..c411e82ec3 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.enterprise; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.enterprise.Enterprise; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Enterprise} filters. + * + * @author Ignasi Barrera + */ +public class EnterprisePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Enterprise enterprise) + { + return Arrays.asList(names).contains(enterprise.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java new file mode 100644 index 0000000000..1cd895c255 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.enterprise; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.enterprise.Role; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Role} filters. + * + * @author Ignasi Barrera + */ +public class RolePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Role role) + { + return Arrays.asList(names).contains(role.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java new file mode 100644 index 0000000000..1039d893c5 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.enterprise; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.enterprise.TemplateDefinitionList; + +import com.google.common.base.Predicate; + +/** + * Container for {@link TemplateDefinitionList} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class TemplateDefinitionListPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final TemplateDefinitionList templateList) + { + return Arrays.asList(names).contains(templateList.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java new file mode 100644 index 0000000000..8a3823f1db --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.enterprise; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.enterprise.User; + +import com.google.common.base.Predicate; + +/** + * Container for {@link User} filters. + * + * @author Ignasi Barrera + */ +public class UserPredicates +{ + public static Predicate nick(final String... nicks) + { + checkNotNull(nicks, "nicks must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final User user) + { + return Arrays.asList(nicks).contains(user.getNick()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java new file mode 100644 index 0000000000..304ed26931 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.Blade; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Blade} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class BladePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "name must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Blade machine) + { + return Arrays.asList(names).contains(machine.getName()); + } + }; + } + + public static Predicate ip(final String ip) + { + return ips(checkNotNull(ip, "ip must be defined")); + } + + public static Predicate ips(final String... ips) + { + checkNotNull(ips, "ips must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Blade machine) + { + return Arrays.asList(ips).contains(machine.getIp()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java new file mode 100644 index 0000000000..d3febc3a74 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.Datacenter; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Datacenter} filters. + * + * @author Ignasi Barrera + */ +public class DatacenterPredicates +{ + public static Predicate id(final Integer... ids) + { + checkNotNull(ids, "ids must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Datacenter datacenter) + { + return Arrays.asList(ids).contains(datacenter.getId()); + } + }; + } + + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Datacenter datacenter) + { + return Arrays.asList(names).contains(datacenter.getName()); + } + }; + } + + public static Predicate location(final String... locations) + { + checkNotNull(locations, "locations must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Datacenter datacenter) + { + return Arrays.asList(locations).contains(datacenter.getLocation()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java new file mode 100644 index 0000000000..d094594ce4 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.Datastore; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Datastore} filters. + * + * @author Ignasi Barrera + */ +public class DatastorePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Datastore datastore) + { + return Arrays.asList(names).contains(datastore.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java new file mode 100644 index 0000000000..09ad31fe6f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import com.abiquo.model.enumerator.HypervisorType; +import com.google.common.base.Predicate; + +/** + * Container for {@link HypervisorType} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class HypervisorPredicates +{ + public static Predicate type(final HypervisorType... types) + { + checkNotNull(types, "types must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final HypervisorType type) + { + return Arrays.asList(types).contains(type); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java new file mode 100644 index 0000000000..4ec5bc253e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.LogicServer; + +import com.google.common.base.Predicate; + +/** + * Container for {@link LogicServer} filters. + * + * @author Francesc Montserrat + */ +public class LogicServerPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final LogicServer logicServer) + { + return Arrays.asList(names).contains(logicServer.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java new file mode 100644 index 0000000000..8857f8ad03 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.Machine; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Machine} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class MachinePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "name must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Machine machine) + { + return Arrays.asList(names).contains(machine.getName()); + } + }; + } + + public static Predicate ip(final String ip) + { + return ips(checkNotNull(ip, "ip must be defined")); + } + + public static Predicate ips(final String... ips) + { + checkNotNull(ips, "ips must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Machine machine) + { + return Arrays.asList(ips).contains(machine.getIp()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java new file mode 100644 index 0000000000..fcd5401bb7 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.ManagedRack; + +import com.google.common.base.Predicate; + +/** + * Container for {@link ManagedRack} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class ManagedRackPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final ManagedRack rack) + { + return Arrays.asList(names).contains(rack.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java new file mode 100644 index 0000000000..d2ed7de199 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.Rack; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Rack} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class RackPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Rack rack) + { + return Arrays.asList(names).contains(rack.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java new file mode 100644 index 0000000000..64b7c403f5 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.RemoteService; + +import com.abiquo.model.enumerator.RemoteServiceType; +import com.google.common.base.Predicate; + +/** + * Container for {@link RemoteService} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class RemoteServicePredicates +{ + public static Predicate type(final RemoteServiceType... types) + { + checkNotNull(types, "types must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final RemoteService remoteService) + { + return Arrays.asList(types).contains(remoteService.getType()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java new file mode 100644 index 0000000000..e4971f095a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.StorageDeviceMetadata; + +import com.google.common.base.Predicate; + +/** + * Container for {@link StorageDeviceMetadata} filters. + * + * @author Ignasi Barrera + */ +public class StorageDeviceMetadataPredicates +{ + + public static Predicate type(final String... types) + { + checkNotNull(types, "types must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final StorageDeviceMetadata metadata) + { + return Arrays.asList(types).contains(metadata.getType()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java new file mode 100644 index 0000000000..1a0e6a2ea8 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.StorageDevice; + +import com.google.common.base.Predicate; + +/** + * Container for {@link StorageDevice} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class StorageDevicePredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final StorageDevice storageDevice) + { + return Arrays.asList(names).contains(storageDevice.getName()); + } + }; + } + + public static Predicate managementIp(final String... ips) + { + checkNotNull(ips, "managementIps must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final StorageDevice storageDevice) + { + return Arrays.asList(ips).contains(storageDevice.getManagementIp()); + } + }; + } + + public static Predicate type(final String... types) + { + checkNotNull(types, "types must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final StorageDevice storageDevice) + { + return Arrays.asList(types).contains(storageDevice.getType()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java new file mode 100644 index 0000000000..5363664a09 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.StoragePool; + +import com.google.common.base.Predicate; + +/** + * Container for {@link StoragePool} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class StoragePoolPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final StoragePool storagePool) + { + return Arrays.asList(names).contains(storagePool.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java new file mode 100644 index 0000000000..66414ce759 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.infrastructure; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.infrastructure.Tier; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Tier} filters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class TierPredicates +{ + public static Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Tier tier) + { + return Arrays.asList(names).contains(tier.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java new file mode 100644 index 0000000000..b05947c24f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.network.AbstractPublicIp; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.Network; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Network} filters. + * + * @author Francesc Montserrat + */ +public class IpPredicates +{ + public static > Predicate name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final T address) + { + return Arrays.asList(names).contains(address.getName()); + } + }; + } + + public static > Predicate address(final String... addresses) + { + checkNotNull(addresses, "addresses must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final T address) + { + return Arrays.asList(addresses).contains(address.getIp()); + } + }; + } + + public static > Predicate available() + { + return new Predicate() + { + @Override + public boolean apply(final T address) + { + return address.isAvailable(); + } + }; + } + + public static > Predicate notUsed() + { + return new Predicate() + { + @Override + public boolean apply(final T address) + { + return address.unwrap().searchLink("virtualmachine") == null; + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java new file mode 100644 index 0000000000..eb22fdba77 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.Network; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Network} filters. + * + * @author Francesc Montserrat + */ +public class NetworkPredicates +{ + public static > Predicate> name(final String... names) + { + checkNotNull(names, "names must be defined"); + + return new Predicate>() + { + @Override + public boolean apply(final Network network) + { + return Arrays.asList(names).contains(network.getName()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java new file mode 100644 index 0000000000..6df89c4c28 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java @@ -0,0 +1,64 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.network.Nic; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Nic} filters. + * + * @author Francesc Montserrat + */ +public class NicPredicates +{ + public static Predicate ip(final String... ips) + { + checkNotNull(ips, "ips must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Nic nic) + { + return Arrays.asList(ips).contains(nic.getIp()); + } + }; + } + + public static Predicate mac(final String... macs) + { + checkNotNull(macs, "macs must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final Nic nic) + { + return Arrays.asList(macs).contains(nic.getMac()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java new file mode 100644 index 0000000000..7f0f685007 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.predicates.task; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; + +import org.jclouds.abiquo.domain.task.AsyncTask; + +import com.abiquo.server.core.task.enums.TaskState; +import com.google.common.base.Predicate; + +/** + * Container for {@link AsyncTask} filters. + * + * @author Ignasi Barrera + */ +public class AsyncTaskPredicates +{ + public static Predicate state(final TaskState... states) + { + checkNotNull(states, "states must be defined"); + + return new Predicate() + { + @Override + public boolean apply(final AsyncTask task) + { + return Arrays.asList(states).contains(task.getState()); + } + }; + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java new file mode 100644 index 0000000000..ac560edb9c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.reference; + +import org.jclouds.abiquo.features.services.MonitoringService; + +/** + * Global constants used in the Abiquo provider. + * + * @author Ignasi Barrera + */ +public interface AbiquoConstants +{ + /** + * Boolean property indicating if the provided credential is an api token. + *

+ * Default value: false + */ + public static final String CREDENTIAL_IS_TOKEN = "abiquo.credential-is-token"; + + /** + * The delay (in ms) used between requests by the {@link MonitoringService} when monitoring + * asynchronous task state. + *

+ * Default value: 5000 ms + */ + public static final String ASYNC_TASK_MONITOR_DELAY = "abiquo.monitor-delay"; +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java new file mode 100644 index 0000000000..a3d685dbea --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.reference; + +/** + * The Abiquo Edition (Community or Enterprise). + * + * @author Francesc Montserrat + */ +public enum AbiquoEdition +{ + ENTERPRISE, COMMUNITY; +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java new file mode 100644 index 0000000000..1f3ce1cdf2 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.reference; + +/** + * Error constants. + * + * @author Francesc Montserrat + */ +public class ValidationErrors +{ + public static final String NULL_RESOURCE = "The resource should be assigned to a "; + + public static final String MISSING_REQUIRED_FIELD = "Missing required field "; + + public static final String MISSING_REQUIRED_LINK = "Missing required link "; + + public static final String INVALID_NETWORK_TYPE = "Invalid network type "; + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/annotations/EnterpriseEdition.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/annotations/EnterpriseEdition.java new file mode 100644 index 0000000000..9862629444 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/annotations/EnterpriseEdition.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.reference.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Indicates that the annotated element will access Abiquo Enterprise Edition functionallity. If the + * target Abiquo Cloud platform is a Community Edition version, the invocation of the method may + * have unexpected results. + * + * @author Ignasi Barrera + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface EnterpriseEdition +{ +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java new file mode 100644 index 0000000000..9db695adcf --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.reference.rest; + +/** + * Names of the "rel" attribute of the links that point to parent objects. + * + * @author Francesc Montserrat + */ +public class ParentLinkName +{ + public final static String RACK = "rack"; + + public final static String DATACENTER = "datacenter"; + + public final static String ENTERPRISE = "enterprise"; + + public final static String ROLE = "role"; + + public final static String TIER = "tier"; + + public final static String STORAGE_DEVICE = "device"; + + public final static String VIRTUAL_DATACENTER = "virtualdatacenter"; + + public final static String VIRTUAL_APPLIANCE = "virtualappliance"; + + public final static String VIRTUAL_MACHINE_TEMPLATE = "virtualmachinetemplate"; + + public final static String DATACENTER_REPOSITORY = "datacenterrepository"; + + public final static String COST_CODE = "costcode"; + + public final static String CATEGORY = "category"; + + public final static String ICON = "icon"; + + public final static String PRIVATE_NETWORK = "privatenetwork"; + + public final static String PUBLIC_NETWORK = "publicnetwork"; + + public final static String EXTERNAL_NETWORK = "externalnetwork"; + + public final static String UNMANAGED_NETWORK = "unmanagednetwork"; + + public final static String NETWORK_CONFIGURATIONS = "configurations"; + + public final static String NETWORK_GATEWAY = "network_configuration"; +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java new file mode 100644 index 0000000000..f32d6b0f26 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java @@ -0,0 +1,41 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.rest.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates the link to be used to generate the enpoind for the request. + * + * @author Ignasi Barrera + */ +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface EndpointLink +{ + + /** + * The name of the link that will be used to generate the request endpoint. + */ + String value(); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClient.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClient.java new file mode 100644 index 0000000000..6ffd12a01c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClient.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.rest.internal; + +import javax.ws.rs.GET; + +import org.jclouds.abiquo.binders.BindLinkToPathAndAcceptHeader; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.http.HttpResponse; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.abiquo.model.rest.RESTLink; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Custom Rest methods to work with the Abiquo Api. + * + * @author Ignasi Barrera + */ +@RequestFilters({AbiquoAuthentication.class, AppendApiVersionToMediaType.class}) +public interface AbiquoHttpAsyncClient +{ + /** + * @see AbiquoHttpClient#get(RESTLink) + */ + @GET + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + public ListenableFuture get( + @BinderParam(BindLinkToPathAndAcceptHeader.class) final RESTLink link); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpClient.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpClient.java new file mode 100644 index 0000000000..1e51824460 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/AbiquoHttpClient.java @@ -0,0 +1,44 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.rest.internal; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.http.HttpResponse; + +import com.abiquo.model.rest.RESTLink; + +/** + * Custom Rest methods to work with the Abiquo Api. + * + * @author Ignasi Barrera + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface AbiquoHttpClient +{ + /** + * Perform a GET request to the given link. + * + * @param link The link to get. + * @return The response. + */ + public HttpResponse get(final RESTLink link); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/ExtendedUtils.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/ExtendedUtils.java new file mode 100644 index 0000000000..13b95511d4 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/rest/internal/ExtendedUtils.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.rest.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.concurrent.ExecutorService; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.jclouds.Constants; +import org.jclouds.crypto.Crypto; +import org.jclouds.date.DateService; +import org.jclouds.domain.Credentials; +import org.jclouds.json.Json; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.rest.HttpAsyncClient; +import org.jclouds.rest.HttpClient; +import org.jclouds.rest.Utils; +import org.jclouds.rest.internal.UtilsImpl; +import org.jclouds.xml.XMLParser; + +import com.google.common.eventbus.EventBus; +import com.google.inject.Injector; +import com.google.inject.Singleton; + +/** + * Custom utility methods. + * + * @author Ignasi Barrera + */ +@Singleton +public class ExtendedUtils extends UtilsImpl implements Utils +{ + private AbiquoHttpClient abiquoHttpClient; + + private AbiquoHttpAsyncClient abiquoHttpAsyncApi; + + @Inject + public ExtendedUtils(final Injector injector, final Json json, final XMLParser xml, + final HttpClient simpleApi, final HttpAsyncClient simpleAsyncApi, final Crypto encryption, + final DateService date, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userThreads, + @Named(Constants.PROPERTY_IO_WORKER_THREADS) final ExecutorService ioThreads, + final EventBus eventBus, final Map credentialStore, + final LoggerFactory loggerFactory, final AbiquoHttpClient abiquoHttpClient, + final AbiquoHttpAsyncClient abiquoHttpAsyncApi) + { + super(injector, json, xml, simpleApi, simpleAsyncApi, encryption, date, userThreads, + ioThreads, eventBus, credentialStore, loggerFactory); + this.abiquoHttpClient = checkNotNull(abiquoHttpClient, "abiquoHttpClient"); + this.abiquoHttpAsyncApi = checkNotNull(abiquoHttpAsyncApi, "abiquoHttpAsyncApi"); + } + + public AbiquoHttpClient getAbiquoHttpClient() + { + return abiquoHttpClient; + } + + public AbiquoHttpAsyncClient getAbiquoHttpAsyncClient() + { + return abiquoHttpAsyncApi; + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java new file mode 100644 index 0000000000..16febd257f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy; + +import org.jclouds.abiquo.domain.DomainWrapper; + +import com.google.common.base.Predicate; + +/** + * List all entities of the given type. + * + * @author Ignasi Barrera + */ +public interface ListEntities, P extends DomainWrapper< ? >> +{ + Iterable execute(P parent); + + Iterable execute(P parent, Predicate selector); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java new file mode 100644 index 0000000000..5d05902c9b --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy; + +import org.jclouds.abiquo.domain.DomainWrapper; + +import com.google.common.base.Predicate; + +/** + * List all entities of the given type. + * + * @author Ignasi Barrera + */ +public interface ListRootEntities> +{ + Iterable execute(); + + Iterable execute(Predicate selector); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/ListRoles.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/ListRoles.java new file mode 100644 index 0000000000..f6922deb58 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/ListRoles.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.admin; + +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.admin.internal.ListRolesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List roles. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListRolesImpl.class) +public interface ListRoles extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImpl.java new file mode 100644 index 0000000000..81113484dd --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.admin.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.strategy.admin.ListRoles; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.RolesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List enterprises. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListRolesImpl implements ListRoles +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListRolesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + RolesDto result = context.getApi().getAdminApi().listRoles(); + return wrap(context, Role.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java new file mode 100644 index 0000000000..97e751ba48 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.strategy.ListEntities; +import org.jclouds.abiquo.strategy.cloud.internal.ListAttachedNicsImpl; + +import com.google.inject.ImplementedBy; + +/** + * List all NICs attached to a given virtual machine. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListAttachedNicsImpl.class) +public interface ListAttachedNics extends ListEntities, VirtualMachine> +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java new file mode 100644 index 0000000000..10a9c5acc0 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualAppliancesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List virtual appliances in each virtual datacenter. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListVirtualAppliancesImpl.class) +public interface ListVirtualAppliances extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java new file mode 100644 index 0000000000..7f2b7b0d32 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java @@ -0,0 +1,47 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud; + +import java.util.List; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualDatacentersImpl; + +import com.google.common.base.Predicate; +import com.google.inject.ImplementedBy; + +/** + * List virtual datacenters. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListVirtualDatacentersImpl.class) +public interface ListVirtualDatacenters extends ListRootEntities +{ + Iterable execute(VirtualDatacenterOptions virtualDatacenterOptions); + + Iterable execute(List virtualDatacenterIds); + + Iterable execute(Predicate selector, + VirtualDatacenterOptions virtualDatacenterOptions); + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java new file mode 100644 index 0000000000..ba6f3864cb --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualMachinesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List virtual machines in each virtual datacenter and each virtual appliance. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListVirtualMachinesImpl.class) +public interface ListVirtualMachines extends ListRootEntities +{ + Iterable execute(VirtualMachineOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImpl.java new file mode 100644 index 0000000000..cf3c16c62a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImpl.java @@ -0,0 +1,138 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.network.ExternalIp; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.domain.network.UnmanagedIp; +import org.jclouds.abiquo.domain.util.LinkUtils; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.abiquo.strategy.cloud.ListAttachedNics; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.RestContext; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Inject; +import com.google.inject.TypeLiteral; + +/** + * List all NICs attached to a given virtual machine. + * + * @author Ignasi Barrera + */ +@Singleton +public class ListAttachedNicsImpl implements ListAttachedNics +{ + protected final RestContext context; + + protected final ExtendedUtils extendedUtils; + + @Inject + public ListAttachedNicsImpl(final RestContext context, + final ExtendedUtils extendedUtils) + { + this.context = checkNotNull(context, "context"); + this.extendedUtils = checkNotNull(extendedUtils, "extendedUtils"); + } + + @Override + public Iterable> execute(final VirtualMachine parent) + { + parent.refresh(); + Iterable nicLinks = LinkUtils.filterNicLinks(parent.unwrap().getLinks()); + return listIps(nicLinks); + } + + @Override + public Iterable> execute(final VirtualMachine parent, + final Predicate> selector) + { + return filter(execute(parent), selector); + } + + private Iterable> listIps(final Iterable nicLinks) + { + return transform(nicLinks, new Function>() + { + @Override + public Ip< ? , ? > apply(final RESTLink input) + { + HttpResponse response = extendedUtils.getAbiquoHttpClient().get(input); + + if (input.getType().equals(PrivateIpDto.BASE_MEDIA_TYPE)) + { + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(extendedUtils.getXml(), TypeLiteral + .get(PrivateIpDto.class)); + + return wrap(context, PrivateIp.class, parser.apply(response)); + } + else if (input.getType().equals(PublicIpDto.BASE_MEDIA_TYPE)) + { + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(extendedUtils.getXml(), TypeLiteral + .get(PublicIpDto.class)); + + return wrap(context, PublicIp.class, parser.apply(response)); + } + else if (input.getType().equals(ExternalIpDto.BASE_MEDIA_TYPE)) + { + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(extendedUtils.getXml(), TypeLiteral + .get(ExternalIpDto.class)); + + return wrap(context, ExternalIp.class, parser.apply(response)); + } + else if (input.getType().equals(UnmanagedIpDto.BASE_MEDIA_TYPE)) + { + ParseXMLWithJAXB parser = + new ParseXMLWithJAXB(extendedUtils.getXml(), TypeLiteral + .get(UnmanagedIpDto.class)); + + return wrap(context, UnmanagedIp.class, parser.apply(response)); + } + else + { + throw new IllegalArgumentException("Unsupported media type: " + input.getType()); + } + } + }); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImpl.java new file mode 100644 index 0000000000..7c70d3a402 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImpl.java @@ -0,0 +1,117 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.strategy.cloud.ListVirtualAppliances; +import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List virtual appliance in each virtual datacenter. + * + * @author Ignasi Barrera + */ +@Singleton +public class ListVirtualAppliancesImpl implements ListVirtualAppliances +{ + protected final RestContext context; + + protected final ListVirtualDatacenters listVirtualDatacenters; + + protected final ExecutorService userExecutor; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject(optional = true) + @Named(Constants.PROPERTY_REQUEST_TIMEOUT) + protected Long maxTime; + + @Inject + ListVirtualAppliancesImpl(final RestContext context, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor, + final ListVirtualDatacenters listVirtualDatacenters) + { + this.context = checkNotNull(context, "context"); + this.listVirtualDatacenters = + checkNotNull(listVirtualDatacenters, "listVirtualDatacenters"); + this.userExecutor = checkNotNull(userExecutor, "userExecutor"); + } + + @Override + public Iterable execute() + { + // Find virtual appliances in concurrent requests + Iterable vdcs = listVirtualDatacenters.execute(); + Iterable vapps = listConcurrentVirtualAppliances(vdcs); + + return wrap(context, VirtualAppliance.class, vapps); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + + private Iterable listConcurrentVirtualAppliances( + final Iterable vdcs) + { + Iterable vapps = + transformParallel(vdcs, + new Function>() + { + @Override + public Future apply(final VirtualDatacenter input) + { + return context.getAsyncApi().getCloudApi() + .listVirtualAppliances(input.unwrap()); + } + }, userExecutor, maxTime, logger, "getting virtual appliances"); + + return DomainWrapper.join(vapps); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImpl.java new file mode 100644 index 0000000000..d73e3b4c4a --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImpl.java @@ -0,0 +1,132 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; +import com.google.inject.Inject; + +/** + * List virtual datacenters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListVirtualDatacentersImpl implements ListVirtualDatacenters +{ + protected final RestContext context; + + protected final ExecutorService userExecutor; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject(optional = true) + @Named(Constants.PROPERTY_REQUEST_TIMEOUT) + protected Long maxTime; + + @Inject + ListVirtualDatacentersImpl(final RestContext context, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) + { + this.context = checkNotNull(context, "context"); + this.userExecutor = checkNotNull(userExecutor, "userExecutor"); + } + + @Override + public Iterable execute() + { + VirtualDatacenterOptions virtualDatacenterOptions = + VirtualDatacenterOptions.builder().build(); + + return execute(virtualDatacenterOptions); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + + @Override + public Iterable execute( + final VirtualDatacenterOptions virtualDatacenterOptions) + { + VirtualDatacentersDto result = + context.getApi().getCloudApi().listVirtualDatacenters(virtualDatacenterOptions); + return wrap(context, VirtualDatacenter.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector, + final VirtualDatacenterOptions virtualDatacenterOptions) + { + return filter(execute(virtualDatacenterOptions), selector); + } + + @Override + public Iterable execute(final List virtualDatacenterIds) + { + // Find virtual datacenters in concurrent requests + return listConcurrentVirtualDatacenters(virtualDatacenterIds); + } + + private Iterable listConcurrentVirtualDatacenters(final List ids) + { + Iterable vdcs = + transformParallel(ids, new Function>() + { + @Override + public Future apply(final Integer input) + { + return context.getAsyncApi().getCloudApi().getVirtualDatacenter(input); + } + }, userExecutor, maxTime, logger, "getting virtual datacenters"); + + return DomainWrapper.wrap(context, VirtualDatacenter.class, Lists.newArrayList(vdcs)); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImpl.java new file mode 100644 index 0000000000..6f0a7c815f --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImpl.java @@ -0,0 +1,127 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.strategy.cloud.ListVirtualAppliances; +import org.jclouds.abiquo.strategy.cloud.ListVirtualMachines; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List virtual machines in each virtual datacenter and each virtual appliance. + * + * @author Ignasi Barrera + */ +@Singleton +public class ListVirtualMachinesImpl implements ListVirtualMachines +{ + protected final RestContext context; + + protected final ExecutorService userExecutor; + + protected final ListVirtualAppliances listVirtualAppliances; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject(optional = true) + @Named(Constants.PROPERTY_REQUEST_TIMEOUT) + protected Long maxTime; + + @Inject + ListVirtualMachinesImpl(final RestContext context, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor, + final ListVirtualAppliances listVirtualAppliances) + { + super(); + this.context = checkNotNull(context, "context"); + this.listVirtualAppliances = checkNotNull(listVirtualAppliances, "listVirtualAppliances"); + this.userExecutor = checkNotNull(userExecutor, "userExecutor"); + } + + @Override + public Iterable execute() + { + return execute(VirtualMachineOptions.builder().disablePagination().build()); + } + + @Override + public Iterable execute(final VirtualMachineOptions options) + { + // Find virtual machines in concurrent requests + Iterable vapps = listVirtualAppliances.execute(); + Iterable vms = + listConcurrentVirtualMachines(vapps, options); + + return wrap(context, VirtualMachine.class, vms); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + + private Iterable listConcurrentVirtualMachines( + final Iterable vapps, final VirtualMachineOptions options) + { + Iterable vms = + transformParallel( + vapps, + new Function>() + { + @Override + public Future apply( + final VirtualAppliance input) + { + return context.getAsyncApi().getCloudApi() + .listVirtualMachines(input.unwrap(), options); + } + }, userExecutor, maxTime, logger, "getting virtual machines"); + + return DomainWrapper.join(vms); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCategories.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCategories.java new file mode 100644 index 0000000000..69e6a40ed0 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCategories.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListCategoriesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List privileges. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListCategoriesImpl.class) +public interface ListCategories extends ListRootEntities +{ +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCurrencies.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCurrencies.java new file mode 100644 index 0000000000..168762e0cf --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListCurrencies.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListCurrenciesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List currencies + * + * @author Susana Acedo + */ +@ImplementedBy(ListCurrenciesImpl.class) +public interface ListCurrencies extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListLicenses.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListLicenses.java new file mode 100644 index 0000000000..8eccf96644 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListLicenses.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.License; +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListLicensesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List licenses. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListLicensesImpl.class) +public interface ListLicenses extends ListRootEntities +{ + public Iterable execute(LicenseOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPrivileges.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPrivileges.java new file mode 100644 index 0000000000..287dc08bd2 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListPrivileges.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListPrivilegesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List privileges. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListPrivilegesImpl.class) +public interface ListPrivileges extends ListRootEntities +{ +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListProperties.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListProperties.java new file mode 100644 index 0000000000..1f7f543c23 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/ListProperties.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config; + +import org.jclouds.abiquo.domain.config.SystemProperty; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.config.internal.ListPropertiesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List system properties. + * + * @author Francesc Montserrat + */ +@ImplementedBy(ListPropertiesImpl.class) +public interface ListProperties extends ListRootEntities +{ + public Iterable execute(PropertyOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImpl.java new file mode 100644 index 0000000000..cefe8119ef --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.strategy.config.ListCategories; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.appslibrary.CategoriesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List categories. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListCategoriesImpl implements ListCategories +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListCategoriesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + CategoriesDto result = context.getApi().getConfigApi().listCategories(); + return wrap(context, Category.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCurrenciesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCurrenciesImpl.java new file mode 100644 index 0000000000..d5d9ea85ff --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListCurrenciesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.config.Currency; +import org.jclouds.abiquo.strategy.config.ListCurrencies; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.pricing.CurrenciesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List currencies + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +@Singleton +public class ListCurrenciesImpl implements ListCurrencies +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListCurrenciesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + CurrenciesDto result = context.getApi().getPricingApi().listCurrencies(); + return wrap(context, Currency.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImpl.java new file mode 100644 index 0000000000..15e0c91051 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImpl.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.config.License; +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.strategy.config.ListLicenses; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.config.LicensesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List licenses. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListLicensesImpl implements ListLicenses +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListLicensesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + LicensesDto result = context.getApi().getConfigApi().listLicenses(); + return wrap(context, License.class, result.getCollection()); + } + + @Override + public Iterable execute(final LicenseOptions options) + { + LicensesDto result = context.getApi().getConfigApi().listLicenses(options); + return wrap(context, License.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImpl.java new file mode 100644 index 0000000000..a91c933c3d --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.strategy.config.ListPrivileges; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List licenses. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListPrivilegesImpl implements ListPrivileges +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListPrivilegesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + PrivilegesDto result = context.getApi().getConfigApi().listPrivileges(); + return wrap(context, Privilege.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImpl.java new file mode 100644 index 0000000000..8eeae43a40 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImpl.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.config.SystemProperty; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.abiquo.strategy.config.ListProperties; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.config.SystemPropertiesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List properties. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListPropertiesImpl implements ListProperties +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListPropertiesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties(); + return wrap(context, SystemProperty.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + + @Override + public Iterable execute(final PropertyOptions options) + { + SystemPropertiesDto result = + context.getApi().getConfigApi().listSystemProperties(options); + return wrap(context, SystemProperty.class, result.getCollection()); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListEnterprises.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListEnterprises.java new file mode 100644 index 0000000000..48fcb8038e --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListEnterprises.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.enterprise; + +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.enterprise.internal.ListEnterprisesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List enterprises. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListEnterprisesImpl.class) +public interface ListEnterprises extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java new file mode 100644 index 0000000000..e92034f1e3 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java @@ -0,0 +1,39 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.enterprise; + +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.strategy.ListEntities; +import org.jclouds.abiquo.strategy.enterprise.internal.ListVirtualMachineTemplatesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List all virtual machine templates available to an enterprise. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListVirtualMachineTemplatesImpl.class) +public interface ListVirtualMachineTemplates extends + ListEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImpl.java new file mode 100644 index 0000000000..76d9cc2607 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImpl.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.enterprise.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Singleton; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.strategy.enterprise.ListEnterprises; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.EnterprisesDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List enterprises. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListEnterprisesImpl implements ListEnterprises +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListEnterprisesImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + EnterprisesDto result = context.getApi().getEnterpriseApi().listEnterprises(); + return wrap(context, Enterprise.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImpl.java new file mode 100644 index 0000000000..b9d95f0a79 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImpl.java @@ -0,0 +1,114 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.enterprise.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.strategy.enterprise.ListVirtualMachineTemplates; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List all virtual machine templates available to an enterprise. + * + * @author Ignasi Barrera + */ +@Singleton +public class ListVirtualMachineTemplatesImpl implements ListVirtualMachineTemplates +{ + protected final RestContext context; + + protected final ExecutorService userExecutor; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject(optional = true) + @Named(Constants.PROPERTY_REQUEST_TIMEOUT) + protected Long maxTime; + + @Inject + ListVirtualMachineTemplatesImpl(final RestContext context, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) + { + super(); + this.context = checkNotNull(context, "context"); + this.userExecutor = checkNotNull(userExecutor, "userExecutor"); + } + + @Override + public Iterable execute(final Enterprise parent) + { + // Find virtual machine templates in concurrent requests + Iterable dcs = parent.listAllowedDatacenters(); + Iterable templates = listConcurrentTemplates(parent, dcs); + + return wrap(context, VirtualMachineTemplate.class, templates); + } + + @Override + public Iterable execute(final Enterprise parent, + final Predicate selector) + { + return filter(execute(parent), selector); + } + + private Iterable listConcurrentTemplates(final Enterprise parent, + final Iterable dcs) + { + Iterable templates = + transformParallel(dcs, + new Function>() + { + @Override + public Future apply(final Datacenter input) + { + return context.getAsyncApi().getVirtualMachineTemplateApi() + .listVirtualMachineTemplates(parent.getId(), input.getId()); + } + }, userExecutor, maxTime, logger, "getting virtual machine templates"); + + return DomainWrapper.join(templates); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/ListEvents.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/ListEvents.java new file mode 100644 index 0000000000..a8680d8154 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/ListEvents.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.event; + +import org.jclouds.abiquo.domain.event.Event; +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.event.internal.ListEventsImpl; + +import com.google.inject.ImplementedBy; + +/** + * List events. + * + * @author Vivien Mahé + */ +@ImplementedBy(ListEventsImpl.class) +public interface ListEvents extends ListRootEntities +{ + Iterable execute(EventOptions options); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/internal/ListEventsImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/internal/ListEventsImpl.java new file mode 100644 index 0000000000..42ca29c927 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/event/internal/ListEventsImpl.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.event.internal; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.event.Event; +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.abiquo.strategy.event.ListEvents; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.event.EventsDto; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +public class ListEventsImpl implements ListEvents +{ + // This strategy does not have still an Executor instance because the current methods call + // single api methods + + protected final RestContext context; + + @Inject + ListEventsImpl(final RestContext context) + { + this.context = context; + } + + @Override + public Iterable execute() + { + EventsDto result = context.getApi().getEventApi().listEvents(); + return wrap(context, Event.class, result.getCollection()); + } + + @Override + public Iterable execute(final EventOptions options) + { + EventsDto result = context.getApi().getEventApi().listEvents(options); + return wrap(context, Event.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListDatacenters.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListDatacenters.java new file mode 100644 index 0000000000..c92869db46 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListDatacenters.java @@ -0,0 +1,39 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.infrastructure; + +import java.util.List; + +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.infrastructure.internal.ListDatacentersImpl; + +import com.google.inject.ImplementedBy; + +/** + * List datacenters. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListDatacentersImpl.class) +public interface ListDatacenters extends ListRootEntities +{ + Iterable execute(List datacenterIds); +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java new file mode 100644 index 0000000000..4fec2b90a6 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.infrastructure; + +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.strategy.ListRootEntities; +import org.jclouds.abiquo.strategy.infrastructure.internal.ListMachinesImpl; + +import com.google.inject.ImplementedBy; + +/** + * List machines in each datacenter and rack. + * + * @author Ignasi Barrera + */ +@ImplementedBy(ListMachinesImpl.class) +public interface ListMachines extends ListRootEntities +{ + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImpl.java new file mode 100644 index 0000000000..0ba7056e1c --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImpl.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.infrastructure.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.strategy.infrastructure.ListDatacenters; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; +import com.google.inject.Inject; + +/** + * List datacenters. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Singleton +public class ListDatacentersImpl implements ListDatacenters +{ + + protected final RestContext context; + + protected final ExecutorService userExecutor; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject(optional = true) + @Named(Constants.PROPERTY_REQUEST_TIMEOUT) + protected Long maxTime; + + @Inject + ListDatacentersImpl(final RestContext context, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) + { + this.context = context; + this.userExecutor = checkNotNull(userExecutor, "userExecutor"); + } + + @Override + public Iterable execute() + { + DatacentersDto result = context.getApi().getInfrastructureApi().listDatacenters(); + return wrap(context, Datacenter.class, result.getCollection()); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + + @Override + public Iterable execute(final List datacenterIds) + { + // Find virtual datacenters in concurrent requests + return listConcurrentDatacenters(datacenterIds); + } + + private Iterable listConcurrentDatacenters(final List ids) + { + Iterable dcs = + transformParallel(ids, new Function>() + { + @Override + public Future apply(final Integer input) + { + return context.getAsyncApi().getInfrastructureApi().getDatacenter(input); + } + }, userExecutor, maxTime, logger, "getting datacenters"); + + return DomainWrapper.wrap(context, Datacenter.class, Lists.newArrayList(dcs)); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImpl.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImpl.java new file mode 100644 index 0000000000..362d25c861 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImpl.java @@ -0,0 +1,133 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.infrastructure.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.strategy.infrastructure.ListDatacenters; +import org.jclouds.abiquo.strategy.infrastructure.ListMachines; +import org.jclouds.logging.Logger; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.RacksDto; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * List machines in each datacenter and rack. + * + * @author Ignasi Barrera + */ +@Singleton +public class ListMachinesImpl implements ListMachines +{ + protected RestContext context; + + protected ListDatacenters listDatacenters; + + protected final ExecutorService userExecutor; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject(optional = true) + @Named(Constants.PROPERTY_REQUEST_TIMEOUT) + protected Long maxTime; + + @Inject + ListMachinesImpl(final RestContext context, + @Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor, + final ListDatacenters listDatacenters) + { + super(); + this.context = checkNotNull(context, "context"); + this.listDatacenters = checkNotNull(listDatacenters, "listDatacenters"); + this.userExecutor = checkNotNull(userExecutor, "userExecutor"); + } + + @Override + public Iterable execute() + { + // Find machines in concurrent requests + Iterable datacenters = listDatacenters.execute(); + Iterable racks = listConcurrentRacks(datacenters); + Iterable machines = listConcurrentMachines(racks); + + return wrap(context, Machine.class, machines); + } + + @Override + public Iterable execute(final Predicate selector) + { + return filter(execute(), selector); + } + + private Iterable listConcurrentRacks(final Iterable datacenters) + { + Iterable racks = + transformParallel(datacenters, new Function>() + { + @Override + public Future apply(final Datacenter input) + { + return context.getAsyncApi().getInfrastructureApi() + .listRacks(input.unwrap()); + } + }, userExecutor, maxTime, logger, "getting racks"); + + return DomainWrapper.join(racks); + } + + private Iterable listConcurrentMachines(final Iterable racks) + { + Iterable machines = + transformParallel(racks, new Function>() + { + @Override + public Future apply(final RackDto input) + { + return context.getAsyncApi().getInfrastructureApi().listMachines(input); + } + }, userExecutor, maxTime, logger, "getting machines"); + + return DomainWrapper.join(machines); + } + +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentEnterprise.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentEnterprise.java new file mode 100644 index 0000000000..727d438278 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentEnterprise.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.suppliers; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.abiquo.domain.enterprise.Enterprise; + +import com.google.common.base.Supplier; + +/** + * Gets the current enterprise. + * + * @author Ignasi Barrera + */ +public class GetCurrentEnterprise implements Supplier +{ + private final GetCurrentUser currentUserSupplier; + + @Inject + public GetCurrentEnterprise(final GetCurrentUser currentUserSupplier) + { + this.currentUserSupplier = checkNotNull(currentUserSupplier, "currentUserSupplier"); + } + + @Override + public Enterprise get() + { + return currentUserSupplier.get().getEnterprise(); + } +} diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentUser.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentUser.java new file mode 100644 index 0000000000..185a660c35 --- /dev/null +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/suppliers/GetCurrentUser.java @@ -0,0 +1,57 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.suppliers; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; + +import javax.inject.Inject; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.rest.RestContext; + +import com.abiquo.server.core.enterprise.UserDto; +import com.google.common.base.Supplier; + +/** + * Gets the current user. + * + * @author Ignasi Barrera + */ +public class GetCurrentUser implements Supplier +{ + private RestContext context; + + @Inject + public GetCurrentUser(final RestContext context) + { + this.context = checkNotNull(context, "context"); + } + + @Override + public User get() + { + UserDto user = context.getApi().getAdminApi().getCurrentUser(); + return wrap(context, User.class, user); + } + +} diff --git a/labs/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..642f443f14 --- /dev/null +++ b/labs/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.abiquo.AbiquoApiMetadata \ No newline at end of file diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java new file mode 100644 index 0000000000..2e6486dc1e --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.apis.Apis; +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link AbiquoApiMetadata} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AbiquoApiMetadataTest") +public class AbiquoApiMetadataTest extends BaseComputeServiceApiMetadataTest +{ + + public AbiquoApiMetadataTest() + { + super(new AbiquoApiMetadata()); + } + + public void testAbiquoApiRegistered() + { + ApiMetadata api = Apis.withId("abiquo"); + + assertNotNull(api); + assertTrue(api instanceof AbiquoApiMetadata); + assertEquals(api.getId(), "abiquo"); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java new file mode 100644 index 0000000000..8f99cba17b --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java @@ -0,0 +1,95 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo; + +import static org.testng.Assert.assertNotNull; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import org.jclouds.abiquo.features.BaseAbiquoAsyncApiTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.inject.TypeLiteral; + +/** + * Tests asynchronous and synchronous API delegates. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AbiquoDelegateApiTest") +public class AbiquoDelegateApiTest extends BaseAbiquoAsyncApiTest +{ + private AbiquoAsyncApi asyncApi; + + private AbiquoApi syncApi; + + @BeforeClass + @Override + protected void setupFactory() throws IOException + { + super.setupFactory(); + asyncApi = injector.getInstance(AbiquoAsyncApi.class); + syncApi = injector.getInstance(AbiquoApi.class); + } + + public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, + ExecutionException + { + assertNotNull(syncApi.getAdminApi()); + assertNotNull(syncApi.getConfigApi()); + assertNotNull(syncApi.getInfrastructureApi()); + assertNotNull(syncApi.getEnterpriseApi()); + assertNotNull(syncApi.getCloudApi()); + assertNotNull(syncApi.getVirtualMachineTemplateApi()); + assertNotNull(syncApi.getTaskApi()); + assertNotNull(syncApi.getPricingApi()); + } + + public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, + ExecutionException + { + assertNotNull(asyncApi.getAdminApi()); + assertNotNull(asyncApi.getConfigApi()); + assertNotNull(asyncApi.getInfrastructureApi()); + assertNotNull(asyncApi.getEnterpriseApi()); + assertNotNull(asyncApi.getCloudApi()); + assertNotNull(asyncApi.getVirtualMachineTemplateApi()); + assertNotNull(asyncApi.getTaskApi()); + assertNotNull(asyncApi.getPricingApi()); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } + + @Override + protected void checkFilters(final HttpRequest request) + { + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java new file mode 100644 index 0000000000..960076a572 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java @@ -0,0 +1,63 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link AppendToPath} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AppendToPathTest") +public class AppendToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + AppendToPath binder = new AppendToPath(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + public void testBindString() + { + AppendToPath binder = new AppendToPath(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, "expanded/path"); + assertEquals(newRequest.getRequestLine(), "GET http://localhost/expanded/path HTTP/1.1"); + } + + public void testBindNumber() + { + AppendToPath binder = new AppendToPath(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, 57); + assertEquals(newRequest.getRequestLine(), "GET http://localhost/57 HTTP/1.1"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java new file mode 100644 index 0000000000..5ef0effe49 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; + +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BindLinkToPathAndAcceptHeader} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindLinkToPathAndAcceptHeaderTest") +public class BindLinkToPathAndAcceptHeaderTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindLinkToPathAndAcceptHeader binder = new BindLinkToPathAndAcceptHeader(); + binder.addHeader(null, HttpHeaders.ACCEPT, null); + } + + public void testAddHeader() + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + + BindLinkToPathAndAcceptHeader binder = new BindLinkToPathAndAcceptHeader(); + HttpRequest updatedRequest = + binder.addHeader(request, HttpHeaders.ACCEPT, "application/vnd.abiquo.datacenters+xml"); + + String accept = updatedRequest.getFirstHeaderOrNull(HttpHeaders.ACCEPT); + + assertNotNull(accept); + assertEquals(accept, "application/vnd.abiquo.datacenters+xml"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java new file mode 100644 index 0000000000..55e684053f --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; + +/** + * Unit tests for the {@link BindLinkToPath} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindLinkToPathTest") +public class BindLinkToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testGetNewEnpointNullInput() + { + BindLinkToPath binder = new BindLinkToPath(); + binder.getNewEndpoint(null, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetNewEnpointInvalidInput() + { + BindLinkToPath binder = new BindLinkToPath(); + binder.getNewEndpoint(null, new Object()); + } + + public void testGetNewEnpoint() + { + BindLinkToPath binder = new BindLinkToPath(); + assertEquals(binder.getNewEndpoint(null, new RESTLink("edit", "http://foo/bar")), + "http://foo/bar"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java new file mode 100644 index 0000000000..066d38e083 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java @@ -0,0 +1,204 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders; + +import static org.testng.Assert.assertEquals; + +import java.lang.reflect.Method; +import java.net.URI; + +import javax.ws.rs.GET; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; + +import org.jclouds.abiquo.rest.annotations.EndpointLink; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindException; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.google.common.collect.ImmutableList; + +/** + * Unit tests for the {@link BindToPath} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindToPathTest") +public class BindToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullRequest() throws SecurityException, NoSuchMethodException + { + BindToPath binder = new BindToPath(); + binder.bindToRequest(null, new Object()); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidRequestType() throws SecurityException, NoSuchMethodException + { + BindToPath binder = new BindToPath(); + binder.bindToRequest( + HttpRequest.builder().method("m").endpoint("http://localhost").build(), new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() throws SecurityException, NoSuchMethodException + { + Method withEndpointLink = + TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(new TestDto())) + .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); + + BindToPath binder = new BindToPath(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidInputType() throws SecurityException, NoSuchMethodException + { + Method withEndpointLink = + TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(new TestDto())) + .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); + + BindToPath binder = new BindToPath(); + binder.bindToRequest(request, new Object()); + } + + @Test(expectedExceptions = BindException.class) + public void testAnnotationNotPresent() throws SecurityException, NoSuchMethodException + { + TestDto dto = new TestDto(); + Method withoutEndpointLink = + TestEndpointLink.class.getMethod("withoutEndpointLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withoutEndpointLink).args(ImmutableList. of(dto)) + .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); + + BindToPath binder = new BindToPath(); + binder.bindToRequest(request, dto); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testLinkNotPresent() throws SecurityException, NoSuchMethodException + { + TestDto dto = new TestDto(); + Method withUnexistingLink = + TestEndpointLink.class.getMethod("withUnexistingLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withUnexistingLink).args(ImmutableList. of(dto)) + .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); + + BindToPath binder = new BindToPath(); + binder.bindToRequest(request, dto); + } + + public void testBindWithoutParameters() throws SecurityException, NoSuchMethodException + { + TestDto dto = new TestDto(); + Method withEndpointLink = + TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(dto)) + .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); + + BindToPath binder = new BindToPath(); + GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto); + assertEquals(newRequest.getRequestLine(), "GET http://linkuri HTTP/1.1"); + } + + public void testBindWithQueryParameters() throws SecurityException, NoSuchMethodException + { + TestDto dto = new TestDto(); + Method withEndpointLink = + TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(dto)) + .method(HttpMethod.GET).endpoint(URI.create("http://localhost?param=value")) + .build(); + + BindToPath binder = new BindToPath(); + GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto); + assertEquals(newRequest.getRequestLine(), "GET http://linkuri?param=value HTTP/1.1"); + } + + public void testBindWithQueryAndMatrixParameters() throws SecurityException, + NoSuchMethodException + { + TestDto dto = new TestDto(); + Method withEndpointLink = + TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestEndpointLink.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(dto)) + .method(HttpMethod.GET) + .endpoint(URI.create("http://localhost?param=value;matrix=value2")).build(); + + BindToPath binder = new BindToPath(); + GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto); + assertEquals(newRequest.getRequestLine(), + "GET http://linkuri?param=value;matrix=value2 HTTP/1.1"); + } + + static interface TestEndpointLink + { + @GET + void withEndpointLink(@EndpointLink("edit") TestDto dto); + + @GET + void withUnexistingLink(@EndpointLink("unexisting") TestDto dto); + + @GET + void withoutEndpointLink(TestDto dto); + } + + static class TestDto extends SingleResourceTransportDto + { + private static final long serialVersionUID = 1L; + + public TestDto() + { + addLink(new RESTLink("edit", "http://linkuri")); + } + + @Override + public String getMediaType() + { + return MediaType.APPLICATION_XML; + } + + @Override + public String getBaseMediaType() + { + return MediaType.APPLICATION_XML; + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java new file mode 100644 index 0000000000..9ed0433492 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java @@ -0,0 +1,95 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; + +/** + * Unit tests for the {@link BindHardDiskRefsToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindHardDiskRefsToPayloadTest") +public class BindHardDiskRefsToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindEmptyArray() throws IOException + { + BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new DiskManagementDto[] {}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } + + public void testBindSingleHardDisk() throws IOException + { + DiskManagementDto hardDisk = CloudResources.hardDiskPut(); + BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new DiskManagementDto[] {hardDisk}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } + + public void testBindMultipleHardDisks() throws IOException + { + DiskManagementDto hardDisk = CloudResources.hardDiskPut(); + BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new DiskManagementDto[] {hardDisk, hardDisk}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java new file mode 100644 index 0000000000..30b22dfe93 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; + +/** + * Unit tests for the {@link BindIpRefToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindIpRefToPayloadTest") +public class BindIpRefToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindIpRef() throws IOException + { + PrivateIpDto ip = NetworkResources.privateIpPut(); + RESTLink selfLink = ip.searchLink("self"); + BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, ip); + assertPayloadEquals( + request.getPayload(), + withHeader(""), LinksDto.class); + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java new file mode 100644 index 0000000000..55d3016afa --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.AbstractIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; + +/** + * Unit tests for the {@link BindIpRefsToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindIpRefsToPayloadTest") +public class BindIpRefsToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindEmptyArray() throws IOException + { + BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new AbstractIpDto[] {}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } + + public void testBindSingleIp() throws IOException + { + PrivateIpDto ip = NetworkResources.privateIpPut(); + BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new AbstractIpDto[] {ip}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } + + public void testBindMultipleIps() throws IOException + { + PrivateIpDto ip = NetworkResources.privateIpPut(); + BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new AbstractIpDto[] {ip, ip}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java new file mode 100644 index 0000000000..aba9fec2d1 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.testng.Assert.assertEquals; + +import java.lang.reflect.Method; +import java.net.URI; + +import javax.ws.rs.HttpMethod; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.abiquo.features.CloudAsyncApi; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.google.common.collect.ImmutableList; + +/** + * Unit tests for the {@link BindMoveVolumeToPath} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindMoveVolumeToPathTest") +public class BindMoveVolumeToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() throws SecurityException, NoSuchMethodException + { + BindMoveVolumeToPath binder = new BindMoveVolumeToPath(); + binder.getNewEndpoint(generatedHttpRequest(), null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidInputType() throws SecurityException, NoSuchMethodException + { + BindMoveVolumeToPath binder = new BindMoveVolumeToPath(); + binder.getNewEndpoint(generatedHttpRequest(), new Object()); + } + + public void testGetNewEndpoint() throws SecurityException, NoSuchMethodException + { + BindMoveVolumeToPath binder = new BindMoveVolumeToPath(); + String newEndpoint = + binder.getNewEndpoint(generatedHttpRequest(), CloudResources.volumePut()); + assertEquals(newEndpoint, + "http://localhost/api/cloud/virtualdatacenters/1/volumes/1/action/move"); + } + + private static GeneratedHttpRequest generatedHttpRequest() throws SecurityException, + NoSuchMethodException + { + Method withEndpointLink = + CloudAsyncApi.class.getMethod("moveVolume", VolumeManagementDto.class, + VirtualDatacenterDto.class); + return GeneratedHttpRequest + .builder() + .declaring(CloudAsyncApi.class) + .javaMethod(withEndpointLink) + .args( + ImmutableList. of(CloudResources.volumePut(), + CloudResources.virtualDatacenterPut())).method(HttpMethod.POST) + .endpoint(URI.create("http://localhost")).build(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java new file mode 100644 index 0000000000..15718cda1a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java @@ -0,0 +1,158 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.NoSuchElementException; + +import javax.ws.rs.GET; +import javax.ws.rs.HttpMethod; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.google.common.collect.ImmutableList; + +/** + * Unit tests for the {@link BindNetworkConfigurationRefToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindNetworkConfigurationRefToPayloadTest") +public class BindNetworkConfigurationRefToPayloadTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullRequest() throws SecurityException, NoSuchMethodException + { + BindNetworkConfigurationRefToPayload binder = + new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); + binder.bindToRequest(null, new Object()); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidRequestType() throws SecurityException, NoSuchMethodException + { + BindNetworkConfigurationRefToPayload binder = + new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); + + binder.bindToRequest( + HttpRequest.builder().method("m").endpoint("http://localhost").build(), new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() throws SecurityException, NoSuchMethodException + { + VirtualMachineDto vm = CloudResources.virtualMachinePut(); + + Method method = + TestNetworkConfig.class.getMethod("withAll", VirtualMachineDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestNetworkConfig.class).javaMethod(method) + .args(ImmutableList. of(vm, null)).method(HttpMethod.GET) + .endpoint(URI.create("http://localhost")).build(); + + BindNetworkConfigurationRefToPayload binder = + new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() throws SecurityException, NoSuchMethodException + { + VirtualMachineDto vm = CloudResources.virtualMachinePut(); + Object network = new Object(); + + Method method = + TestNetworkConfig.class.getMethod("withAll", VirtualMachineDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestNetworkConfig.class).javaMethod(method) + .args(ImmutableList. of(vm, network)).method(HttpMethod.GET) + .endpoint(URI.create("http://localhost")).build(); + + BindNetworkConfigurationRefToPayload binder = + new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); + binder.bindToRequest(request, network); + } + + @Test(expectedExceptions = NoSuchElementException.class) + public void testBindNetworkConfigurationRefWithoutVirtualMachine() throws SecurityException, + NoSuchMethodException + { + VLANNetworkDto network = NetworkResources.privateNetworkPut(); + + Method method = + TestNetworkConfig.class.getMethod("withoutVirtualMachine", VLANNetworkDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestNetworkConfig.class).javaMethod(method) + .args(ImmutableList. of(network)).method(HttpMethod.GET) + .endpoint(URI.create("http://localhost")).build(); + + BindNetworkConfigurationRefToPayload binder = + new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); + binder.bindToRequest(request, network); + } + + public void testBindNetworkConfigurationRef() throws SecurityException, NoSuchMethodException, + IOException + { + VirtualMachineDto vm = CloudResources.virtualMachinePut(); + VLANNetworkDto network = NetworkResources.privateNetworkPut(); + + Method method = + TestNetworkConfig.class.getMethod("withAll", VirtualMachineDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(TestNetworkConfig.class).javaMethod(method) + .args(ImmutableList. of(vm, network)).method(HttpMethod.GET) + .endpoint(URI.create("http://localhost")).build(); + + BindNetworkConfigurationRefToPayload binder = + new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); + + String configLink = vm.searchLink("configurations").getHref() + "/" + network.getId(); + + GeneratedHttpRequest newRequest = binder.bindToRequest(request, network); + assertPayloadEquals(newRequest.getPayload(), withHeader(""), LinksDto.class); + } + + static interface TestNetworkConfig + { + @GET + void withoutVirtualMachine(VLANNetworkDto network); + + @GET + void withAll(VirtualMachineDto virtualMachine, VLANNetworkDto network); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java new file mode 100644 index 0000000000..d4d896ff1e --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Unit tests for the {@link BindNetworkRefToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindNetworkRefToPayloadTest") +public class BindNetworkRefToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindNetworkRef() throws IOException + { + VLANNetworkDto network = NetworkResources.privateNetworkPut(); + BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, network); + assertPayloadEquals(request.getPayload(), withHeader(""), + LinksDto.class); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java new file mode 100644 index 0000000000..208b33d2a4 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Unit tests for the {@link BindUnmanagedIpRefToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindUnmanagedIpRefToPayloadTest") +public class BindUnmanagedIpRefToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindUnmanagedIpRefToPayload binder = + new BindUnmanagedIpRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindUnmanagedIpRefToPayload binder = + new BindUnmanagedIpRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindUnmanagedNetworkIpRef() throws IOException + { + VLANNetworkDto network = NetworkResources.unmanagedNetworkPut(); + RESTLink ipsLink = network.searchLink("ips"); + BindUnmanagedIpRefToPayload binder = + new BindUnmanagedIpRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, network); + assertPayloadEquals(request.getPayload(), + withHeader(""), LinksDto.class); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java new file mode 100644 index 0000000000..12204d4a6f --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; + +/** + * Unit tests for the {@link BindVirtualDatacenterRefToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindVirtualDatacenterRefToPayloadTest") +public class BindVirtualDatacenterRefToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindVirtualDatacenterRefToPayload binder = + new BindVirtualDatacenterRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindVirtualDatacenterRefToPayload binder = + new BindVirtualDatacenterRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindSingleVolume() throws IOException + { + VirtualDatacenterDto vdc = CloudResources.virtualDatacenterPut(); + BindVirtualDatacenterRefToPayload binder = + new BindVirtualDatacenterRefToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, vdc); + assertPayloadEquals(request.getPayload(), withHeader(""), + LinksDto.class); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java new file mode 100644 index 0000000000..8aef3a3464 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java @@ -0,0 +1,95 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.cloud; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; +import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.http.HttpRequest; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Unit tests for the {@link BindVolumeRefsToPayload} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindVolumeRefsToPayloadTest") +public class BindVolumeRefsToPayloadTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindEmptyArray() throws IOException + { + BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new VolumeManagementDto[] {}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } + + public void testBindSingleVolume() throws IOException + { + VolumeManagementDto volume = CloudResources.volumePut(); + BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new VolumeManagementDto[] {volume}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } + + public void testBindMultipleVolumes() throws IOException + { + VolumeManagementDto volume = CloudResources.volumePut(); + BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + request = binder.bindToRequest(request, new VolumeManagementDto[] {volume, volume}); + assertPayloadEquals(request.getPayload(), withHeader(""), LinksDto.class); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java new file mode 100644 index 0000000000..e8ba7e0e3f --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.abiquo.functions.infrastructure.ParseMachineId; +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.MachineDto; + +/** + * Unit tests for the {@link AppendMachineIdToPath} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AppendMachineIdToPathTest") +public class AppendMachineIdToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testGetValueWithNullInput() + { + AppendMachineIdToPath binder = new AppendMachineIdToPath(new ParseMachineId()); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.getValue(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetValueWithInvalidInput() + { + AppendMachineIdToPath binder = new AppendMachineIdToPath(new ParseMachineId()); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.getValue(request, new Object()); + } + + public void testGetValue() + { + AppendMachineIdToPath binder = new AppendMachineIdToPath(new ParseMachineId()); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + + MachineDto machine = new MachineDto(); + machine.setId(5); + assertEquals(binder.getValue(request, machine), "5"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java new file mode 100644 index 0000000000..50f20fac30 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.abiquo.functions.infrastructure.ParseRemoteServiceType; +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.RemoteServiceType; + +/** + * Unit tests for the {@link AppendRemoteServiceTypeToPath} binder. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AppendRemoteServiceTypeToPathTest") +public class AppendRemoteServiceTypeToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testGetValueWithNullInput() + { + AppendRemoteServiceTypeToPath binder = + new AppendRemoteServiceTypeToPath(new ParseRemoteServiceType()); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.getValue(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetValueWithInvalidInput() + { + AppendRemoteServiceTypeToPath binder = + new AppendRemoteServiceTypeToPath(new ParseRemoteServiceType()); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.getValue(request, new Object()); + } + + public void testGetValue() + { + AppendRemoteServiceTypeToPath binder = + new AppendRemoteServiceTypeToPath(new ParseRemoteServiceType()); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + + assertEquals(binder.getValue(request, RemoteServiceType.VIRTUAL_SYSTEM_MONITOR), + "virtualsystemmonitor"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java new file mode 100644 index 0000000000..47358b6aa9 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure; + +import static org.testng.Assert.assertEquals; + +import java.lang.reflect.Method; +import java.net.URI; + +import javax.ws.rs.HttpMethod; + +import org.jclouds.abiquo.features.InfrastructureAsyncApi; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.google.common.collect.ImmutableList; + +/** + * Unit tests for the {@link BindSupportedDevicesLinkToPath} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindSupportedDevicesLinkToPathTest") +public class BindSupportedDevicesLinkToPathTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testGetNewEnpointNullInput() + { + BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); + binder.getNewEndpoint(null, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetNewEnpointInvalidInput() + { + BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); + binder.getNewEndpoint(null, new Object()); + } + + public void testGetNewEnpoint() throws Exception + { + DatacenterDto datacenter = new DatacenterDto(); + datacenter.addLink(new RESTLink("devices", "http://foo/bar")); + + BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); + + Method withEndpointLink = + InfrastructureAsyncApi.class.getMethod("listSupportedStorageDevices", + DatacenterDto.class); + + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(InfrastructureAsyncApi.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(datacenter)) + .method(HttpMethod.GET).endpoint(URI.create("http://foo/bar")).build(); + + assertEquals(binder.getNewEndpoint(request, datacenter), "http://foo/bar/action/supported"); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testGetNewEnpointWithoutLink() throws Exception + { + DatacenterDto datacenter = new DatacenterDto(); + + BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); + + Method withEndpointLink = + InfrastructureAsyncApi.class.getMethod("listSupportedStorageDevices", + DatacenterDto.class); + + GeneratedHttpRequest request = + GeneratedHttpRequest.builder().declaring(InfrastructureAsyncApi.class) + .javaMethod(withEndpointLink).args(ImmutableList. of(datacenter)) + .method(HttpMethod.GET).endpoint(URI.create("http://foo/bar")).build(); + + assertEquals(binder.getNewEndpoint(request, datacenter), "http://foo/bar/action/supported"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java new file mode 100644 index 0000000000..16920db191 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure.ucs; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.LogicServerDto; + +/** + * Unit tests for the {@link BindLogicServerParameters} binder. + * + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "BindLogicServerParametersTest") +public class BindLogicServerParametersTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindLogicServerParameters binder = new BindLogicServerParameters(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindLogicServerParameters binder = new BindLogicServerParameters(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testBindLogicServerWithEmptyName() + { + BindLogicServerParameters binder = new BindLogicServerParameters(); + LogicServerDto dto = new LogicServerDto(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, dto); + } + + public void testBindLogicServer() + { + BindLogicServerParameters binder = new BindLogicServerParameters(); + LogicServerDto dto = new LogicServerDto(); + dto.setName("name"); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, dto); + assertEquals(newRequest.getRequestLine(), "GET http://localhost?lsName=name HTTP/1.1"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java new file mode 100644 index 0000000000..3e47226f13 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.binders.infrastructure.ucs; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.OrganizationDto; + +/** + * Unit tests for the {@link BindOrganizationParameters} binder. + * + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "BindOrganizationParametersTest") +public class BindOrganizationParametersTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + BindOrganizationParameters binder = new BindOrganizationParameters(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() + { + BindOrganizationParameters binder = new BindOrganizationParameters(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testBindLogicServerWithEmptyName() + { + BindOrganizationParameters binder = new BindOrganizationParameters(); + OrganizationDto dto = new OrganizationDto(); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, dto); + } + + public void testBindLogicServer() + { + BindOrganizationParameters binder = new BindOrganizationParameters(); + OrganizationDto dto = new OrganizationDto(); + dto.setDn("org"); + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, dto); + assertEquals(newRequest.getRequestLine(), "GET http://localhost?org=org HTTP/1.1"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java new file mode 100644 index 0000000000..2f016a123c --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java @@ -0,0 +1,140 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute; + +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; +import static org.testng.Assert.assertEquals; + +import java.util.Properties; + +import org.jclouds.Constants; +import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceLiveTest; +import org.jclouds.logging.config.LoggingModule; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Live tests for the Abiquo ComputeService. + * + * @author Ignasi Barrera + */ +@Test(groups = "live", testName = "AbiquoComputeServiceLiveTest", singleThreaded = true) +// Made abstract to avoid executing tests. Since the base class has test configuration, even if we +// disable tests here, or comment them out, the ones in the base class will be executed +public class AbiquoComputeServiceLiveTest extends BaseComputeServiceLiveTest +{ + public AbiquoComputeServiceLiveTest() + { + provider = "abiquo"; + } + + @Override + public void setServiceDefaults() + { + System + .setProperty("test.abiquo.template", + "imageNameMatches=ubuntu_server_ssh_iptables,loginUser=user:abiquo,authenticateSudo=true"); + } + + @Override + protected Properties setupProperties() + { + Properties overrides = super.setupProperties(); + overrides.put(Constants.PROPERTY_MAX_RETRIES, "0"); + overrides.put(Constants.PROPERTY_MAX_REDIRECTS, "0"); + overrides.put("jclouds.timeouts.CloudApi.listVirtualMachines", "60000"); + return overrides; + } + + @Override + protected void initializeContext() + { + super.initializeContext(); + String templateId = buildTemplate(client.templateBuilder()).getImage().getId(); + view.getUtils().getCredentialStore().put("image#" + templateId, loginCredentials); + } + + @Override + protected LoggingModule getLoggingModule() + { + return new SLF4JLoggingModule(); + } + + @Override + protected Module getSshModule() + { + return new JschSshClientModule(); + } + + @Override + public void testListSizes() throws Exception + { + for (Hardware hardware : client.listHardwareProfiles()) + { + assert hardware.getProviderId() != null : hardware; + assert getCores(hardware) > 0 : hardware; + assert hardware.getVolumes().size() >= 0 : hardware; + // There are some small images in Abiquo that have less than 1GB of RAM + // assert hardware.getRam() > 0 : hardware; + assertEquals(hardware.getType(), ComputeType.HARDWARE); + } + } + + @Override + public void testOptionToNotBlock() throws Exception + { + // By default the provider blocks until the node is running + } + + // Abiquo does not set the hostname + @Override + protected void checkResponseEqualsHostname(final ExecResponse execResponse, + final NodeMetadata node) + { + assert node.getHostname() == null : node + " with hostname: " + node.getHostname(); + } + + // Abiquo does not support metadata + @Override + protected void checkUserMetadataInNodeEquals(final NodeMetadata node, + final ImmutableMap userMetadata) + { + assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( + "node userMetadata did not match %s %s", userMetadata, node); + } + + // Abiquo does not support tags + @Override + protected void checkTagsInNodeEquals(final NodeMetadata node, final ImmutableSet tags) + { + assert node.getTags().equals(ImmutableSet. of()) : String.format( + "node tags did not match %s %s", tags, node); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java new file mode 100644 index 0000000000..2edbc1fa1f --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link DatacenterToLocation} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "DatacenterToLocationTest") +public class DatacenterToLocationTest +{ + @SuppressWarnings("unchecked") + public void testDatacenterToLocation() + { + RestContext context = EasyMock.createMock(RestContext.class); + DatacenterToLocation function = new DatacenterToLocation(); + + Datacenter datacenter = Datacenter.builder(context).name("dc").location("New York").build(); + datacenter.unwrap().setId(5); + Location location = function.apply(datacenter); + + assertEquals(location.getId(), "5"); + assertEquals(location.getScope(), LocationScope.ZONE); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java new file mode 100644 index 0000000000..ea31bbc06d --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.domain.NodeMetadata.Status; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualMachineState; + +/** + * Unit tests for the {@link VirtualMachineStateToNodeState} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineStateToNodeStateTest") +public class VirtualMachineStateToNodeStateTest +{ + public void testVirtualMachineStateToNodeState() + { + VirtualMachineStateToNodeState function = new VirtualMachineStateToNodeState(); + + assertEquals(function.apply(VirtualMachineState.ALLOCATED), Status.PENDING); + assertEquals(function.apply(VirtualMachineState.LOCKED), Status.PENDING); + assertEquals(function.apply(VirtualMachineState.CONFIGURED), Status.PENDING); + assertEquals(function.apply(VirtualMachineState.ON), Status.RUNNING); + assertEquals(function.apply(VirtualMachineState.OFF), Status.SUSPENDED); + assertEquals(function.apply(VirtualMachineState.PAUSED), Status.SUSPENDED); + assertEquals(function.apply(VirtualMachineState.NOT_ALLOCATED), Status.TERMINATED); + assertEquals(function.apply(VirtualMachineState.UNKNOWN), Status.UNRECOGNIZED); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardwareTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardwareTest.java new file mode 100644 index 0000000000..3c6d812a80 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToHardwareTest.java @@ -0,0 +1,173 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Volume; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; + +/** + * Unit tests for the {@link VirtualMachineTemplateToHardware} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineTemplateToHardwareTest") +public class VirtualMachineTemplateToHardwareTest +{ + @SuppressWarnings("unchecked") + public void testVirtualMachineTemplateToHardware() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToHardware function = new VirtualMachineTemplateToHardware(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + dto.setHdRequired(50L * 1024 * 1024 * 1024); // 50 GB + dto.setCpuRequired(5); + dto.setRamRequired(2048); + dto.addLink(new RESTLink("edit", "http://foo/bar")); + + Hardware hardware = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertEquals(hardware.getId(), dto.getId().toString()); + assertEquals(hardware.getName(), dto.getName()); + assertEquals(hardware.getUri(), URI.create("http://foo/bar")); + + assertEquals(hardware.getRam(), dto.getRamRequired()); + assertEquals(hardware.getProcessors().size(), 1); + assertEquals(hardware.getProcessors().get(0).getCores(), (double) dto.getCpuRequired()); + assertEquals(hardware.getProcessors().get(0).getSpeed(), + VirtualMachineTemplateToHardware.DEFAULT_CORE_SPEED); + + assertEquals(hardware.getVolumes().size(), 1); + assertEquals(hardware.getVolumes().get(0).getSize(), 50F); + assertEquals(hardware.getVolumes().get(0).getType(), Volume.Type.LOCAL); + assertEquals(hardware.getVolumes().get(0).isBootDevice(), true); + assertEquals(hardware.getVolumes().get(0).isDurable(), false); + } + + @SuppressWarnings("unchecked") + public void testConvertWithoutEditLink() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToHardware function = new VirtualMachineTemplateToHardware(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + dto.setHdRequired(50L * 1024 * 1024 * 1024); // 50 GB + dto.setCpuRequired(5); + dto.setRamRequired(2048); + + Hardware hardware = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertNull(hardware.getUri()); + } + + @SuppressWarnings("unchecked") + @Test(expectedExceptions = NullPointerException.class) + public void testConvertWithoutId() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToHardware function = new VirtualMachineTemplateToHardware(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + } + + @SuppressWarnings("unchecked") + public void testConvertWithoutCpu() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToHardware function = new VirtualMachineTemplateToHardware(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + dto.setHdRequired(50L * 1024 * 1024 * 1024); // 50 GB + dto.setRamRequired(2048); + + Hardware hardware = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertEquals(hardware.getProcessors().size(), 1); + assertEquals(hardware.getProcessors().get(0).getCores(), 0D); + } + + @SuppressWarnings("unchecked") + public void testConvertWithoutRam() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToHardware function = new VirtualMachineTemplateToHardware(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + dto.setHdRequired(50L * 1024 * 1024 * 1024); // 50 GB + dto.setCpuRequired(5); + + Hardware hardware = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertEquals(hardware.getRam(), 0); + } + + @SuppressWarnings("unchecked") + public void testConvertWithoutHd() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToHardware function = new VirtualMachineTemplateToHardware(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + dto.setCpuRequired(5); + dto.setRamRequired(2048); + + Hardware hardware = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertEquals(hardware.getVolumes().size(), 1); + assertEquals(hardware.getVolumes().get(0).getSize(), 0F); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java new file mode 100644 index 0000000000..95e79e1006 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java @@ -0,0 +1,99 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; + +/** + * Unit tests for the {@link VirtualMachineTemplateToImage} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineTemplateToImageTest") +public class VirtualMachineTemplateToImageTest +{ + @SuppressWarnings("unchecked") + public void testVirtualMachineTemplateToImage() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToImage function = new VirtualMachineTemplateToImage(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + dto.addLink(new RESTLink("diskfile", "http://foo/bar")); + + Image image = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertEquals(image.getId(), dto.getId().toString()); + assertEquals(image.getName(), dto.getName()); + assertEquals(image.getDescription(), dto.getDescription()); + assertEquals(image.getUri(), URI.create("http://foo/bar")); + assertEquals(image.getOperatingSystem(), + OperatingSystem.builder().description(dto.getName()).build()); + } + + @SuppressWarnings("unchecked") + public void testConvertWithoutDownloadLink() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToImage function = new VirtualMachineTemplateToImage(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + dto.setId(5); + dto.setName("Template"); + dto.setDescription("Template description"); + + Image image = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + + assertNull(image.getUri()); + } + + @SuppressWarnings("unchecked") + @Test(expectedExceptions = NullPointerException.class) + public void testConvertWithoutId() + { + RestContext context = EasyMock.createMock(RestContext.class); + VirtualMachineTemplateToImage function = new VirtualMachineTemplateToImage(); + + // VirtualMachineTemplate domain object does not have a builder, it is read only + VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); + function.apply(wrap(context, VirtualMachineTemplate.class, dto)); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java new file mode 100644 index 0000000000..d29b655776 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java @@ -0,0 +1,245 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.functions; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.ExternalIp; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadata.Status; +import org.jclouds.domain.Location; +import org.jclouds.rest.RestContext; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + +/** + * Unit tests for the {@link VirtualMachineToNodeMetadata} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineToNodeMetadataTest") +public class VirtualMachineToNodeMetadataTest +{ + private VirtualMachineToNodeMetadata function; + + private VirtualMachineWithNodeExtendedDto vm; + + private PrivateIpDto privNic; + + private PublicIpDto pubNic; + + private ExternalIpDto extNic; + + private Hardware hardware; + + @BeforeMethod + public void setup() + { + vm = new VirtualMachineWithNodeExtendedDto(); + vm.setNodeName("VM"); + vm.setName("Internal name"); + vm.setId(5); + vm.setVdrpPort(22); + vm.setRam(2048); + vm.setCpu(2); + vm.setState(VirtualMachineState.ON); + vm.addLink(new RESTLink("edit", "http://foo/bar")); + + privNic = new PrivateIpDto(); + privNic.setIp("192.168.1.2"); + privNic.setMac("2a:6e:40:69:84:e0"); + + pubNic = new PublicIpDto(); + pubNic.setIp("80.80.80.80"); + pubNic.setMac("2a:6e:40:69:84:e1"); + + extNic = new ExternalIpDto(); + extNic.setIp("10.10.10.10"); + extNic.setMac("2a:6e:40:69:84:e2"); + + hardware = new HardwareBuilder() // + .ids("1") // + .build(); + + function = + new VirtualMachineToNodeMetadata(templateToImage(), + templateToHardware(), + stateToNodeState(), + datacenterToLocation()); + } + + public void testVirtualMachineToNodeMetadata() + { + VirtualAppliance vapp = EasyMock.createMock(VirtualAppliance.class); + VirtualMachine mockVm = mockVirtualMachine(vapp); + + NodeMetadata node = function.apply(mockVm); + + verify(mockVm); + + assertEquals(node.getId(), vm.getId().toString()); + assertEquals(node.getUri(), URI.create("http://foo/bar")); + assertEquals(node.getName(), vm.getNodeName()); + assertEquals(node.getGroup(), "VAPP"); + assertEquals(node.getLocation().getId(), "1"); + assertEquals(node.getLocation().getDescription(), "Mock Location"); + assertEquals(node.getImageId(), "1"); + assertEquals(node.getHardware().getId(), "1"); + assertEquals(node.getHardware().getHypervisor(), HypervisorType.VMX_04.name()); + assertEquals(node.getHardware().getId(), "1"); + assertEquals(node.getHardware().getRam(), vm.getRam()); + assertEquals(node.getHardware().getProcessors().get(0).getCores(), (double) vm.getCpu()); + assertEquals(node.getLoginPort(), vm.getVdrpPort()); + assertEquals(node.getPrivateAddresses().size(), 1); + assertEquals(node.getPublicAddresses().size(), 2); + assertEquals(Iterables.get(node.getPrivateAddresses(), 0), privNic.getIp()); + assertEquals(Iterables.get(node.getPublicAddresses(), 0), pubNic.getIp()); + assertEquals(Iterables.get(node.getPublicAddresses(), 1), extNic.getIp()); + } + + private VirtualMachineTemplateToImage templateToImage() + { + VirtualMachineTemplateToImage templateToImage = + EasyMock.createMock(VirtualMachineTemplateToImage.class); + Image image = EasyMock.createMock(Image.class); + + expect(image.getId()).andReturn("1"); + expect(image.getOperatingSystem()).andReturn(null); + expect(templateToImage.apply(anyObject(VirtualMachineTemplate.class))).andReturn(image); + + replay(image); + replay(templateToImage); + + return templateToImage; + } + + private VirtualMachineTemplateToHardware templateToHardware() + { + VirtualMachineTemplateToHardware virtualMachineTemplateToHardware = + EasyMock.createMock(VirtualMachineTemplateToHardware.class); + + expect(virtualMachineTemplateToHardware.apply(anyObject(VirtualMachineTemplate.class))) + .andReturn(hardware); + + replay(virtualMachineTemplateToHardware); + + return virtualMachineTemplateToHardware; + } + + private DatacenterToLocation datacenterToLocation() + { + DatacenterToLocation datacenterToLocation = EasyMock.createMock(DatacenterToLocation.class); + Location location = EasyMock.createMock(Location.class); + + expect(location.getId()).andReturn("1"); + expect(location.getDescription()).andReturn("Mock Location"); + + expect(datacenterToLocation.apply(anyObject(Datacenter.class))).andReturn(location); + + replay(location); + replay(datacenterToLocation); + + return datacenterToLocation; + } + + private VirtualMachineStateToNodeState stateToNodeState() + { + VirtualMachineStateToNodeState stateToNodeState = + EasyMock.createMock(VirtualMachineStateToNodeState.class); + expect(stateToNodeState.apply(anyObject(VirtualMachineState.class))).andReturn( + Status.RUNNING); + replay(stateToNodeState); + return stateToNodeState; + } + + private VirtualDatacenter mockVirtualDatacenter() + { + VirtualDatacenter vdc = EasyMock.createMock(VirtualDatacenter.class); + expect(vdc.getHypervisorType()).andReturn(HypervisorType.VMX_04); + expect(vdc.getDatacenter()).andReturn(null); + replay(vdc); + return vdc; + } + + private VirtualMachineTemplate mockTemplate() + { + return EasyMock.createMock(VirtualMachineTemplate.class); + } + + @SuppressWarnings("unchecked") + private VirtualMachine mockVirtualMachine(final VirtualAppliance vapp) + { + VirtualMachine mockVm = EasyMock.createMock(VirtualMachine.class); + + Ip< ? , ? > mockPrivNic = + wrap(EasyMock.createMock(RestContext.class), PrivateIp.class, privNic); + Ip< ? , ? > mockPubNic = + wrap(EasyMock.createMock(RestContext.class), PublicIp.class, pubNic); + Ip< ? , ? > mockExtNic = + wrap(EasyMock.createMock(RestContext.class), ExternalIp.class, extNic); + + expect(mockVm.getId()).andReturn(vm.getId()); + expect(mockVm.getURI()).andReturn(URI.create(vm.getEditLink().getHref())); + expect(mockVm.getNameLabel()).andReturn(vm.getNodeName()); + expect(mockVm.getTemplate()).andReturn(mockTemplate()); + expect(mockVm.getState()).andReturn(vm.getState()); + expect(mockVm.listAttachedNics()).andReturn( + ImmutableList.> of(mockPubNic, mockPrivNic, mockExtNic)); + expect(mockVm.getVirtualAppliance()).andReturn(vapp); + expect(vapp.getName()).andReturn("VAPP"); + expect(mockVm.getVirtualDatacenter()).andReturn(mockVirtualDatacenter()); + expect(mockVm.getRam()).andReturn(vm.getRam()); + expect(mockVm.getCpu()).andReturn(vm.getCpu()); + + replay(mockVm); + replay(vapp); + + return mockVm; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java new file mode 100644 index 0000000000..7e8496f1f6 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java @@ -0,0 +1,145 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.compute.options; + +import static org.jclouds.abiquo.domain.DomainWrapper.wrap; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Unit tests for the {@link AbiquoTemplateOptions} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AbiquoTemplateOptionsTest") +public class AbiquoTemplateOptionsTest +{ + public void testAs() + { + TemplateOptions options = new AbiquoTemplateOptions(); + assertEquals(options.as(AbiquoTemplateOptions.class), options); + } + + public void testOverrideCores() + { + TemplateOptions options = new AbiquoTemplateOptions().overrideCores(5); + assertEquals(options.as(AbiquoTemplateOptions.class).getOverrideCores(), Integer.valueOf(5)); + } + + public void testOverrideRam() + { + TemplateOptions options = new AbiquoTemplateOptions().overrideRam(2048); + assertEquals(options.as(AbiquoTemplateOptions.class).getOverrideRam(), + Integer.valueOf(2048)); + } + + public void testVncPassword() + { + TemplateOptions options = new AbiquoTemplateOptions().vncPassword("foo"); + assertEquals(options.as(AbiquoTemplateOptions.class).getVncPassword(), "foo"); + } + + public void testVirtualDatacenter() + { + TemplateOptions options = new AbiquoTemplateOptions().virtualDatacenter("foo"); + assertEquals(options.as(AbiquoTemplateOptions.class).getVirtualDatacenter(), "foo"); + } + + @SuppressWarnings("unchecked") + public void testIps() + { + RestContext context = EasyMock.createMock(RestContext.class); + + PrivateIpDto dto1 = new PrivateIpDto(); + dto1.setIp("10.60.0.1"); + PrivateIpDto dto2 = new PrivateIpDto(); + dto2.setIp("10.60.0.2"); + + PrivateIp ip1 = wrap(context, PrivateIp.class, dto1); + PrivateIp ip2 = wrap(context, PrivateIp.class, dto2); + + TemplateOptions options = new AbiquoTemplateOptions().ips(ip1, ip2); + + Ip< ? , ? >[] ips = options.as(AbiquoTemplateOptions.class).getIps(); + assertNotNull(ips); + assertEquals(ips[0].getIp(), "10.60.0.1"); + assertEquals(ips[1].getIp(), "10.60.0.2"); + } + + @SuppressWarnings("unchecked") + public void testGatewayNetwork() + { + RestContext context = EasyMock.createMock(RestContext.class); + + VLANNetworkDto dto = new VLANNetworkDto(); + dto.setAddress("10.0.0.0"); + dto.setMask(24); + dto.setGateway("10.0.0.1"); + dto.setType(NetworkType.INTERNAL); + + PrivateNetwork gateway = wrap(context, PrivateNetwork.class, dto); + + TemplateOptions options = new AbiquoTemplateOptions().gatewayNetwork(gateway); + assertEquals(options.as(AbiquoTemplateOptions.class).getGatewayNetwork(), gateway); + } + + @SuppressWarnings("unchecked") + public void testUnmanagedIps() + { + RestContext context = EasyMock.createMock(RestContext.class); + + VLANNetworkDto dto1 = new VLANNetworkDto(); + dto1.setAddress("10.0.0.0"); + dto1.setMask(24); + dto1.setGateway("10.0.0.1"); + dto1.setType(NetworkType.UNMANAGED); + + VLANNetworkDto dto2 = new VLANNetworkDto(); + dto2.setAddress("10.1.0.0"); + dto2.setMask(24); + dto2.setGateway("10.1.0.1"); + dto2.setType(NetworkType.UNMANAGED); + + UnmanagedNetwork net1 = wrap(context, UnmanagedNetwork.class, dto1); + UnmanagedNetwork net2 = wrap(context, UnmanagedNetwork.class, dto2); + + TemplateOptions options = new AbiquoTemplateOptions().unmanagedIps(net1, net2); + + UnmanagedNetwork[] nets = options.as(AbiquoTemplateOptions.class).getUnmanagedIps(); + assertNotNull(nets); + assertEquals(nets[0].getAddress(), "10.0.0.0"); + assertEquals(nets[1].getAddress(), "10.1.0.0"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java new file mode 100644 index 0000000000..c8ba73da03 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.config; + +import static org.testng.Assert.assertNotNull; + +import java.util.concurrent.ScheduledExecutorService; + +import org.jclouds.Constants; +import org.jclouds.abiquo.internal.BaseInjectionTest; +import org.testng.annotations.Test; + +import com.google.inject.Key; +import com.google.inject.name.Names; + +/** + * Unit tests for the {@link SchedulerModule} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "SchedulerModuleTest") +public class SchedulerModuleTest extends BaseInjectionTest +{ + public void testScheduledExecutorIsProvided() + { + assertNotNull(injector.getInstance(Key.get(ScheduledExecutorService.class, + Names.named(Constants.PROPERTY_SCHEDULER_THREADS)))); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java new file mode 100644 index 0000000000..0219fb15f4 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.fail; + +import java.util.Properties; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoLiveApiTest; +import org.testng.annotations.Test; + +/** + * Live integration tests for the Abiquo versioning support. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "AbiquoVersionLiveApiTest") +public class AbiquoVersionLiveApiTest extends BaseAbiquoLiveApiTest +{ + @Override + protected Properties setupProperties() + { + Properties overrides = super.setupProperties(); + overrides.setProperty("abiquo.api-version", "0.0"); + return overrides; + } + + public void testUnsupportedVersion() + { + try + { + view.getAdministrationService().getCurrentUser(); + fail("Unsupported versions in mime types should not be allowed"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.NOT_ACCEPTABLE, "406-NOT-ACCEPTABLE"); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java new file mode 100644 index 0000000000..ac5ae69395 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java @@ -0,0 +1,216 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.abiquo.server.core.enterprise.UserDto; + +/** + * Enterprise domain utilities. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class AdminResources +{ + public static RoleDto rolePost() + { + RoleDto role = new RoleDto(); + role.addLink(new RESTLink("privileges", + "http://localhost/api/admin/roles/1/action/privileges")); + role.setName("HAWAIAN_ADMIN"); + return role; + } + + public static RoleDto rolePut() + { + RoleDto role = rolePost(); + role.setId(1); + role.addLink(new RESTLink("edit", "http://localhost/api/admin/roles/1")); + + return role; + } + + public static String rolePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/roles/1/action/privileges", "privileges")); + buffer.append("false"); + buffer.append("HAWAIAN_ADMIN"); + buffer.append(""); + return buffer.toString(); + } + + public static String rolePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/roles/1/action/privileges", "privileges")); + buffer.append(link("/admin/roles/1", "edit")); + buffer.append("false"); + buffer.append("1"); + buffer.append("HAWAIAN_ADMIN"); + buffer.append(""); + return buffer.toString(); + } + + public static DatacenterLimitsDto datacenterLimitsPost() + { + DatacenterLimitsDto limits = new DatacenterLimitsDto(); + limits.setCpuCountLimits(0, 0); + limits.setHdLimitsInMb(0, 0); + limits.setPublicIPLimits(0, 0); + limits.setRamLimitsInMb(0, 0); + limits.setStorageLimits(0, 0); + limits.setVlansLimits(0, 0); + limits.setRepositoryHardLimitsInMb(0); + limits.setRepositorySoftLimitsInMb(0); + return limits; + } + + public static DatacenterLimitsDto datacenterLimitsPut(final EnterpriseDto enterprise) + { + DatacenterLimitsDto limits = datacenterLimitsPost(); + limits.setId(1); + limits.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/" + + enterprise.getId() + "/limits/1")); + return limits; + } + + public static String datacenterLimitsPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String datacenterLimitsPutPayload(final EnterpriseDto enterprise) + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/enterprises/" + enterprise.getId() + "/limits/1", "edit")); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String userPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/roles/1", "role")); + buffer.append("true"); + buffer.append("ABIQUO"); + buffer.append("A hawaian user"); + buffer.append("abe.joha@aloha.com"); + buffer.append("en_US"); + buffer.append("Aberahama"); + buffer.append("abejo"); + buffer.append("c69a39bd64ffb77ea7ee3369dce742f3"); + buffer.append("Johanson"); + buffer.append(""); + return buffer.toString(); + } + + public static UserDto userPost() + { + UserDto user = new UserDto(); + user.setName("Aberahama"); + user.setSurname("Johanson"); + user.setDescription("A hawaian user"); + user.setEmail("abe.joha@aloha.com"); + user.setNick("abejo"); + user.setAuthType("ABIQUO"); + user.setLocale("en_US"); + user.setActive(true); + user.setPassword("c69a39bd64ffb77ea7ee3369dce742f3"); + user.addLink(new RESTLink("role", "http://localhost/api/admin/roles/1")); + return user; + } + + public static String userPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/roles/1", "role")); + buffer.append(link("/admin/enterprises/1/users/1", "edit")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer + .append(link("/admin/enterprises/1/users/1/action/virtualmachines", "virtualmachines")); + buffer.append("true"); + buffer.append("ABIQUO"); + buffer.append("A hawaian user"); + buffer.append("abe.joha@aloha.com"); + buffer.append("1"); + buffer.append("en_US"); + buffer.append("Aberahama"); + buffer.append("abejo"); + buffer.append("c69a39bd64ffb77ea7ee3369dce742f3"); + buffer.append("Johanson"); + buffer.append(""); + return buffer.toString(); + } + + public static UserDto userPut() + { + UserDto user = userPost(); + user.setId(1); + user.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/1/users/1")); + user.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); + user.addLink(new RESTLink("virtualmachines", + "http://localhost/api/admin/enterprises/1/users/1/action/virtualmachines")); + return user; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java new file mode 100644 index 0000000000..b605f9f164 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/CloudResources.java @@ -0,0 +1,529 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.VolumeState; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.abiquo.server.core.cloud.VirtualMachineStateDto; +import com.abiquo.server.core.cloud.VirtualMachineTaskDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Cloud domain utilities. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class CloudResources +{ + public static VirtualDatacenterDto virtualDatacenterPost() + { + VirtualDatacenterDto virtualDatacenter = new VirtualDatacenterDto(); + virtualDatacenter.setName("VDC"); + virtualDatacenter.setHypervisorType(HypervisorType.KVM); + virtualDatacenter.setVlan(NetworkResources.vlanPost()); + return virtualDatacenter; + } + + public static VirtualApplianceDto virtualAppliancePost() + { + VirtualApplianceDto virtualAppliance = new VirtualApplianceDto(); + virtualAppliance.setName("VA"); + return virtualAppliance; + } + + public static VirtualMachineDto virtualMachinePost() + { + VirtualMachineDto virtualMachine = new VirtualMachineDto(); + virtualMachine.setName("VM"); + return virtualMachine; + } + + public static VirtualDatacenterDto virtualDatacenterPut() + { + VirtualDatacenterDto virtualDatacenter = virtualDatacenterPost(); + virtualDatacenter.setId(1); + virtualDatacenter.addLink(new RESTLink("datacenter", + "http://localhost/api/admin/datacenters/1")); + virtualDatacenter.addLink(new RESTLink("disks", + "http://localhost/api/cloud/virtualdatacenters/1/disks")); + virtualDatacenter.addLink(new RESTLink("enterprise", + "http://localhost/api/admin/enterprises/1")); + virtualDatacenter.addLink(new RESTLink("edit", + "http://localhost/api/cloud/virtualdatacenters/1")); + virtualDatacenter.addLink(new RESTLink("tiers", + "http://localhost/api/cloud/virtualdatacenters/1/tiers")); + virtualDatacenter.addLink(new RESTLink("virtualappliances", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances")); + virtualDatacenter.addLink(new RESTLink("volumes", + "http://localhost/api/cloud/virtualdatacenters/1/volumes")); + virtualDatacenter.addLink(new RESTLink("privatenetworks", + "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks")); + virtualDatacenter.addLink(new RESTLink("defaultnetwork", + "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1")); + virtualDatacenter.addLink(new RESTLink("defaultvlan", + "http://localhost/api/cloud/virtualdatacenters/1/action/defaultvlan")); + virtualDatacenter.addLink(new RESTLink("topurchase", + "http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase")); + virtualDatacenter.addLink(new RESTLink("purchased", + "http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased")); + virtualDatacenter.addLink(new RESTLink("templates", + "http://localhost/api/cloud/virtualdatacenters/1/action/templates")); + return virtualDatacenter; + + } + + public static VirtualApplianceDto virtualAppliancePut() + { + VirtualApplianceDto virtualAppliance = virtualAppliancePost(); + virtualAppliance.setId(1); + virtualAppliance.addLink(new RESTLink("virtualdatacenter", + "http://localhost/api/cloud/virtualdatacenters/1")); + virtualAppliance.addLink(new RESTLink("deploy", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/deploy")); + virtualAppliance.addLink(new RESTLink("edit", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1")); + virtualAppliance.addLink(new RESTLink("state", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/state")); + virtualAppliance.addLink(new RESTLink("undeploy", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/undeploy")); + virtualAppliance.addLink(new RESTLink("virtualmachines", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")); + return virtualAppliance; + } + + public static VirtualMachineDto virtualMachinePut() + { + VirtualMachineDto virtualMachine = virtualMachinePost(); + virtualMachine.setId(1); + virtualMachine + .addLink(new RESTLink("deploy", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/deploy")); + virtualMachine + .addLink(new RESTLink("disks", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/disks")); + virtualMachine + .addLink(new RESTLink("edit", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1")); + virtualMachine + .addLink(new RESTLink("state", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/state")); + virtualMachine + .addLink(new RESTLink("reset", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/reset")); + virtualMachine + .addLink(new RESTLink("tasks", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/tasks")); + virtualMachine + .addLink(new RESTLink("undeploy", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/undeploy")); + virtualMachine + .addLink(new RESTLink("persistent", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/persistent")); + virtualMachine.addLink(new RESTLink("virtualappliance", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1")); + virtualMachine + .addLink(new RESTLink("virtualmachinetemplate", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1")); + virtualMachine + .addLink(new RESTLink("nics", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/nics")); + virtualMachine + .addLink(new RESTLink("volumes", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/volumes")); + virtualMachine + .addLink(new RESTLink("configurations", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/configurations")); + return virtualMachine; + } + + public static VirtualMachineStateDto virtualMachineState() + { + VirtualMachineStateDto state = new VirtualMachineStateDto(); + state.setState(VirtualMachineState.ON); + return state; + } + + public static String virtualMachineStatePayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("ON"); + buffer.append(""); + return buffer.toString(); + } + + public static VolumeManagementDto volumePost() + { + VolumeManagementDto volume = new VolumeManagementDto(); + volume.setName("Volume"); + volume.setSizeInMB(1024); + volume.addLink(new RESTLink("tier", + "http://localhost/api/cloud/virtualdatacenters/1/tiers/1")); + return volume; + } + + public static VolumeManagementDto volumePut() + { + VolumeManagementDto volume = volumePost(); + volume.setId(1); + volume.setState(VolumeState.DETACHED.name()); + + volume.getLinks().clear(); + + RESTLink mappings = + new RESTLink("action", + "http://localhost/api/cloud/virtualdatacenters/1/volumes/1/action/initiatormappings"); + mappings.setTitle("initiator mappings"); + volume.addLink(mappings); + volume.addLink(new RESTLink("edit", + "http://localhost/api/cloud/virtualdatacenters/1/volumes/1")); + volume.addLink(new RESTLink("tier", + "http://localhost/api/cloud/virtualdatacenters/1/tiers/1")); + volume.addLink(new RESTLink("virtualdatacenter", + "http://localhost/api/cloud/virtualdatacenters/1")); + return volume; + } + + public static VirtualMachineTemplateDto virtualMachineTemplatePut() + { + VirtualMachineTemplateDto template = new VirtualMachineTemplateDto(); + template.setId(10); + template.setName("m0n0wall"); + template.setDiskFormatType(DiskFormatType.VMDK_FLAT.toString()); + template.setPath("1/abiquo-repository.abiquo.com/m0n0wall/m0n0wall-1.3b18-i386-flat.vmdk"); + template.setDiskFileSize(27262976); + template.setCpuRequired(1); + template.setRamRequired(128); + template.setCpuRequired(27262976); + template.setCreationUser("SYSTEM"); + template + .setIconUrl("http://ww1.prweb.com/prfiles/2010/08/02/2823234/gI_0_HakunaLogoMedium.jpg"); + template.addLink(new RESTLink("icon", "http://localhost/api/config/icons/1")); + template.addLink(new RESTLink("category", "http://localhost/api/config/categories/1")); + + return template; + + } + + public static TierDto cloudTierPut() + { + TierDto tier = new TierDto(); + tier.setId(1); + tier.setEnabled(true); + tier.setName("Tier"); + tier.addLink(new RESTLink("edit", "http://localhost/api/cloud/virtualdatacenters/1/tiers/1")); + return tier; + } + + public static VirtualMachineTaskDto deployOptions() + { + VirtualMachineTaskDto deploy = new VirtualMachineTaskDto(); + deploy.setForceEnterpriseSoftLimits(false); + return deploy; + + } + + public static VirtualMachineTaskDto undeployOptions() + { + VirtualMachineTaskDto deploy = new VirtualMachineTaskDto(); + deploy.setForceUndeploy(true); + return deploy; + } + + public static String virtualDatacenterPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("KVM"); + buffer.append("VDC"); + buffer.append(NetworkResources.vlanNetworkPostPayload()); + buffer.append(""); + return buffer.toString(); + } + + public static String virtualAppliancePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("0"); + buffer.append("VA"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String virtualMachinePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("VM"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String virtualDatacenterPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1", "datacenter")); + buffer.append(link("/cloud/virtualdatacenters/1/disks", "disks")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer.append(link("/cloud/virtualdatacenters/1", "edit")); + buffer.append(link("/cloud/virtualdatacenters/1/tiers", "tiers")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances", "virtualappliances")); + buffer.append(link("/cloud/virtualdatacenters/1/volumes", "volumes")); + buffer.append(link("/cloud/virtualdatacenters/1/privatenetworks", "privatenetworks")); + buffer.append(link("/cloud/virtualdatacenters/1/privatenetworks/1", "defaultnetwork")); + buffer.append(link("/cloud/virtualdatacenters/1/action/defaultvlan", "defaultvlan")); + buffer.append(link("/cloud/virtualdatacenters/1/publicips/topurchase", "topurchase")); + buffer.append(link("/cloud/virtualdatacenters/1/publicips/purchased", "purchased")); + buffer.append(link("/cloud/virtualdatacenters/1/action/templates", "templates")); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("KVM"); + buffer.append("1"); + buffer.append("VDC"); + buffer.append(NetworkResources.vlanNetworkPostPayload()); + buffer.append(""); + return buffer.toString(); + } + + public static String virtualDatacenterRefPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1", "virtualdatacenter")); + buffer.append(""); + return buffer.toString(); + } + + public static String virtualAppliancePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1", "virtualdatacenter")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1/action/deploy", + "deploy")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1", "edit")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1/state", "state")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1/action/undeploy", + "undeploy")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines", + "virtualmachines")); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("VA"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String virtualMachinePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/deploy", + "deploy")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/disks", + "disks")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1", + "edit")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/state", "state")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/reset", + "reset")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/tasks", "tasks")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/undeploy", + "undeploy")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/persistent", + "persistent")); + buffer.append(link("/cloud/virtualdatacenters/1/virtualappliances/1", "virtualappliance")); + buffer.append(link( + "/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1", + "virtualmachinetemplate")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/nics", + "nics")); + buffer.append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/volumes", + "volumes")); + buffer + .append(link( + "/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/configurations", + "configurations")); + + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("0"); + buffer.append("0"); + buffer.append("VM"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String volumePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1/tiers/1", "tier")); + buffer.append("Volume"); + buffer.append("1024"); + buffer.append(""); + return buffer.toString(); + } + + public static String volumePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1/volumes/1/action/initiatormappings", + "action", "initiator mappings")); + buffer.append(link("/cloud/virtualdatacenters/1/volumes/1", "edit")); + buffer.append(link("/cloud/virtualdatacenters/1/tiers/1", "tier")); + buffer.append(link("/cloud/virtualdatacenters/1", "virtualdatacenter")); + buffer.append("1"); + buffer.append("Volume"); + buffer.append("DETACHED"); + buffer.append("1024"); + buffer.append(""); + return buffer.toString(); + } + + public static String cloudTierPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1/tiers/1", "edit")); + buffer.append("true"); + buffer.append("1"); + buffer.append("Tier"); + buffer.append(""); + return buffer.toString(); + } + + public static String deployPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("false"); + buffer.append(""); + return buffer.toString(); + } + + public static String undeployPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("false"); + buffer.append("true"); + buffer.append(""); + return buffer.toString(); + } + + public static DiskManagementDto hardDiskPost() + { + DiskManagementDto disk = new DiskManagementDto(); + disk.setSizeInMb(1024L); + return disk; + } + + public static DiskManagementDto hardDiskPut() + { + DiskManagementDto disk = hardDiskPost(); + disk.addLink(new RESTLink("edit", "http://localhost/api/cloud/virtualdatacenters/1/disks/1")); + disk.addLink(new RESTLink("virtualdatacenter", + "http://localhost/api/cloud/virtualdatacenters/1")); + return disk; + } + + public static String hardDiskPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("1024"); + buffer.append(""); + return buffer.toString(); + } + + public static String hardDiskPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1", "virtualdatacenter")); + buffer.append(link("/cloud/virtualdatacenters/1/disks/1", "edit")); + buffer.append("0"); + buffer.append("1024"); + buffer.append(""); + return buffer.toString(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/ConfigResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/ConfigResources.java new file mode 100644 index 0000000000..f3df44905a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/ConfigResources.java @@ -0,0 +1,182 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.CategoryDto; +import com.abiquo.server.core.config.LicenseDto; +import com.abiquo.server.core.config.SystemPropertyDto; +import com.google.common.io.Resources; + +/** + * Enterprise domain utilities. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class ConfigResources +{ + public static LicenseDto licensePost() + { + LicenseDto license = new LicenseDto(); + license.setCode(readLicense("license/expired")); + license.setCustomerid("3bca6d1d-5fe2-42c5-82ea-a5276ea8c71c"); + return license; + } + + public static CategoryDto categoryPost() + { + CategoryDto category = new CategoryDto(); + category.setName("category"); + category.setErasable(false); + category.setDefaultCategory(false); + return category; + } + + public static CategoryDto categoryPut() + { + CategoryDto category = categoryPost(); + category.setId(1); + category.addLink(new RESTLink("edit", "http://localhost/api/config/categories/1")); + return category; + } + + public static LicenseDto licensePut() + { + LicenseDto license = licensePost(); + license.setId(1); + license.addLink(new RESTLink("edit", "http://localhost/api/config/licenses/1")); + + return license; + } + + public static SystemPropertyDto propertyPut() + { + SystemPropertyDto property = new SystemPropertyDto(); + property.setId(1); + property.setDescription("Time interval in seconds"); + property.setValue("10"); + property.setName("api.applibrary.ovfpackagesDownloadingProgressUpdateInterval"); + property.addLink(new RESTLink("edit", "http://localhost/api/config/properties/1")); + + return property; + } + + public static String licensePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/enterprises/config/licenses/1", "edit")); + buffer.append("3bca6d1d-5fe2-42c5-82ea-a5276ea8c71c"); + buffer.append("" + readLicense("license/expired") + ""); + buffer.append("1"); + buffer.append(""); + return buffer.toString(); + } + + public static String licensePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("3bca6d1d-5fe2-42c5-82ea-a5276ea8c71c"); + buffer.append("" + readLicense("license/expired") + ""); + buffer.append(""); + return buffer.toString(); + } + + public static String categoryPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("false"); + buffer.append("false"); + buffer.append("category"); + buffer.append(""); + return buffer.toString(); + } + + public static String categoryPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/config/categories/1", "edit")); + buffer.append("false"); + buffer.append("false"); + buffer.append("1"); + buffer.append("category"); + buffer.append(""); + return buffer.toString(); + } + + public static String iconPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/config/icons/1", "edit")); + buffer.append("1"); + buffer.append("icon"); + buffer.append("http://www.pixeljoint.com/files/icons/mipreview1.gif"); + buffer.append(""); + return buffer.toString(); + } + + public static String iconPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("icon"); + buffer.append("http://www.pixeljoint.com/files/icons/mipreview1.gif"); + buffer.append(""); + return buffer.toString(); + } + + public static String propertyPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/config/properties/1", "edit")); + buffer.append("Time interval in seconds"); + buffer.append("1"); + buffer + .append("api.applibrary.ovfpackagesDownloadingProgressUpdateInterval"); + buffer.append("10"); + buffer.append(""); + return buffer.toString(); + } + + private static String readLicense(final String filename) + { + URL url = ConfigResources.class.getResource("/" + filename); + try + { + return Resources.toString(url, Charset.defaultCharset()); + } + catch (IOException e) + { + throw new RuntimeException("Could not read file " + filename); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/DomainUtils.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/DomainUtils.java new file mode 100644 index 0000000000..88e3092f09 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/DomainUtils.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import org.jclouds.xml.XMLParser; + +import com.abiquo.model.rest.RESTLink; + +/** + * Utility class to build domain objects used in tests. + * + * @author Ignasi Barrera + */ +public class DomainUtils +{ + /** + * Adds the XML header to the given XML. + */ + public static String withHeader(final String xml) + { + return XMLParser.DEFAULT_XML_HEADER + xml; + } + + /** + * Builds a link in xml format + */ + public static String link(final String href, final String rel) + { + return ""; + } + + /** + * Builds a link in xml format + */ + public static String link(final String href, final String rel, final String title) + { + return ""; + } + + /** + * Builds a link in xml format + */ + public static String link(final RESTLink link) + { + return ""; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/EnterpriseResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/EnterpriseResources.java new file mode 100644 index 0000000000..6dc496b1d8 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/EnterpriseResources.java @@ -0,0 +1,353 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import java.util.HashMap; +import java.util.Map; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto; +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; +import com.abiquo.server.core.enterprise.UserDto; + +/** + * Enterprise domain utilities. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class EnterpriseResources +{ + public static EnterpriseDto enterprisePost() + { + EnterpriseDto enterprise = new EnterpriseDto(); + enterprise.setName("Kalakaua"); + return enterprise; + } + + public static EnterpriseDto enterprisePut() + { + EnterpriseDto enterprise = enterprisePost(); + enterprise.setId(1); + enterprise.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/1")); + enterprise + .addLink(new RESTLink("limits", "http://localhost/api/admin/enterprises/1/limits")); + enterprise.addLink(new RESTLink("users", "http://localhost/api/admin/enterprises/1/users")); + enterprise.addLink(new RESTLink("properties", + "http://localhost/api/admin/enterprises/1/properties")); + enterprise.addLink(new RESTLink("reservedmachines", + "http://localhost/api/admin/enterprises/1/reservedmachines")); + enterprise.addLink(new RESTLink("datacenterrepositories", + "http://localhost/api/admin/enterprises/1/datacenterrepositories")); + enterprise.addLink(new RESTLink("externalnetworks", + "http://localhost/api/admin/enterprises/1/action/externalnetworks")); + enterprise.addLink(new RESTLink("virtualmachines", + "http://localhost/api/admin/enterprises/1/action/virtualmachines")); + enterprise.addLink(new RESTLink("cloud/virtualdatacenters", + "http://localhost/api/admin/enterprises/1/action/virtualdatacenters")); + enterprise.addLink(new RESTLink("virtualappliances", + "http://localhost/api/admin/enterprises/1/action/virtualappliances")); + enterprise.addLink(new RESTLink("appslib/templateDefinitionLists", + "http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists")); + + return enterprise; + } + + public static EnterprisePropertiesDto enterprisePropertiesPut() + { + EnterprisePropertiesDto enterpriseProp = new EnterprisePropertiesDto(); + enterpriseProp.setId(1); + Map props = new HashMap(); + props.put("key", "value"); + enterpriseProp.setProperties(props); + enterpriseProp.addLink(new RESTLink("edit", + "http://localhost/api/admin/enterprises/1/properties")); + enterpriseProp.addLink(new RESTLink("enterprise", + "http://localhost/api/admin/enterprises/1")); + + return enterpriseProp; + } + + public static String enterprisePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("false"); + buffer.append("Kalakaua"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String enterprisePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/enterprises/1", "edit")); + buffer.append(link("/admin/enterprises/1/limits", "limits")); + buffer.append(link("/admin/enterprises/1/users", "users")); + buffer.append(link("/admin/enterprises/1/properties", "properties")); + buffer.append(link("/admin/enterprises/1/reservedmachines", "reservedmachines")); + buffer + .append(link("/admin/enterprises/1/datacenterrepositories", "datacenterrepositories")); + buffer.append(link("/admin/enterprises/1/action/externalnetworks", "externalnetworks")); + buffer.append(link("/admin/enterprises/1/action/virtualmachines", "virtualmachines")); + buffer.append(link("/admin/enterprises/1/action/virtualdatacenters", + "cloud/virtualdatacenters")); + buffer.append(link("/admin/enterprises/1/action/virtualappliances", "virtualappliances")); + buffer.append(link("/admin/enterprises/1/appslib/templateDefinitionLists", + "appslib/templateDefinitionLists")); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("false"); + buffer.append("Kalakaua"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String enterprisePropertiesPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/enterprises/1/properties", "edit")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer.append("1"); + buffer.append(""); + buffer.append(""); + buffer.append("key"); + buffer.append("value"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + return buffer.toString(); + } + + public static DatacenterLimitsDto datacenterLimitsPost() + { + DatacenterLimitsDto limits = new DatacenterLimitsDto(); + limits.setCpuCountLimits(0, 0); + limits.setHdLimitsInMb(0, 0); + limits.setPublicIPLimits(0, 0); + limits.setRamLimitsInMb(0, 0); + limits.setStorageLimits(0, 0); + limits.setVlansLimits(0, 0); + limits.setRepositoryHardLimitsInMb(0); + limits.setRepositorySoftLimitsInMb(0); + return limits; + } + + public static DatacenterLimitsDto datacenterLimitsPut(final EnterpriseDto enterprise) + { + DatacenterLimitsDto limits = datacenterLimitsPost(); + limits.setId(1); + limits.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/" + + enterprise.getId() + "/limits/1")); + return limits; + } + + public static TemplateDefinitionListDto templateListPost() + { + TemplateDefinitionListDto templateList = new TemplateDefinitionListDto(); + templateList.setName("myList"); + templateList.setUrl("http://virtualapp-repository.com/vapp1.ovf"); + return templateList; + } + + public static TemplateDefinitionListDto templateListPut() + { + TemplateDefinitionListDto templateList = templateListPost(); + templateList.setId(1); + templateList.addLink(new RESTLink("edit", + "http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists/1")); + templateList + .addLink(new RESTLink("repositoryStatus", + "http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists/1/actions/repositoryStatus")); + return templateList; + } + + public static String datacenterLimitsPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String templateListPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("myList"); + buffer.append("http://virtualapp-repository.com/vapp1.ovf"); + buffer.append(""); + return buffer.toString(); + } + + public static String templateListPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/enterprises/1/appslib/templateDefinitionLists/1", "edit")); + buffer.append(link( + "/admin/enterprises/1/appslib/templateDefinitionLists/1/actions/repositoryStatus", + "repositoryStatus")); + buffer.append("1"); + buffer.append("myList"); + buffer.append("http://virtualapp-repository.com/vapp1.ovf"); + buffer.append(""); + return buffer.toString(); + } + + public static String datacenterLimitsPutPayload(final EnterpriseDto enterprise) + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/enterprises/" + enterprise.getId() + "/limits/1", "edit")); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("1"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String userPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/roles/1", "role")); + buffer.append("true"); + buffer.append("ABIQUO"); + buffer.append("A hawaian user"); + buffer.append("abe.joha@aloha.com"); + buffer.append("en_US"); + buffer.append("Aberahama"); + buffer.append("abejo"); + buffer.append("c69a39bd64ffb77ea7ee3369dce742f3"); + buffer.append("Johanson"); + buffer.append(""); + return buffer.toString(); + } + + public static UserDto userPost() + { + UserDto user = new UserDto(); + user.setName("Aberahama"); + user.setSurname("Johanson"); + user.setDescription("A hawaian user"); + user.setEmail("abe.joha@aloha.com"); + user.setNick("abejo"); + user.setAuthType("ABIQUO"); + user.setLocale("en_US"); + user.setActive(true); + user.setPassword("c69a39bd64ffb77ea7ee3369dce742f3"); + user.addLink(new RESTLink("role", "http://localhost/api/admin/roles/1")); + return user; + } + + public static String userPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/roles/1", "role")); + buffer.append(link("/admin/enterprises/1/users/1", "edit")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer + .append(link("/admin/enterprises/1/users/1/action/virtualmachines", "virtualmachines")); + buffer.append("true"); + buffer.append("ABIQUO"); + buffer.append("A hawaian user"); + buffer.append("abe.joha@aloha.com"); + buffer.append("1"); + buffer.append("en_US"); + buffer.append("Aberahama"); + buffer.append("abejo"); + buffer.append("c69a39bd64ffb77ea7ee3369dce742f3"); + buffer.append("Johanson"); + buffer.append(""); + return buffer.toString(); + } + + public static UserDto userPut() + { + UserDto user = userPost(); + user.setId(1); + user.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/1/users/1")); + user.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); + user.addLink(new RESTLink("virtualmachines", + "http://localhost/api/admin/enterprises/1/users/1/action/virtualmachines")); + return user; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java new file mode 100644 index 0000000000..89cef979df --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java @@ -0,0 +1,555 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.OrganizationDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.RemoteServiceDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; + +/** + * Infrastructure domain utilities. + * + * @author Ignasi Barrera + */ +public class InfrastructureResources +{ + public static DatacenterDto datacenterPost() + { + DatacenterDto datacenter = new DatacenterDto(); + datacenter.setName("DC"); + datacenter.setLocation("Honolulu"); + return datacenter; + } + + public static RackDto rackPost() + { + RackDto rack = new RackDto(); + rack.setName("Aloha"); + rack.setShortDescription("A hawaian rack"); + rack.setHaEnabled(false); + rack.setVlanIdMin(6); + rack.setVlanIdMax(3024); + rack.setVlanPerVdcReserved(6); + rack.setNrsq(80); + return rack; + } + + public static UcsRackDto managedRackPost() + { + UcsRackDto rack = new UcsRackDto(); + rack.setName("Aloha"); + rack.setShortDescription("A hawaian rack"); + rack.setHaEnabled(false); + rack.setVlanIdMin(6); + rack.setVlanIdMax(3024); + rack.setVlanPerVdcReserved(6); + rack.setNrsq(80); + return rack; + } + + public static MachineDto machinePost() + { + MachineDto machine = new MachineDto(); + machine.setName("Kamehameha"); + machine.setVirtualCpuCores(3); + machine.setDescription("A hawaian machine"); + machine.setVirtualRamInMb(512); + machine.setVirtualSwitch("192.168.1.10"); + return machine; + } + + public static RemoteServiceDto remoteServicePost() + { + RemoteServiceDto remoteService = new RemoteServiceDto(); + remoteService.setType(RemoteServiceType.NODE_COLLECTOR); + remoteService.setUri("http://localhost:80/nodecollector"); + remoteService.setStatus(0); + return remoteService; + } + + public static StorageDeviceDto storageDevicePost() + { + StorageDeviceDto storage = new StorageDeviceDto(); + storage.setName("Aloha aloha"); + storage.setIscsiIp("10.10.10.10"); + storage.setIscsiPort(99); + storage.setManagementPort(90); + + return storage; + } + + public static StoragePoolDto storagePoolPost() + { + StoragePoolDto storagePool = new StoragePoolDto(); + storagePool.setName("Hawaian Storage Pool"); + return storagePool; + } + + public static DatacenterDto datacenterPut() + { + DatacenterDto datacenter = datacenterPost(); + datacenter.setId(1); + datacenter.addLink(new RESTLink("checkmachinestate", + "http://localhost/api/admin/datacenters/1/action/checkmachinestate")); + datacenter.addLink(new RESTLink("checkmachineipmistate", + "http://localhost/api/admin/datacenters/1/action/checkmachineipmistate")); + datacenter.addLink(new RESTLink("checkremoteservice", + "http://localhost/api/admin/datacenters/1/action/checkremoteservice")); + datacenter.addLink(new RESTLink("devices", + "http://localhost/api/admin/datacenters/1/storage/devices")); + datacenter.addLink(new RESTLink("discovermultiple", + "http://localhost/api/admin/datacenters/1/action/discovermultiple")); + datacenter.addLink(new RESTLink("discoversingle", + "http://localhost/api/admin/datacenters/1/action/discoversingle")); + datacenter.addLink(new RESTLink("edit", "http://localhost/api/admin/datacenters/1")); + datacenter.addLink(new RESTLink("getLimits", + "http://localhost/api/admin/datacenters/1/action/getLimits")); + datacenter.addLink(new RESTLink("racks", "http://localhost/api/admin/datacenters/1/racks")); + datacenter.addLink(new RESTLink("remoteservices", + "http://localhost/api/admin/datacenters/1/remoteservices")); + datacenter.addLink(new RESTLink("tiers", + "http://localhost/api/admin/datacenters/1/storage/tiers")); + datacenter.addLink(new RESTLink("network", + "http://localhost/api/admin/datacenters/1/network")); + datacenter.addLink(new RESTLink("enterprises", + "http://localhost/api/admin/datacenters/1/action/enterprises")); + datacenter.addLink(new RESTLink("hypervisor", + "http://localhost/api/admin/datacenters/1/action/hypervisor")); + datacenter.addLink(new RESTLink("hypervisors", + "http://localhost/api/admin/datacenters/1/hypervisors")); + return datacenter; + } + + public static RackDto rackPut() + { + RackDto rack = rackPost(); + rack.setId(1); + rack.addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1")); + rack.addLink(new RESTLink("edit", "http://localhost/api/admin/datacenters/1/racks/1")); + rack.addLink(new RESTLink("machines", + "http://localhost/api/admin/datacenters/1/racks/1/machines")); + return rack; + } + + public static UcsRackDto managedRackPut() + { + UcsRackDto rack = managedRackPost(); + rack.setId(1); + rack.addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1")); + rack.addLink(new RESTLink("edit", "http://localhost/api/admin/datacenters/1/racks/1")); + rack.addLink(new RESTLink("fsm", "http://localhost/api/admin/datacenters/1/racks/1/fsm")); + rack.addLink(new RESTLink("logicservers", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers")); + rack.addLink(new RESTLink("ls-templates", + "http://localhost/api/admin/datacenters/1/racks/1/lstemplates")); + rack.addLink(new RESTLink("organizations", + "http://localhost/api/admin/datacenters/1/racks/1/organizations")); + rack.addLink(new RESTLink("ls-associate", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers/associate")); + rack.addLink(new RESTLink("ls-associateclone", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers/assocclone")); + rack.addLink(new RESTLink("ls-associatetemplate", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers/associatetemplate")); + rack.addLink(new RESTLink("ls-clone", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers/clone")); + rack.addLink(new RESTLink("ls-delete", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers/delete")); + rack.addLink(new RESTLink("ls-dissociate", + "http://localhost/api/admin/datacenters/1/racks/1/logicservers/dissociate")); + return rack; + } + + public static LogicServerDto logicServerPut() + { + LogicServerDto logicServer = new LogicServerDto(); + logicServer.setName("server"); + logicServer.setAssociated("associated"); + logicServer.setType("instance"); + + return logicServer; + } + + public static OrganizationDto organizationPut() + { + OrganizationDto org = new OrganizationDto(); + org.setName("org"); + org.setDn("org-root/org-Finance"); + org.setLevel("1"); + + return org; + } + + public static TierDto tierPut() + { + TierDto tier = new TierDto(); + tier.setId(1); + tier.setEnabled(true); + tier.setName("Tier"); + tier.addLink(new RESTLink("edit", + "http://localhost/api/admin/datacenters/1/storage/tiers/1")); + tier.addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1")); + tier.addLink(new RESTLink("pools", + "http://localhost/api/admin/datacenters/1/storage/tiers/1/pools")); + + return tier; + } + + public static StorageDeviceDto storageDevicePut() + { + StorageDeviceDto storageDevice = storageDevicePost(); + storageDevice.setId(1); + storageDevice + .addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1")); + storageDevice.addLink(new RESTLink("edit", + "http://localhost/api/admin/datacenters/1/storage/devices/1")); + storageDevice.addLink(new RESTLink("pools", + "http://localhost/api/admin/datacenters/1/storage/devices/1/pools")); + + return storageDevice; + } + + public static StoragePoolDto storagePoolPut() + { + StoragePoolDto storagePool = storagePoolPost(); + storagePool.setIdStorage("tururututu"); + storagePool.addLink(new RESTLink("device", + "http://localhost/api/admin/datacenters/1/storage/devices/1")); + storagePool.addLink(new RESTLink("edit", + "http://localhost/api/admin/datacenters/1/storage/devices/1/pools/tururututu")); + + return storagePool; + } + + public static RemoteServiceDto remoteServicePut() + { + RemoteServiceDto remoteService = remoteServicePost(); + remoteService.setId(1); + remoteService.addLink(new RESTLink("check", + "http://localhost/api/admin/datacenters/1/remoteservices/nodecollector/action/check")); + remoteService + .addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1")); + remoteService.addLink(new RESTLink("edit", + "http://localhost/api/admin/datacenters/1/remoteservices/nodecollector")); + return remoteService; + } + + public static MachineDto machinePut() + { + MachineDto machine = machinePost(); + machine.setId(1); + machine.addLink(new RESTLink("edit", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1")); + machine.addLink(new RESTLink("rack", "http://localhost/api/admin/datacenters/1/racks/1")); + machine.addLink(new RESTLink("checkstate", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/checkstate")); + machine.addLink(new RESTLink("checkipmistate", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/checkipmistate")); + machine.addLink(new RESTLink("led", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/led")); + machine.addLink(new RESTLink("ledoff", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/ledoff")); + machine.addLink(new RESTLink("ledon", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/ledon")); + machine.addLink(new RESTLink("logicserver", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/logicserver")); + machine.addLink(new RESTLink("poweroff", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/poweroff")); + machine.addLink(new RESTLink("poweron", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/poweron")); + machine.addLink(new RESTLink("virtualmachines", + "http://localhost/api/admin/datacenters/1/racks/1/machines/1/virtualmachines")); + machine.setVirtualCpuCores(5); + + return machine; + } + + public static String datacenterPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("Honolulu"); + buffer.append("DC"); + buffer.append(""); + return buffer.toString(); + } + + public static String rackPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("false"); + buffer.append("Aloha"); + buffer.append("80"); + buffer.append("A hawaian rack"); + buffer.append("3024"); + buffer.append("6"); + buffer.append("6"); + buffer.append(""); + return buffer.toString(); + } + + public static String managedRackPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("false"); + buffer.append("Aloha"); + buffer.append("80"); + buffer.append("A hawaian rack"); + buffer.append("3024"); + buffer.append("6"); + buffer.append("6"); + buffer.append(""); + return buffer.toString(); + } + + public static String storagePoolPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("false"); + buffer.append("Hawaian Storage Pool"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String storageDevicePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("10.10.10.10"); + buffer.append("99"); + buffer.append("90"); + buffer.append("Aloha aloha"); + buffer.append(""); + return buffer.toString(); + } + + public static String machinePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(""); + buffer.append("A hawaian machine"); + buffer.append("Kamehameha"); + buffer.append("3"); + buffer.append("1"); + buffer.append("512"); + buffer.append("1"); + buffer.append("192.168.1.10"); + buffer.append(""); + return buffer.toString(); + } + + public static String remoteServicePostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("0"); + buffer.append("NODE_COLLECTOR"); + buffer.append("http://localhost:80/nodecollector"); + buffer.append(""); + return buffer.toString(); + } + + public static String datacenterPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/action/checkmachinestate", "checkmachinestate")); + buffer.append(link("/admin/datacenters/1/action/checkmachineipmistate", + "checkmachineipmistate")); + buffer.append(link("/admin/datacenters/1/action/checkremoteservice", "checkremoteservice")); + buffer.append(link("/admin/datacenters/1/storage/devices", "devices")); + buffer.append(link("/admin/datacenters/1/action/discovermultiple", "discovermultiple")); + buffer.append(link("/admin/datacenters/1/action/discoversingle", "discoversingle")); + buffer.append(link("/admin/datacenters/1", "edit")); + buffer.append(link("/admin/datacenters/1/action/getLimits", "getLimits")); + buffer.append(link("/admin/datacenters/1/racks", "racks")); + buffer.append(link("/admin/datacenters/1/remoteservices", "remoteservices")); + buffer.append(link("/admin/datacenters/1/storage/tiers", "tiers")); + buffer.append(link("/admin/datacenters/1/network", "network")); + buffer.append(link("/admin/datacenters/1/action/enterprises", "enterprises")); + buffer.append(link("/admin/datacenters/1/action/hypervisor", "hypervisor")); + buffer.append(link("/admin/datacenters/1/hypervisors", "hypervisors")); + buffer.append("1"); + buffer.append("Honolulu"); + buffer.append("DC"); + buffer.append(""); + return buffer.toString(); + } + + public static String storagePoolPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/storage/devices/1", "device")); + buffer.append(link("/admin/datacenters/1/storage/devices/1/pools/tururututu", "edit")); + buffer.append("0"); + buffer.append("false"); + buffer.append("tururututu"); + buffer.append("Hawaian Storage Pool"); + buffer.append("0"); + buffer.append("0"); + buffer.append(""); + return buffer.toString(); + } + + public static String tierPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/storage/tiers/1", "edit")); + buffer.append(link("/admin/datacenters/1", "datacenter")); + buffer.append(link("/admin/datacenters/1/storage/tiers/1/pools", "pools")); + buffer.append("true"); + buffer.append("1"); + buffer.append("Tier"); + buffer.append(""); + return buffer.toString(); + } + + public static String rackPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1", "datacenter")); + buffer.append(link("/admin/datacenters/1/racks/1", "edit")); + buffer.append(link("/admin/datacenters/1/racks/1/machines", "machines")); + buffer.append("false"); + buffer.append("1"); + buffer.append("Aloha"); + buffer.append("80"); + buffer.append("A hawaian rack"); + buffer.append("3024"); + buffer.append("6"); + buffer.append("6"); + buffer.append(""); + return buffer.toString(); + } + + public static String managedRackPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1", "datacenter")); + buffer.append(link("/admin/datacenters/1/racks/1", "edit")); + buffer.append(link("/admin/datacenters/1/racks/1/fsm", "fsm")); + buffer.append(link("/admin/datacenters/1/racks/1/logicservers", "logicservers")); + buffer.append(link("/admin/datacenters/1/racks/1/lstemplates", "ls-templates")); + buffer.append(link("/admin/datacenters/1/racks/1/organizations", "organizations")); + buffer.append(link("/admin/datacenters/1/racks/1/logicservers/associate", "ls-associate")); + buffer.append(link("/admin/datacenters/1/racks/1/logicservers/assocclone", + "ls-associateclone")); + buffer.append(link("/admin/datacenters/1/racks/1/logicservers/associatetemplate", + "ls-associatetemplate")); + buffer.append(link("/admin/datacenters/1/racks/1/logicservers/clone", "ls-clone")); + buffer.append(link("/admin/datacenters/1/racks/1/logicservers/delete", "ls-delete")); + buffer + .append(link("/admin/datacenters/1/racks/1/logicservers/dissociate", "ls-dissociate")); + buffer.append("false"); + buffer.append("1"); + buffer.append("Aloha"); + buffer.append("80"); + buffer.append("A hawaian rack"); + buffer.append("3024"); + buffer.append("6"); + buffer.append("6"); + buffer.append(""); + return buffer.toString(); + } + + public static String storageDevicePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1", "datacenter")); + buffer.append(link("/admin/datacenters/1/storage/devices/1", "edit")); + buffer.append(link("/admin/datacenters/1/storage/devices/1/pools", "pools")); + buffer.append("1"); + buffer.append("10.10.10.10"); + buffer.append("99"); + buffer.append("90"); + buffer.append("Aloha aloha"); + buffer.append(""); + return buffer.toString(); + } + + public static String remoteServicePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/remoteservices/nodecollector/action/check", + "check")); + buffer.append(link("/admin/datacenters/1", "datacenter")); + buffer.append(link("/admin/datacenters/1/remoteservices/nodecollector", "edit")); + buffer.append("1"); + buffer.append("0"); + buffer.append("NODE_COLLECTOR"); + buffer.append("http://localhost:80/nodecollector"); + buffer.append(""); + return buffer.toString(); + } + + public static String machinePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1", "edit")); + buffer.append(link("/admin/datacenters/1/racks/1", "rack")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/action/checkstate", + "checkstate")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/action/checkipmistate", + "checkipmistate")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/led", "led")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/action/ledoff", "ledoff")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/action/ledon", "ledon")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/logicserver", "logicserver")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/action/poweroff", "poweroff")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/action/poweron", "poweron")); + buffer.append(link("/admin/datacenters/1/racks/1/machines/1/virtualmachines", + "virtualmachines")); + buffer.append(""); + buffer.append("A hawaian machine"); + buffer.append("1"); + buffer.append("Kamehameha"); + buffer.append("5"); + buffer.append("1"); + buffer.append("512"); + buffer.append("1"); + buffer.append("192.168.1.10"); + buffer.append(""); + return buffer.toString(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/NetworkResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/NetworkResources.java new file mode 100644 index 0000000000..6db98f41d3 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/NetworkResources.java @@ -0,0 +1,277 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.infrastructure.network.NicDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; + +/** + * Network domain utilities. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class NetworkResources +{ + public static VLANNetworkDto vlanPost() + { + VLANNetworkDto vlan = new VLANNetworkDto(); + vlan.setAddress("192.168.1.0"); + vlan.setDefaultNetwork(true); + vlan.setName("DefaultNetwork"); + vlan.setGateway("192.168.1.1"); + vlan.setMask(24); + + return vlan; + } + + public static PrivateIpDto privateIpPut() + { + PrivateIpDto ip = new PrivateIpDto(); + ip.setId(1); + ip.setName("private ip"); + ip.setMac("00:58:5A:c0:C3:01"); + RESTLink self = + new RESTLink("self", + "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips/1"); + self.setTitle("privateip"); + ip.addLink(self); + return ip; + } + + public static PublicIpDto publicIpToPurchase() + { + PublicIpDto ip = new PublicIpDto(); + RESTLink self = + new RESTLink("purchase", + "http://localhost/api/cloud/virtualdatacenters/5/publicips/purchased/1"); + ip.addLink(self); + return ip; + } + + public static PublicIpDto publicIpToRelease() + { + PublicIpDto ip = new PublicIpDto(); + RESTLink self = + new RESTLink("release", + "http://localhost/api/cloud/virtualdatacenters/5/publicips/topurchase/1"); + ip.addLink(self); + return ip; + } + + public static NicDto nicPut() + { + NicDto nic = new NicDto(); + nic.setId(1); + nic.setIp("123.123.123.123"); + nic.setMac("00:58:5A:c0:C3:01"); + nic.addLink(new RESTLink("edit", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/nics/1")); + + return nic; + } + + public static VLANNetworkDto privateNetworkPut() + { + VLANNetworkDto vlan = new VLANNetworkDto(); + vlan.setId(1); + vlan.setAddress("192.168.1.0"); + vlan.setDefaultNetwork(true); + vlan.setName("DefaultNetwork"); + vlan.setGateway("192.168.1.1"); + vlan.setMask(24); + vlan.setType(NetworkType.INTERNAL); + vlan.addLink(new RESTLink("edit", + "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1")); + vlan.addLink(new RESTLink("ips", + "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips")); + + return vlan; + } + + public static VLANNetworkDto publicNetworkPut() + { + VLANNetworkDto vlan = new VLANNetworkDto(); + vlan.setId(1); + vlan.setAddress("192.168.1.0"); + vlan.setDefaultNetwork(true); + vlan.setName("PublicNetwork"); + vlan.setGateway("192.168.1.1"); + vlan.setMask(24); + vlan.setType(NetworkType.PUBLIC); + vlan.addLink(new RESTLink("edit", "http://localhost/api/admin/datacenters/1/network/1")); + vlan.addLink(new RESTLink("ips", "http://localhost/api/admin/datacenters/1/network/1/ips")); + + return vlan; + } + + public static VLANNetworkDto externalNetworkPut() + { + VLANNetworkDto vlan = new VLANNetworkDto(); + vlan.setId(1); + vlan.setAddress("192.168.1.0"); + vlan.setDefaultNetwork(true); + vlan.setName("ExternalNetwork"); + vlan.setGateway("192.168.1.1"); + vlan.setMask(24); + vlan.setType(NetworkType.EXTERNAL); + vlan.addLink(new RESTLink("edit", "http://localhost/api/admin/datacenters/1/network/1")); + vlan.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); + vlan.addLink(new RESTLink("ips", + "http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips")); + + return vlan; + } + + public static VLANNetworkDto unmanagedNetworkPut() + { + VLANNetworkDto vlan = new VLANNetworkDto(); + vlan.setId(1); + vlan.setAddress("192.168.1.0"); + vlan.setDefaultNetwork(true); + vlan.setName("UnmanagedNetwork"); + vlan.setGateway("192.168.1.1"); + vlan.setMask(24); + vlan.setType(NetworkType.UNMANAGED); + vlan.addLink(new RESTLink("edit", "http://localhost/api/admin/datacenters/1/network/1")); + vlan.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); + vlan.addLink(new RESTLink("ips", + "http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips")); + + return vlan; + } + + public static String vlanNetworkPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("
192.168.1.0
"); + buffer.append("true"); + buffer.append("192.168.1.1"); + buffer.append("24"); + buffer.append("DefaultNetwork"); + buffer.append("
"); + return buffer.toString(); + } + + public static String privateNetworkPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1/privatenetworks/1", "edit")); + buffer.append(link("/cloud/virtualdatacenters/1/privatenetworks/1/ips", "ips")); + buffer.append("
192.168.1.0
"); + buffer.append("true"); + buffer.append("192.168.1.1"); + buffer.append("1"); + buffer.append("24"); + buffer.append("DefaultNetwork"); + buffer.append("INTERNAL"); + buffer.append("
"); + return buffer.toString(); + } + + public static String publicNetworkPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/network/1", "edit")); + buffer.append(link("/admin/datacenters/1/network/1/ips", "ips")); + buffer.append("
192.168.1.0
"); + buffer.append("true"); + buffer.append("192.168.1.1"); + buffer.append("1"); + buffer.append("24"); + buffer.append("PublicNetwork"); + buffer.append("PUBLIC"); + buffer.append("
"); + return buffer.toString(); + } + + public static String externalNetworkPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/network/1", "edit")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer.append(link("/admin/enterprises/1/limits/1/externalnetworks/1/ips", "ips")); + buffer.append("
192.168.1.0
"); + buffer.append("true"); + buffer.append("192.168.1.1"); + buffer.append("1"); + buffer.append("24"); + buffer.append("ExternalNetwork"); + buffer.append("EXTERNAL"); + buffer.append("
"); + return buffer.toString(); + } + + public static String unmanagedNetworkPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/admin/datacenters/1/network/1", "edit")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer.append(link("/admin/enterprises/1/limits/1/externalnetworks/1/ips", "ips")); + buffer.append("
192.168.1.0
"); + buffer.append("true"); + buffer.append("192.168.1.1"); + buffer.append("1"); + buffer.append("24"); + buffer.append("UnmanagedNetwork"); + buffer.append("UNMANAGED"); + buffer.append("
"); + return buffer.toString(); + } + + public static String privateIpPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1/privatenetworks/1/ips/1", "self", + "privateip")); + buffer.append("false"); + buffer.append("1"); + buffer.append("00:58:5A:c0:C3:01"); + buffer.append("private ip"); + buffer.append("false"); + buffer.append(""); + return buffer.toString(); + } + + public static String linksDtoPayload(final LinksDto dto) + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + for (RESTLink link : dto.getLinks()) + { + buffer.append(link(link)); + } + buffer.append(""); + return buffer.toString(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java new file mode 100644 index 0000000000..f694aa5a51 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java @@ -0,0 +1,80 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.pricing.CurrencyDto; + +/** + * Enterprise domain utilities. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +public class PricingResources +{ + + public static CurrencyDto currencyPost() + { + CurrencyDto currency = new CurrencyDto(); + currency.setName("yuan"); + currency.setSymbol("¥"); + currency.setDigits(3); + return currency; + } + + public static CurrencyDto currencyPut() + { + CurrencyDto currency = new CurrencyDto(); + currency.setName("yuan"); + currency.setSymbol("¥"); + currency.setDigits(3); + currency.setId(1); + currency.addLink(new RESTLink("edit", "http://localhost/api/config/currencies/1")); + return currency; + } + + public static String currencyPostPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append("¥"); + buffer.append("3"); + buffer.append("yuan"); + buffer.append(""); + return buffer.toString(); + } + + public static String currencyPutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/config/currencies/1", "edit")); + buffer.append("¥"); + buffer.append("3"); + buffer.append("1"); + buffer.append("yuan"); + buffer.append(""); + return buffer.toString(); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/TemplateResources.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/TemplateResources.java new file mode 100644 index 0000000000..d8f67b403c --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/TemplateResources.java @@ -0,0 +1,178 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain; + +import static org.jclouds.abiquo.domain.DomainUtils.link; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.abiquo.server.core.appslibrary.DatacenterRepositoryDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto; + +/** + * VM template domain utilities. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +public class TemplateResources +{ + public static DatacenterRepositoryDto datacenterRepositoryPut() + { + DatacenterRepositoryDto dcRepository = new DatacenterRepositoryDto(); + dcRepository.setName("Datacenter Repo"); + dcRepository.setRepositoryCapacityMb(0); + dcRepository.setRepositoryLocation("10.60.1.104:/volume1/nfs-devel"); + dcRepository.setRepositoryRemainingMb(0); + dcRepository.addLink(new RESTLink("applianceManagerRepositoryUri", + "http://localhost/am/erepos/1")); + dcRepository + .addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1")); + dcRepository.addLink(new RESTLink("edit", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1")); + dcRepository + .addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); + dcRepository.addLink(new RESTLink("refresh", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/actions/refresh")); + dcRepository + .addLink(new RESTLink("virtualmachinetemplates", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates")); + + return dcRepository; + } + + public static VirtualMachineTemplateDto virtualMachineTemplatePut() + { + VirtualMachineTemplateDto template = new VirtualMachineTemplateDto(); + template.setName("Template"); + template.setId(1); + template.setDescription("Description"); + template + .addLink(new RESTLink("edit", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1")); + template.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); + template.addLink(new RESTLink("conversions", "http://localhost/api/admin/enterprises/1" + + "/datacenterrepositories/1/virtualmachinetemplates/1/conversions")); + template.addLink(new RESTLink("tasks", "http://localhost/api/admin/enterprises/1" + + "/datacenterrepositories/1/virtualmachinetemplates/1/tasks")); + + return template; + } + + public static String virtualMachineTemplatePutPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link( + "/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1", "edit")); + buffer.append(link("/admin/enterprises/1", "enterprise")); + buffer.append(link("/admin/enterprises/1" + + "/datacenterrepositories/1/virtualmachinetemplates/1/conversions", "conversions")); + + buffer.append(link("/admin/enterprises/1" + + "/datacenterrepositories/1/virtualmachinetemplates/1/tasks", "tasks")); + buffer.append("1"); + buffer.append("Template"); + buffer.append("Description"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("0"); + buffer.append("false"); + buffer.append("0"); + buffer.append("false"); + buffer.append(""); + return buffer.toString(); + } + + public static VirtualMachineTemplatePersistentDto persistentData() + { + VirtualMachineTemplatePersistentDto dto = new VirtualMachineTemplatePersistentDto(); + dto.setPersistentTemplateName("New persistent template name"); + dto.setPersistentVolumeName("New persistent volume name"); + dto.addLink(new RESTLink("tier", "http://localhost/api/cloud/virtualdatacenters/1/tiers/1")); + dto.addLink(new RESTLink("virtualdatacenter", + "http://localhost/api/cloud/virtualdatacenters/1")); + dto.addLink(new RESTLink("virtualmachinetemplate", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1")); + return dto; + } + + public static String persistentPayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer.append(link("/cloud/virtualdatacenters/1/tiers/1", "tier")); + buffer.append(link("/cloud/virtualdatacenters/1", "virtualdatacenter")); + buffer.append(link( + "/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1", + "virtualmachinetemplate")); + buffer + .append("New persistent template name"); + buffer.append("New persistent volume name"); + buffer.append(""); + return buffer.toString(); + } + + public static ConversionDto conversionPut() + { + ConversionDto conversion = new ConversionDto(); + conversion.setState(ConversionState.ENQUEUED); + conversion.setSourceFormat(DiskFormatType.VMDK_STREAM_OPTIMIZED); + conversion.setSourcePath("source/path.vmkd"); + conversion.setTargetFormat(DiskFormatType.RAW); + conversion.setTargetPath("target/path.raw"); + conversion.setTargetSizeInBytes(1000000l); + conversion + .addLink(new RESTLink("edit", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions/RAW")); + conversion + .addLink(new RESTLink("tasks", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions/RAW/tasks")); + + return conversion; + } + + public static String conversionPutPlayload() + { + StringBuffer buffer = new StringBuffer(); + buffer.append(""); + buffer + .append(link( + "/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions/RAW", + "edit")); + buffer + .append(link( + "/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions/RAW/tasks", + "tasks")); + + buffer.append("ENQUEUED"); + buffer.append("VMDK_STREAM_OPTIMIZED"); + buffer.append("source/path.vmkd"); + buffer.append("RAW"); + buffer.append("target/path.raw"); + buffer.append("1000000"); + buffer.append(""); + return buffer.toString(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java new file mode 100644 index 0000000000..f096f8d4f1 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java @@ -0,0 +1,112 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.admin; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.DomainWrapper; +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.config.PrivilegePredicates; +import org.jclouds.abiquo.predicates.enterprise.RolePredicates; +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.PrivilegeDto; +import com.abiquo.server.core.enterprise.RoleDto; + +/** + * Live integration tests for the {@link Role} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "RoleLiveApiTest") +public class RoleLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + Role role = + Role.builder(env.context.getApiContext()).name("dummyRoleUpdateRole").blocked(false) + .build(); + role.save(); + + role.setName("UPDATED_ROLE"); + role.update(); + + // Recover the updated role + RoleDto updated = env.adminApi.getRole(role.getId()); + + assertEquals(updated.getName(), "UPDATED_ROLE"); + + role.delete(); + } + + public void testCreateRepeated() + { + Role repeated = Role.Builder.fromRole(env.role).build(); + + try + { + repeated.save(); + fail("Should not be able to create roles with the same name"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "ROLE-7"); + } + } + + public void testCreateEnterpriseRole() + { + Role entRole = Role.Builder.fromRole(env.role).build(); + entRole.setName(entRole.getName() + "enterprise"); + entRole.setEnterprise(env.enterprise); + entRole.save(); + + entRole = env.enterprise.findRole(RolePredicates.name(entRole.getName())); + + assertNotNull(entRole); + } + + public void testAddPrivilege() + { + PrivilegeDto dto = env.configApi.getPrivilege(8); + Privilege privilege = DomainWrapper.wrap(env.context.getApiContext(), Privilege.class, dto); + List privileges = env.role.listPrivileges(); + privileges.add(privilege); + + env.role.setPrivileges(privileges); + + env.role.update(); + + privilege = env.role.findPrivileges(PrivilegePredicates.name(dto.getName())); + + assertNotNull(privilege); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java new file mode 100644 index 0000000000..9a372a4b8e --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/HardDiskLiveApiTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link HardDisk} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "HardDiskLiveApiTest") +public class HardDiskLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private HardDisk hardDisk; + + public void createHardDisk() + { + hardDisk = + HardDisk.builder(env.context.getApiContext(), env.virtualDatacenter).sizeInMb(64L) + .build(); + hardDisk.save(); + + assertNotNull(hardDisk.getId()); + assertNotNull(hardDisk.getSequence()); + + assertNotNull(env.virtualDatacenter.getHardDisk(hardDisk.getId())); + } + + @Test(dependsOnMethods = "createHardDisk") + public void deleteHardDisk() + { + HardDisk hd = env.virtualDatacenter.getHardDisk(hardDisk.getId()); + assertNotNull(hd); + + Integer id = hd.getId(); + hardDisk.delete(); + assertNull(env.virtualDatacenter.getHardDisk(id)); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveApiTest.java new file mode 100644 index 0000000000..827c83b756 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveApiTest.java @@ -0,0 +1,108 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceState; + +/** + * Live integration tests for the {@link VirtualAppliance} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "VirtualApplianceLiveApiTest") +public class VirtualApplianceLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + env.virtualAppliance.setName("Virtual AppAloha updated"); + env.virtualAppliance.update(); + + // Recover the updated virtual appliance + VirtualApplianceDto updated = + env.cloudApi.getVirtualAppliance(env.virtualDatacenter.unwrap(), + env.virtualAppliance.getId()); + + assertEquals(updated.getName(), "Virtual AppAloha updated"); + } + + public void testCreateRepeated() + { + VirtualAppliance repeated = + VirtualAppliance.Builder.fromVirtualAppliance(env.virtualAppliance).build(); + + repeated.save(); + + List virtualAppliances = + env.cloudApi.listVirtualAppliances(env.virtualDatacenter.unwrap()).getCollection(); + + assertEquals(virtualAppliances.size(), 2); + repeated.delete(); + } + + public void testGetState() + { + assertEquals(env.virtualAppliance.getState(), VirtualApplianceState.NOT_DEPLOYED); + } + + public void testListVirtualMachinesReturnsAll() + { + List vms = new ArrayList(); + + // Pagination by default is set to 25 items per page, so create a few more to verify that + // all are returned when listing + int numVms = 30; + + for (int i = 0; i < numVms; i++) + { + VirtualMachine vm = + VirtualMachine.Builder.fromVirtualMachine(env.virtualMachine).build(); + vm.save(); + vms.add(vm); + } + + try + { + Iterable all = env.virtualAppliance.listVirtualMachines(); + + assertNotNull(all); + assertTrue(size(all) >= numVms); + } + finally + { + for (VirtualMachine vm : vms) + { + vm.delete(); + } + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java new file mode 100644 index 0000000000..5c5025016a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java @@ -0,0 +1,209 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static com.google.common.collect.Iterables.size; +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter.Builder; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.cloud.VirtualMachineTemplatePredicates; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; + +/** + * Live integration tests for the {@link VirtualDatacenter} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "VirtualDatacenterLiveApiTest") +public class VirtualDatacenterLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private VirtualMachineTemplate template; + + public void testUpdate() + { + env.virtualDatacenter.setName("Aloha updated"); + env.virtualDatacenter.update(); + + // Recover the updated virtual datacenter + VirtualDatacenterDto updated = + env.cloudApi.getVirtualDatacenter(env.virtualDatacenter.getId()); + + assertEquals(updated.getName(), "Aloha updated"); + } + + public void testCreateRepeated() + { + PrivateNetwork newnet = + PrivateNetwork.builder(env.context.getApiContext()).name("Newnet").gateway("10.0.0.1") + .address("10.0.0.0").mask(24).build(); + + VirtualDatacenter repeated = + Builder.fromVirtualDatacenter(env.virtualDatacenter).network(newnet).build(); + + repeated.save(); + + List virtualDatacenters = + env.cloudApi.listVirtualDatacenters(VirtualDatacenterOptions.builder().build()) + .getCollection(); + + assertEquals(virtualDatacenters.size(), 2); + assertEquals(virtualDatacenters.get(0).getName(), virtualDatacenters.get(1).getName()); + repeated.delete(); + } + + public void testCreateFromEnterprise() + { + Enterprise enterprise = + env.enterpriseAdminContext.getAdministrationService().getCurrentUser().getEnterprise(); + assertNotNull(enterprise); + + List datacenters = enterprise.listAllowedDatacenters(); + assertNotNull(datacenters); + assertTrue(size(datacenters) > 0); + + Datacenter datacenter = datacenters.get(0); + + List hypervisors = datacenter.listAvailableHypervisors(); + assertNotNull(datacenters); + assertTrue(size(datacenters) > 0); + + HypervisorType hypervisor = hypervisors.get(0); + + PrivateNetwork network = + PrivateNetwork.builder(env.enterpriseAdminContext.getApiContext()) + .name("DefaultNetwork").gateway("192.168.1.1").address("192.168.1.0").mask(24) + .build(); + + VirtualDatacenter virtualDatacenter = + VirtualDatacenter + .builder(env.enterpriseAdminContext.getApiContext(), datacenters.get(0), enterprise) + .name(PREFIX + "Plain Virtual Aloha from ENT").cpuCountLimits(18, 20) + .hdLimitsInMb(279172872, 279172872).publicIpsLimits(2, 2).ramLimits(19456, 20480) + .storageLimits(289910292, 322122547).vlansLimits(1, 2).hypervisorType(hypervisor) + .network(network).build(); + + virtualDatacenter.save(); + assertNotNull(virtualDatacenter.getId()); + + virtualDatacenter.delete(); + } + + public void testCreateFromVirtualDatacenter() + { + HypervisorType hypervisor = env.virtualDatacenter.getHypervisorType(); + + Enterprise enterprise = env.user.getEnterprise(); + assertNotNull(enterprise); + + Datacenter datacenter = env.virtualDatacenter.getDatacenter(); + assertNotNull(datacenter); + + PrivateNetwork network = + PrivateNetwork.builder(env.plainUserContext.getApiContext()).name("DefaultNetwork") + .gateway("192.168.1.1").address("192.168.1.0").mask(24).build(); + + VirtualDatacenter virtualDatacenter = + VirtualDatacenter.builder(env.context.getApiContext(), datacenter, enterprise) + .name(PREFIX + "Plain Virtual Aloha from VDC").cpuCountLimits(18, 20) + .hdLimitsInMb(279172872, 279172872).publicIpsLimits(2, 2).ramLimits(19456, 20480) + .storageLimits(289910292, 322122547).vlansLimits(1, 2).hypervisorType(hypervisor) + .network(network).build(); + + virtualDatacenter.save(); + assertNotNull(virtualDatacenter.getId()); + + virtualDatacenter.delete(); + } + + public void testPurchaseIp() + { + PublicIp publicIp = env.virtualDatacenter.listAvailablePublicIps().get(0); + assertNotNull(publicIp); + env.virtualDatacenter.purchasePublicIp(publicIp); + + PublicIp apiIp = + env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(publicIp + .getIp())); + assertNotNull(apiIp); + + env.virtualDatacenter.releaseePublicIp(apiIp); + apiIp = + env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(publicIp + .getIp())); + assertNull(apiIp); + } + + public void testGetDefaultNetwork() + { + PrivateNetwork network = env.virtualDatacenter.getDefaultNetwork().toPrivateNetwork(); + + assertNotNull(network); + assertEquals(network.getName(), env.privateNetwork.getName()); + assertEquals(network.getType(), env.privateNetwork.getType()); + } + + public void testGetAvailableTemplates() + { + List templates = env.virtualDatacenter.listAvailableTemplates(); + assertNotNull(templates); + assertFalse(templates.isEmpty()); + + template = templates.get(0); + } + + @Test(dependsOnMethods = "testGetAvailableTemplates") + public void testFindAvailableTemplate() + { + VirtualMachineTemplate templateFound = + env.virtualDatacenter.findAvailableTemplate(VirtualMachineTemplatePredicates + .id(template.getId())); + + assertNotNull(template); + assertNotNull(templateFound); + assertEquals(templateFound.getId(), template.getId()); + } + + @Test(dependsOnMethods = "testGetAvailableTemplates") + public void testGetAvailableTemplate() + { + VirtualMachineTemplate templateFound = + env.virtualDatacenter.getAvailableTemplate(template.getId()); + assertNotNull(templateFound); + assertEquals(templateFound.getId(), template.getId()); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveApiTest.java new file mode 100644 index 0000000000..1416d81fc1 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveApiTest.java @@ -0,0 +1,142 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.cloud.VirtualMachineState; + +/** + * Live integration tests for the {@link VirtualMachine} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "VirtualMachineLiveApiTest") +public class VirtualMachineLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testHasDataFromNode() + { + assertNotNull(env.virtualMachine.getNameLabel()); + assertNotNull(env.virtualMachine.getInternalName()); + assertNotNull(env.virtualMachine.getOwnerName()); + } + + public void testUpdateInfoFromNode() + { + env.virtualMachine.setNameLabel(PREFIX + "-label-updated"); + env.virtualMachine.update(); + env.virtualMachine.refresh(); + + assertEquals(env.virtualMachine.getNameLabel(), PREFIX + "-label-updated"); + } + + public void testGetTasks() + { + List tasks = env.virtualMachine.listTasks(); + assertNotNull(tasks); + } + + public void testGetState() + { + VirtualMachineState state = env.virtualMachine.getState(); + assertEquals(state, VirtualMachineState.NOT_ALLOCATED); + } + + public void testIsPersistent() + { + assertFalse(env.virtualMachine.isPersistent()); + } + + public void testGetVirtualAppliance() + { + VirtualAppliance vapp = env.virtualMachine.getVirtualAppliance(); + assertNotNull(vapp); + assertEquals(vapp.getId(), env.virtualAppliance.getId()); + } + + public void testRebootVirtualMachineFailsWhenNotAllocated() + { + // Since the virtual machine is not deployed, this should not generate a task + + try + { + env.virtualMachine.reboot(); + fail("Reboot should have failed for the NOT_ALLOCATED virtual machine"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "VM-11"); + } + } + + public void testUpdateForcingLimits() + { + int originalHard = env.virtualDatacenter.getCpuCountHardLimit(); + int originalSoft = env.virtualDatacenter.getCpuCountSoftLimit(); + + env.virtualDatacenter.setCpuCountHardLimit(10); + env.virtualDatacenter.setCpuCountSoftLimit(5); + env.virtualDatacenter.update(); + + try + { + VirtualMachine vm = env.virtualAppliance.getVirtualMachine(env.virtualMachine.getId()); + vm.setCpu(7); + AsyncTask task = vm.update(true); + + assertNull(task); + assertEquals(vm.getCpu(), 7); + } + finally + { + env.virtualDatacenter.setCpuCountHardLimit(originalHard); + env.virtualDatacenter.setCpuCountSoftLimit(originalSoft); + env.virtualDatacenter.update(); + } + } + + public void testAttachDvd() + { + VirtualMachine vm = + VirtualMachine.Builder.fromVirtualMachine(env.virtualMachine).dvd(true).build(); + vm.save(); + + VirtualMachineDto updated = + env.cloudApi.getVirtualMachine(env.virtualAppliance.unwrap(), vm.getId()); + + assertNotNull(updated.getDvd()); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java new file mode 100644 index 0000000000..0a82a9b806 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java @@ -0,0 +1,241 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.network.ExternalIp; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.domain.network.PublicNetwork; +import org.jclouds.abiquo.domain.network.UnmanagedIp; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.Lists; + +/** + * Live integration tests for the {@link VirtualMachine} networking operations. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "VirtualMachineNetworkingLiveApiTest") +public class VirtualMachineNetworkingLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private PrivateIp privateIp; + + private ExternalIp externalIp; + + private PublicIp publicIpInfrastructure; + + private PublicIp publicIpCloud; + + private UnmanagedIp unmanagedIp1; + + private UnmanagedIp unmanagedIp2; + + @BeforeClass + public void setupIps() + { + privateIp = env.privateNetwork.listUnusedIps().get(0); + assertNotNull(privateIp); + + externalIp = env.externalNetwork.listUnusedIps().get(0); + assertNotNull(externalIp); + + publicIpInfrastructure = env.virtualDatacenter.listAvailablePublicIps().get(0); + env.virtualDatacenter.purchasePublicIp(publicIpInfrastructure); + + publicIpCloud = + env.virtualDatacenter.findPurchasedPublicIp(IpPredicates + . address(publicIpInfrastructure.getIp())); + assertNotNull(publicIpCloud); + } + + @AfterClass + public void restorePrivateIp() + { + AsyncTask task = env.virtualMachine.setNics(Lists.> newArrayList(privateIp)); + assertNull(task); + + List> nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 1); + assertEquals(nics.get(0).getId(), privateIp.getId()); + + String address = publicIpCloud.getIp(); + env.virtualDatacenter.releaseePublicIp(publicIpCloud); + assertNull(env.virtualDatacenter.findPurchasedPublicIp(IpPredicates + . address(address))); + } + + // TODO: Infrastructure edit link for public ips can not be used to attach + @Test(enabled = false) + public void testAttachInfrastructurePublicIp() + { + AsyncTask task = + env.virtualMachine.setNics(Lists.> newArrayList(publicIpInfrastructure)); + assertNull(task); + + List> nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 1); + assertEquals(nics.get(0).getId(), publicIpInfrastructure.getId()); + } + + public void testAttachPublicIp() + { + AsyncTask task = + env.virtualMachine.setNics(Lists.> newArrayList(publicIpCloud)); + assertNull(task); + + List> nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 1); + assertEquals(nics.get(0).getId(), publicIpCloud.getId()); + } + + @Test(dependsOnMethods = "testAttachPublicIp") + public void testAttachPrivateIp() + { + List> nics = env.virtualMachine.listAttachedNics(); + nics.add(privateIp); + + AsyncTask task = env.virtualMachine.setNics(nics); + assertNull(task); + + nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 2); + assertEquals(nics.get(0).getId(), publicIpCloud.getId()); + assertEquals(nics.get(1).getId(), privateIp.getId()); + } + + @Test(dependsOnMethods = "testAttachPrivateIp") + public void testAttachExternalIp() + { + List> nics = env.virtualMachine.listAttachedNics(); + nics.add(externalIp); + + AsyncTask task = env.virtualMachine.setNics(nics); + assertNull(task); + + nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 3); + assertEquals(nics.get(0).getId(), publicIpCloud.getId()); + assertEquals(nics.get(1).getId(), privateIp.getId()); + assertEquals(nics.get(2).getId(), externalIp.getId()); + } + + @Test(dependsOnMethods = "testAttachExternalIp") + public void testAddUnmanagedNics() + { + List> nics = env.virtualMachine.listAttachedNics(); + + AsyncTask task = + env.virtualMachine.setNics(nics, + Lists. newArrayList(env.unmanagedNetwork, env.unmanagedNetwork)); + assertNull(task); + + nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 5); + assertEquals(nics.get(0).getId(), publicIpCloud.getId()); + assertEquals(nics.get(1).getId(), privateIp.getId()); + assertEquals(nics.get(2).getId(), externalIp.getId()); + // Unmanaged ips are created during the attach. + assertEquals(nics.get(3).getNetworkName(), env.unmanagedNetwork.getName()); + assertEquals(nics.get(4).getNetworkName(), env.unmanagedNetwork.getName()); + + unmanagedIp1 = (UnmanagedIp) nics.get(3); + unmanagedIp2 = (UnmanagedIp) nics.get(4); + } + + @Test(dependsOnMethods = "testAddUnmanagedNics") + public void testReorderNics() + { + List> nics = env.virtualMachine.listAttachedNics(); + + AsyncTask task = + env.virtualMachine.setNics(Lists.> newArrayList(nics.get(2), nics.get(1), + nics.get(0), nics.get(4), nics.get(3))); + assertNull(task); + + nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 5); + assertEquals(nics.get(0).getId(), externalIp.getId()); + assertEquals(nics.get(1).getId(), privateIp.getId()); + assertEquals(nics.get(2).getId(), publicIpCloud.getId()); + assertEquals(nics.get(3).getId(), unmanagedIp2.getId()); + assertEquals(nics.get(4).getId(), unmanagedIp1.getId()); + } + + @Test(dependsOnMethods = "testReorderNics") + public void testDetachNics() + { + List> nics = env.virtualMachine.listAttachedNics(); + + AsyncTask task = + env.virtualMachine.setNics(Lists.> newArrayList(nics.get(1), nics.get(2))); + assertNull(task); + + nics = env.virtualMachine.listAttachedNics(); + assertEquals(nics.size(), 2); + assertEquals(nics.get(0).getId(), privateIp.getId()); + assertEquals(nics.get(1).getId(), publicIpCloud.getId()); + } + + @Test(dependsOnMethods = "testDetachNics") + public void testSetDefaultGateway() + { + PublicNetwork network = publicIpCloud.getNetwork(); + env.virtualMachine.setGatewayNetwork(network); + + Integer configId = env.virtualMachine.unwrap().getIdFromLink("network_configuration"); + assertEquals(configId, network.getId()); + } + + // TODO: Review this functionality + @Test(dependsOnMethods = "testSetDefaultGateway", enabled = false) + public void testDetachAllNics() + { + try + { + env.virtualMachine.setNics(null); + + fail("It should not be allowed to remove all nics from a vm"); + } + catch (AbiquoException ex) + { + // At least one nic must be configured + assertHasError(ex, Status.BAD_REQUEST, "VM-46"); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java new file mode 100644 index 0000000000..074f40288d --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java @@ -0,0 +1,159 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link VirtualMachine} storage operations. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "VirtualMachineStorageLiveApiTest") +public class VirtualMachineStorageLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private Volume volume; + + private HardDisk hardDisk; + + public void testAttachVolumes() + { + volume = createVolume(); + + // Since the virtual machine is not deployed, this should not generate a task + AsyncTask task = env.virtualMachine.attachVolumes(volume); + assertNull(task); + + List attached = env.virtualMachine.listAttachedVolumes(); + assertEquals(attached.size(), 1); + assertEquals(attached.get(0).getId(), volume.getId()); + } + + @Test(dependsOnMethods = "testAttachVolumes") + public void detachVolume() + { + env.virtualMachine.detachVolumes(volume); + List attached = env.virtualMachine.listAttachedVolumes(); + assertTrue(attached.isEmpty()); + } + + @Test(dependsOnMethods = "detachVolume") + public void detachAllVolumes() + { + // Since the virtual machine is not deployed, this should not generate a task + AsyncTask task = env.virtualMachine.attachVolumes(volume); + assertNull(task); + + env.virtualMachine.detachAllVolumes(); + List attached = env.virtualMachine.listAttachedVolumes(); + assertTrue(attached.isEmpty()); + + deleteVolume(volume); + } + + public void testAttachHardDisks() + { + hardDisk = createHardDisk(); + + // Since the virtual machine is not deployed, this should not generate a task + AsyncTask task = env.virtualMachine.attachHardDisks(hardDisk); + assertNull(task); + + List attached = env.virtualMachine.listAttachedHardDisks(); + assertEquals(attached.size(), 1); + assertEquals(attached.get(0).getId(), hardDisk.getId()); + } + + @Test(dependsOnMethods = "testAttachHardDisks") + public void detachHardDisk() + { + env.virtualMachine.detachHardDisks(hardDisk); + List attached = env.virtualMachine.listAttachedHardDisks(); + assertTrue(attached.isEmpty()); + } + + @Test(dependsOnMethods = "detachHardDisk") + public void detachAllHardDisks() + { + // Since the virtual machine is not deployed, this should not generate a task + AsyncTask task = env.virtualMachine.attachHardDisks(hardDisk); + assertNull(task); + + env.virtualMachine.detachAllHardDisks(); + List attached = env.virtualMachine.listAttachedHardDisks(); + assertTrue(attached.isEmpty()); + + deleteHardDisk(hardDisk); + } + + private Volume createVolume() + { + Tier tier = env.virtualDatacenter.findStorageTier(TierPredicates.name(env.tier.getName())); + + Volume volume = + Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) + .name(PREFIX + "Hawaian volume").sizeInMb(32).build(); + volume.save(); + + assertNotNull(volume.getId()); + assertNotNull(env.virtualDatacenter.getVolume(volume.getId())); + + return volume; + } + + private void deleteVolume(final Volume volume) + { + Integer id = volume.getId(); + volume.delete(); + assertNull(env.virtualDatacenter.getVolume(id)); + } + + private HardDisk createHardDisk() + { + HardDisk hardDisk = + HardDisk.builder(env.context.getApiContext(), env.virtualDatacenter).sizeInMb(64L) + .build(); + hardDisk.save(); + + assertNotNull(hardDisk.getId()); + assertNotNull(hardDisk.getSequence()); + + return hardDisk; + } + + private void deleteHardDisk(final HardDisk hardDisk) + { + Integer id = hardDisk.getId(); + hardDisk.delete(); + assertNull(env.virtualDatacenter.getHardDisk(id)); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java new file mode 100644 index 0000000000..b9be919742 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link VirtualMachineTemplate} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "VirtualMachineTemplateLiveApiTest") +public class VirtualMachineTemplateLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testGetParent() + { + Datacenter datacenter = env.virtualMachine.getTemplate().getDatacenter(); + assertNotNull(datacenter); + assertEquals(datacenter.getId(), env.datacenter.getId()); + } + + public void testGetCategory() + { + Category category = env.virtualMachine.getTemplate().getCategory(); + assertNotNull(category); + } + + public void testGetIcon() + { + String iconUrl = env.virtualMachine.getTemplate().getIconUrl(); + assertNotNull(iconUrl); + } + + public void testRequestConversionToSameFormat() + { + try + { + env.virtualMachine.getTemplate().requestConversion( + env.virtualMachine.getTemplate().getDiskFormatType()); + fail("Should not be able to create create a conversion to the base format"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "CONVERSION-3"); + } + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java new file mode 100644 index 0000000000..1a85ea0139 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java @@ -0,0 +1,145 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.cloud; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.cloud.VolumePredicates; +import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; + +/** + * Live integration tests for the {@link Volume} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "VolumeLiveApiTest") +public class VolumeLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testCreateVolume() + { + // We need the vdc-relative tier + Tier tier = env.virtualDatacenter.findStorageTier(TierPredicates.name(env.tier.getName())); + + Volume volume = + Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) + .name(PREFIX + "Hawaian volume").sizeInMb(32).build(); + volume.save(); + + assertNotNull(volume.getId()); + assertNotNull(env.virtualDatacenter.getVolume(volume.getId())); + } + + @Test(dependsOnMethods = "testCreateVolume") + public void testFilterVolumes() + { + VolumeOptions validOptions = VolumeOptions.builder().has("hawa").build(); + VolumeOptions invalidOptions = VolumeOptions.builder().has("cacatua").build(); + + List volumes = + env.cloudApi.listVolumes(env.virtualDatacenter.unwrap(), validOptions).getCollection(); + + assertEquals(volumes.size(), 1); + + volumes = + env.cloudApi.listVolumes(env.virtualDatacenter.unwrap(), invalidOptions) + .getCollection(); + + assertEquals(volumes.size(), 0); + } + + @Test(dependsOnMethods = "testFilterVolumes") + public void testUpdateVolume() + { + Volume volume = + env.virtualDatacenter.findVolume(VolumePredicates.name(PREFIX + "Hawaian volume")); + assertNotNull(volume); + + volume.setName("Hawaian volume updated"); + AsyncTask task = volume.update(); + assertNull(task); + + // Reload the volume to check + Volume updated = env.virtualDatacenter.getVolume(volume.getId()); + assertEquals(updated.getName(), "Hawaian volume updated"); + } + + @Test(dependsOnMethods = "testUpdateVolume") + public void testMoveVolume() + { + // Create the new virtual datacenter + PrivateNetwork network = + PrivateNetwork.builder(env.context.getApiContext()).name("DefaultNetwork") + .gateway("192.168.1.1").address("192.168.1.0").mask(24).build(); + + VirtualDatacenter newVdc = + VirtualDatacenter.builder(env.context.getApiContext(), env.datacenter, env.enterprise) + .name("New VDC").network(network).hypervisorType(env.machine.getType()).build(); + newVdc.save(); + assertNotNull(newVdc.getId()); + + Volume volume = + env.virtualDatacenter.findVolume(VolumePredicates.name("Hawaian volume updated")); + assertNotNull(volume); + + volume.moveTo(newVdc); + + // Check that the underlying Dto has been updated to the new VDC + assertTrue(volume.unwrap().getEditLink().getHref() + .startsWith(newVdc.unwrap().getEditLink().getHref())); + + // Move it back to the original VDC + volume.moveTo(env.virtualDatacenter); + + // Check that the underlying Dto has been updated to the new VDC + assertTrue(volume.unwrap().getEditLink().getHref() + .startsWith(env.virtualDatacenter.unwrap().getEditLink().getHref())); + + // Tear down the virtual datacenter + newVdc.delete(); + } + + @Test(dependsOnMethods = "testMoveVolume") + public void testDeleteVolume() + { + Volume volume = + env.virtualDatacenter.findVolume(VolumePredicates.name("Hawaian volume updated")); + assertNotNull(volume); + + Integer id = volume.getId(); + volume.delete(); + + assertNull(env.virtualDatacenter.getVolume(id)); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java new file mode 100644 index 0000000000..6ce6d7db12 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.config.CategoryPredicates; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link Category} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "CategoryLiveApiTest") +public class CategoryLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testCreateAndGet() + { + Category category = + Category.builder(env.context.getApiContext()).name(PREFIX + "-test-category").build(); + category.save(); + + Category apiCategory = + env.context.getAdministrationService().findCategory( + CategoryPredicates.name(PREFIX + "-test-category")); + assertNotNull(apiCategory); + assertEquals(category.getName(), apiCategory.getName()); + + apiCategory.delete(); + } + + @Test(dependsOnMethods = "testCreateAndGet") + public void testUpdate() + { + Iterable categories = env.context.getAdministrationService().listCategories(); + assertNotNull(categories); + + Category category = categories.iterator().next(); + String name = category.getName(); + + category.setName(PREFIX + "-test-category-updated"); + category.update(); + + Category apiCategory = + env.context.getAdministrationService().findCategory( + CategoryPredicates.name(PREFIX + "-test-category-updated")); + + assertNotNull(apiCategory); + assertEquals(PREFIX + "-test-category-updated", apiCategory.getName()); + + category.setName(name); + category.update(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java new file mode 100644 index 0000000000..4e0bd132a4 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java @@ -0,0 +1,76 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.config.CurrencyPredicates; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link Currency} domain class. + * + * @author Susana Acedo + */ +@Test(groups = "api", testName = "CurrencyLiveApiTest") +public class CurrencyLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testCreateAndGet() + { + Currency currency = + Currency.builder(env.context.getApiContext()).name(PREFIX + "test-currency") + .symbol("test-$").digits(2).build(); + currency.save(); + + Currency apiCurrency = + env.context.getPricingService().findCurrency( + CurrencyPredicates.name(PREFIX + "test-currency")); + assertNotNull(apiCurrency); + assertEquals(currency.getName(), apiCurrency.getName()); + + apiCurrency.delete(); + } + + @Test(dependsOnMethods = "testCreateAndGet") + public void testUpdate() + { + Iterable currencies = env.context.getPricingService().listCurrencies(); + assertNotNull(currencies); + + Currency currency = currencies.iterator().next(); + String name = currency.getName(); + + currency.setName(PREFIX + "t-currency-upd"); + currency.update(); + + Currency apiCurrency = + env.context.getPricingService().findCurrency( + CurrencyPredicates.name(PREFIX + "t-currency-upd")); + + assertNotNull(apiCurrency); + assertEquals(PREFIX + "t-currency-upd", apiCurrency.getName()); + + currency.setName(name); + currency.update(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/LicenseLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/LicenseLiveApiTest.java new file mode 100644 index 0000000000..769412c28d --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/LicenseLiveApiTest.java @@ -0,0 +1,55 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.fail; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link User} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "LicenseLiveApiTest") +public class LicenseLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testCreateRepeated() + { + License repeated = License.Builder.fromLicense(env.license).build(); + + try + { + repeated.add(); + fail("Should not be able to create licenses with the same code"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "LICENSE-5"); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/SystemPropertiesLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/SystemPropertiesLiveApiTest.java new file mode 100644 index 0000000000..96526653f5 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/config/SystemPropertiesLiveApiTest.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.config; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link User} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "SystemPropertiesLiveApiTest") +public class SystemPropertiesLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testUpdate() + { + SystemProperty prop = + env.administrationService.getSystemProperty("client.dashboard.showStartUpAlert"); + + String value = prop.getValue(); + prop.setValue("0"); + prop.update(); + + // Recover the updated datacenter + SystemProperty updated = + env.administrationService.getSystemProperty("client.dashboard.showStartUpAlert"); + + assertEquals(updated.getValue(), "0"); + + prop.setValue(value); + prop.update(); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterpriseLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterpriseLiveApiTest.java new file mode 100644 index 0000000000..972c98ef8c --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterpriseLiveApiTest.java @@ -0,0 +1,190 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.enterprise.Enterprise.Builder; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; + +/** + * Live integration tests for the {@link Enterprise} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "EnterpriseLiveApiTest") +public class EnterpriseLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private Enterprise enterprise; + + private Limits limits; + + @BeforeClass + public void setupEnterprise() + { + enterprise = Enterprise.Builder.fromEnterprise(env.enterprise).build(); + enterprise.setName(PREFIX + "-enterprise-test"); + enterprise.save(); + + limits = enterprise.allowDatacenter(env.datacenter); + assertNotNull(limits); + + DatacentersLimitsDto limitsDto = + env.enterpriseApi.getLimits(enterprise.unwrap(), env.datacenter.unwrap()); + assertNotNull(limitsDto); + assertEquals(limitsDto.getCollection().size(), 1); + } + + @AfterClass + public void tearDownEnterprise() + { + enterprise.prohibitDatacenter(env.datacenter); + + try + { + // If a datacenter is not allowed, the limits for it can not be retrieved + env.enterpriseApi.getLimits(enterprise.unwrap(), env.datacenter.unwrap()); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "ENTERPRISE-10"); + } + + List allowed = enterprise.listAllowedDatacenters(); + assertNotNull(allowed); + assertTrue(allowed.isEmpty()); + + enterprise.delete(); + } + + public void testUpdate() + { + enterprise.setName("Updated Enterprise"); + enterprise.update(); + + // Recover the updated enterprise + EnterpriseDto updated = env.enterpriseApi.getEnterprise(enterprise.getId()); + + assertEquals(updated.getName(), "Updated Enterprise"); + } + + public void testCreateRepeated() + { + Enterprise repeated = Builder.fromEnterprise(enterprise).build(); + + try + { + repeated.save(); + fail("Should not be able to create enterprises with the same name"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "ENTERPRISE-4"); + } + } + + public void testAllowTwiceWorks() + { + // Allow the datacenter again and check that the configuration has not changed + Limits limits = enterprise.allowDatacenter(env.datacenter); + assertNotNull(limits); + + DatacentersLimitsDto limitsDto = + env.enterpriseApi.getLimits(enterprise.unwrap(), env.datacenter.unwrap()); + assertNotNull(limitsDto); + assertEquals(limitsDto.getCollection().size(), 1); + } + + public void testListLimits() + { + List allLimits = enterprise.listLimits(); + assertNotNull(allLimits); + assertEquals(allLimits.size(), 1); + } + + public void testUpdateInvalidLimits() + { + // CPU soft remains to 0 => conflict because hard is smaller + limits.setCpuCountHardLimit(2); + + try + { + limits.update(); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.BAD_REQUEST, "CONSTR-LIMITRANGE"); + } + } + + public void testUpdateLimits() + { + limits.setCpuCountLimits(4, 5); + limits.update(); + + DatacentersLimitsDto limitsDto = + env.enterpriseApi.getLimits(enterprise.unwrap(), env.datacenter.unwrap()); + assertNotNull(limitsDto); + assertEquals(limitsDto.getCollection().size(), 1); + assertEquals(limitsDto.getCollection().get(0).getCpuCountHardLimit(), 5); + assertEquals(limitsDto.getCollection().get(0).getCpuCountSoftLimit(), 4); + } + + public void testListAllowedDatacenters() + { + List allowed = enterprise.listAllowedDatacenters(); + + assertNotNull(allowed); + assertFalse(allowed.isEmpty()); + assertEquals(allowed.get(0).getId(), env.datacenter.getId()); + } + + public void testListVirtualMachines() + { + List machines = env.defaultEnterprise.listVirtualMachines(); + assertTrue(machines.size() > 0); + } + + public void testListVirtualAppliances() + { + List vapps = env.defaultEnterprise.listVirtualAppliances(); + assertTrue(vapps.size() > 0); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterprisePropertiesLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterprisePropertiesLiveApiTest.java new file mode 100644 index 0000000000..8b6d4d7403 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/EnterprisePropertiesLiveApiTest.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; + +/** + * Live integration tests for the {@link Enterprise} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "EnterprisePropertiesLiveApiTest") +public class EnterprisePropertiesLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + EnterpriseProperties properties = + env.administrationService.getEnterpriseProperties(env.enterprise); + + Integer size = properties.getProperties().size(); + properties.getProperties().put("Prop", "Value"); + properties.update(); + + // Recover the updated properties + EnterprisePropertiesDto updated = + env.enterpriseApi.getEnterpriseProperties(env.enterprise.unwrap()); + + assertEquals(updated.getProperties().size(), size + 1); + assertTrue(updated.getProperties().containsKey("Prop")); + assertTrue(updated.getProperties().containsValue("Value")); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java new file mode 100644 index 0000000000..4b16195d02 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java @@ -0,0 +1,81 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import java.util.List; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.enterprise.TemplateDefinitionListPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live integration tests for the {@link TemplateDefinitionList} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "TemplateDefinitionListLiveApiTest") +public class TemplateDefinitionListLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private TemplateDefinitionList list; + + public void testUpdate() + { + list.setName(list.getName() + "Updated"); + list.update(); + + List lists = + env.enterprise.listTemplateDefinitionLists(TemplateDefinitionListPredicates + .name("myListUpdated")); + + assertEquals(lists.size(), 1); + } + + public void testListStates() + { + List states = list.listStatus(env.datacenter); + assertNotNull(states); + } + + @BeforeClass + public void setup() + { + list = + TemplateDefinitionList.builder(env.context.getApiContext(), env.enterprise) + .name("myList").url("http://virtualapp-repository.com/vapp1.ovf").build(); + + list.save(); + + assertNotNull(list.getId()); + } + + @AfterClass + public void tearDown() + { + Integer idTemplateList = list.getId(); + list.delete(); + assertNull(env.enterprise.getTemplateDefinitionList(idTemplateList)); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java new file mode 100644 index 0000000000..57b524a513 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java @@ -0,0 +1,109 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.enterprise; + +import static org.jclouds.abiquo.predicates.enterprise.UserPredicates.nick; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.enterprise.UserPredicates; +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.UserDto; +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link User} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "UserLiveApiTest") +public class UserLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + String username = env.user.getName(); + env.user.setName("Manolo"); + env.user.update(); + + // Recover the updated user + UserDto updated = env.enterpriseApi.getUser(env.enterprise.unwrap(), env.user.getId()); + + assertEquals(updated.getName(), "Manolo"); + + env.user.setName(username); + env.user.update(); + } + + public void testCreateRepeated() + { + User repeated = User.Builder.fromUser(env.user).build(); + + try + { + repeated.save(); + fail("Should not be able to create users with the same nick"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "USER-4"); + } + } + + public void testChangeRoleAndUpdate() + { + env.user.setRole(env.anotherRole); + env.user.update(); + + Role role2 = env.enterprise.findUser(UserPredicates.nick(env.user.getNick())).getRole(); + + assertEquals(env.anotherRole.getId(), role2.getId()); + assertEquals(role2.getName(), "Another role"); + + env.user.setRole(env.role); + env.user.update(); + } + + public void testListUser() + { + Iterable users = env.enterprise.listUsers(); + assertEquals(Iterables.size(users), 2); + + users = env.enterprise.listUsers(nick(env.user.getNick())); + assertEquals(Iterables.size(users), 1); + + users = env.enterprise.listUsers(nick(env.user.getName() + "FAIL")); + assertEquals(Iterables.size(users), 0); + } + + public void testGetCurrentUser() + { + User user = env.context.getAdministrationService().getCurrentUser(); + assertNotNull(user); + assertEquals(user.getNick(), env.context.getApiContext().getIdentity()); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java new file mode 100644 index 0000000000..a82bc2b2f8 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java @@ -0,0 +1,283 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.event; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.Date; +import java.util.UUID; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.Volume; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.event.options.EventOptions; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.ComponentType; +import com.abiquo.model.enumerator.EventType; +import com.abiquo.model.enumerator.SeverityType; +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link Event} domain class. + * + * @author Vivien Mahé + */ +@Test(groups = "api", testName = "EventLiveApiTest") +public class EventLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testListEventsFilteredByDatacenter() + { + String name = randomName(); + env.datacenter.setName(name); + env.datacenter.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).datacenterName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredByRack() + { + String name = randomName(); + env.rack.setName(name); + env.rack.update(); + + EventOptions options = EventOptions.builder().dateFrom(new Date()).rackName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredByPM() + { + String name = randomName(); + env.machine.setName(name); + env.machine.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).physicalMachineName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredByStorageDevice() + { + String name = randomName(); + env.storageDevice.setName(name); + env.storageDevice.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).storageSystemName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredByStoragePool() + { + Tier tier = env.datacenter.findTier(TierPredicates.name("Default Tier 2")); + assertNotNull(tier); + + try + { + env.storagePool.setTier(tier); + env.storagePool.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()) + .storagePoolName(env.storagePool.getName()).build(); + assertEvents(options); + } + finally + { + // Restore the original tier + env.storagePool.setTier(env.tier); + env.storagePool.update(); + } + } + + public void testListEventsFilteredByEnterprise() + { + String entName = env.enterprise.getName(); + String name = randomName(); + env.enterprise.setName(name); + env.enterprise.update(); + + // Enterprise current = + // env.enterpriseAdminContext.getAdministrationService().getCurrentEnterprise(); + // current.setName("Enterprise updated"); + // current.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).enterpriseName(name).build(); + assertEvents(options); + + env.enterprise.setName(entName); + env.enterprise.update(); + } + + /** + * TODO: Using the painUserContext, modifying the user returns this error: HTTP/1.1 401 + * Unauthorized + **/ + @Test(enabled = false) + public void testListEventsFilteredByUser() + { + User current = env.plainUserContext.getAdministrationService().getCurrentUser(); + current.setEmail("test@test.com"); + current.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).userName(current.getName()).build(); + assertEvents(options); + } + + public void testListEventsFilteredByVDC() + { + String name = randomName(); + env.virtualDatacenter.setName(name); + env.virtualDatacenter.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).virtualDatacenterName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredByVapp() + { + String name = randomName(); + env.virtualAppliance.setName(name); + env.virtualAppliance.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).virtualAppName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredByVM() + { + VirtualMachine vm = createVirtualMachine(); + vm.delete(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).actionPerformed(EventType.VM_DELETE) + .build(); + assertEvents(options); + } + + public void testListEventsFilteredByVolume() + { + String name = randomName(); + Volume volume = createVolume(); + volume.setName(name); + volume.update(); + volume.delete(); // We don't need it any more. events already exist + + EventOptions options = EventOptions.builder().dateFrom(new Date()).volumeName(name).build(); + assertEvents(options); + } + + public void testListEventsFilteredBySeverity() + { + String name = randomName(); + env.virtualAppliance.setName(name); + env.virtualAppliance.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).virtualAppName(name) + .severity(SeverityType.INFO).build(); + assertEvents(options); + } + + public void testListEventsFilteredByActionPerformed() + { + String name = randomName(); + env.virtualAppliance.setName(name); + env.virtualAppliance.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).virtualAppName(name) + .actionPerformed(EventType.VAPP_MODIFY).build(); + assertEvents(options); + } + + public void testListEventsFilteredByComponent() + { + String name = randomName(); + env.virtualAppliance.setName(name); + env.virtualAppliance.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).virtualAppName(name) + .component(ComponentType.VIRTUAL_APPLIANCE).build(); + assertEvents(options); + } + + public void testListEventsFilteredByDescription() + { + String name = randomName(); + env.virtualAppliance.setName(name); + env.virtualAppliance.update(); + + EventOptions options = + EventOptions.builder().dateFrom(new Date()).virtualAppName(name) + .description("Virtual appliance '" + name + "' has been modified.").build(); + assertEvents(options); + } + + // Helpers + + private void assertEvents(final EventOptions options) + { + Iterable events = env.eventService.listEvents(options); + assertTrue(Iterables.size(events) >= 1); + } + + private Volume createVolume() + { + Tier tier = env.virtualDatacenter.findStorageTier(TierPredicates.name(env.tier.getName())); + Volume volume = + Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) + .name(PREFIX + "Event vol").sizeInMb(32).build(); + + volume.save(); + assertNotNull(volume.getId()); + + return volume; + } + + private VirtualMachine createVirtualMachine() + { + VirtualMachine virtualMachine = + VirtualMachine.builder(env.context.getApiContext(), env.virtualAppliance, env.template) + .cpu(2).ram(128).build(); + + virtualMachine.save(); + assertNotNull(virtualMachine.getId()); + + return virtualMachine; + } + + private static String randomName() + { + return PREFIX + UUID.randomUUID().toString().substring(0, 12); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java new file mode 100644 index 0000000000..18aa3e98ba --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java @@ -0,0 +1,91 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link Blade} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "ucs", testName = "BladeLiveUcsTest") +public class BladeLiveUcsTest extends BaseAbiquoApiLiveApiTest +{ + Blade blade; + + public void testFindAvailableVirtualSwitch() + { + String vswitch = blade.getAvailableVirtualSwitches().get(0); + String found = blade.findAvailableVirtualSwitch(vswitch); + assertEquals(found, vswitch); + } + + public void testGetRack() + { + ManagedRack rack = blade.getRack(); + assertNotNull(rack); + assertEquals(rack.getId(), env.ucsRack.getId()); + } + + public void testListBlades() + { + Iterable blades = env.ucsRack.listMachines(); + assertTrue(Iterables.size(blades) > 0); + } + + public void testGetLogicServer() + { + LogicServer logicServer = blade.getLogicServer(); + assertNotNull(logicServer); + assertNotNull(logicServer.getName()); + } + + public void testLedOn() + { + blade.ledOn(); + BladeLocatorLed led = blade.getLocatorLed(); + assertNotNull(led); + assertEquals(led.getAdminStatus(), "on"); + } + + public void testLedOff() + { + blade.ledOff(); + BladeLocatorLed led = blade.getLocatorLed(); + assertNotNull(led); + assertEquals(led.getAdminStatus(), "off"); + } + + @BeforeClass + public void setup() + { + blade = env.ucsRack.listMachines().get(0); + assertNotNull(blade); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java new file mode 100644 index 0000000000..650960dd56 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.enterprise.Limits; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.infrastructure.Datacenter.Builder; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.server.core.infrastructure.DatacenterDto; + +/** + * Live integration tests for the {@link Datacenter} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "DatacenterLiveApiTest") +public class DatacenterLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + env.datacenter.setLocation("New York"); + env.datacenter.update(); + + // Recover the updated datacenter + DatacenterDto updated = env.infrastructureApi.getDatacenter(env.datacenter.getId()); + + assertEquals(updated.getLocation(), "New York"); + } + + public void testCheckHypervisorType() + { + HypervisorType type = env.datacenter.getHypervisorType(env.machine.getIp()); + + assertEquals(env.machine.getType(), type); + } + + public void testCreateRepeated() + { + Datacenter repeated = Builder.fromDatacenter(env.datacenter).build(); + + try + { + repeated.save(); + fail("Should not be able to create datacenters with the same name"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "DC-3"); + } + } + + public void testListLimits() + { + List limits = env.datacenter.listLimits(); + assertNotNull(limits); + assertTrue(limits.size() > 0); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java new file mode 100644 index 0000000000..67c1d7403d --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java @@ -0,0 +1,171 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.RemoteServicePredicates; +import org.jclouds.abiquo.util.Config; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.MachineState; +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.server.core.infrastructure.MachineDto; + +/** + * Live integration tests for the {@link Machine} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "MachineLiveApiTest") +public class MachineLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testDiscoverMachineWithouRemoteService() + { + // Delete node collector + RemoteService nc = + env.datacenter.findRemoteService(RemoteServicePredicates + .type(RemoteServiceType.NODE_COLLECTOR)); + nc.delete(); + + try + { + String ip = Config.get("abiquo.hypervisor.address"); + HypervisorType type = HypervisorType.valueOf(Config.get("abiquo.hypervisor.type")); + String user = Config.get("abiquo.hypervisor.user"); + String pass = Config.get("abiquo.hypervisor.pass"); + + env.datacenter.discoverSingleMachine(ip, type, user, pass); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.NOT_FOUND, "RS-2"); + } + + URI endpoint = URI.create(env.context.getApiContext().getProviderMetadata().getEndpoint()); + + // Restore rs + nc = + RemoteService.builder(env.context.getApiContext(), env.datacenter) + .type(RemoteServiceType.NODE_COLLECTOR).ip(endpoint.getHost()).build(); + nc.save(); + } + + public void testUpdate() + { + env.machine.setName("API Machine"); + env.machine.update(); + + // Recover the updated machine + MachineDto updated = + env.infrastructureApi.getMachine(env.rack.unwrap(), env.machine.getId()); + assertEquals(updated.getName(), "API Machine"); + } + + public void testCheck() + { + MachineState state = env.machine.check(); + + // Recover the machine with same state that has been returned + MachineDto machine = + env.infrastructureApi.getMachine(env.rack.unwrap(), env.machine.getId()); + assertEquals(machine.getState(), state); + } + + public void testCheckFromDatacenter() + { + String ip = Config.get("abiquo.hypervisor.address"); + HypervisorType type = HypervisorType.valueOf(Config.get("abiquo.hypervisor.type")); + String user = Config.get("abiquo.hypervisor.user"); + String pass = Config.get("abiquo.hypervisor.pass"); + + MachineState state = env.datacenter.checkMachineState(ip, type, user, pass); + + // Recover the same machine and compare states + MachineDto machine = + env.infrastructureApi.getMachine(env.rack.unwrap(), env.machine.getId()); + assertEquals(machine.getState(), state); + } + + public void testFindDatastore() + { + Datastore datastore = env.machine.getDatastores().get(0); + Datastore found = env.machine.findDatastore(datastore.getName()); + assertEquals(found.getName(), datastore.getName()); + } + + public void testFindAvailableVirtualSwitch() + { + String vswitch = env.machine.getAvailableVirtualSwitches().get(0); + String found = env.machine.findAvailableVirtualSwitch(vswitch); + assertEquals(found, vswitch); + } + + public void testGetRack() + { + Rack rack = env.machine.getRack(); + assertNotNull(rack); + assertEquals(rack.getId(), env.rack.getId()); + } + + public void testListVirtualMachines() + { + List machines = env.machine.listRemoteVirtualMachines(); + assertNotNull(machines); + assertTrue(machines.size() >= 0); + } + + public void testReserveMachine() + { + assertFalse(env.machine.isReserved()); + + env.machine.reserveFor(env.enterprise); + assertTrue(env.machine.isReserved()); + + Enterprise owner = env.machine.getOwnerEnterprise(); + assertNotNull(owner); + assertEquals(owner.getId(), env.enterprise.getId()); + } + + @Test(dependsOnMethods = "testReserveMachine") + public void testCancelReservation() + { + env.machine.cancelReservationFor(env.enterprise); + assertFalse(env.machine.isReserved()); + + Enterprise owner = env.machine.getOwnerEnterprise(); + assertNull(owner); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java new file mode 100644 index 0000000000..75ca5eb220 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java @@ -0,0 +1,123 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.LogicServerPredicates; +import org.jclouds.abiquo.predicates.infrastructure.ManagedRackPredicates; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link ManagedRack} domain class. + * + * @author Francesc Montserrat + */ +@Test(groups = "ucs", testName = "ManagedRackLiveUcsTest") +public class ManagedRackLiveUcsTest extends BaseAbiquoApiLiveApiTest +{ + private LogicServer logicServer; + + private Organization organization; + + public void testUpdate() + { + env.ucsRack.setShortDescription("Updated description"); + env.ucsRack.update(); + + // Recover the updated rack + UcsRackDto updated = + env.infrastructureApi.getManagedRack(env.datacenter.unwrap(), env.ucsRack.getId()); + + assertEquals(updated.getShortDescription(), "Updated description"); + } + + public void testListManagedRacks() + { + Iterable racks = env.datacenter.listManagedRacks(); + assertEquals(Iterables.size(racks), 1); + + racks = env.datacenter.listManagedRacks(ManagedRackPredicates.name(env.ucsRack.getName())); + assertEquals(Iterables.size(racks), 1); + } + + public void testFindRack() + { + ManagedRack rack = + env.datacenter.findManagedRack(ManagedRackPredicates.name(env.ucsRack.getName())); + assertNotNull(rack); + + rack = + env.datacenter.findManagedRack(ManagedRackPredicates.name(env.ucsRack.getName() + + "FAIL")); + assertNull(rack); + } + + public void testCloneLogicServer() + { + List originals = env.ucsRack.listServiceProfiles(); + assertNotNull(originals); + assertTrue(originals.size() > 0); + LogicServer original = originals.get(0); + + List organizations = env.ucsRack.listOrganizations(); + assertNotNull(organizations); + assertTrue(organizations.size() > 0); + organization = organizations.get(0); + + env.ucsRack.cloneLogicServer(original, organization, "jclouds"); + + logicServer = + env.ucsRack.findServiceProfile(LogicServerPredicates.name(organization.getDn() + "/" + + "ls-jclouds")); + assertNotNull(logicServer); + + String name = logicServer.getName(); + assertEquals(name.substring(name.length() - 7, name.length()), "jclouds"); + } + + @Test(dependsOnMethods = "testCloneLogicServer") + public void testListFsms() + { + List fsms = env.ucsRack.listFsm(logicServer.getName()); + assertNotNull(fsms); + assertTrue(fsms.size() > 0); + } + + @Test(dependsOnMethods = {"testCloneLogicServer", "testListFsms"}) + public void testDeleteLogicServer() + { + String name = logicServer.getName(); + + env.ucsRack.deleteLogicServer(logicServer); + + LogicServer profile = env.ucsRack.findServiceProfile(LogicServerPredicates.name(name)); + assertNull(profile); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java new file mode 100644 index 0000000000..0961998b02 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.jclouds.abiquo.predicates.infrastructure.RackPredicates.name; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.RackDto; +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link Rack} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "RackLiveApiTest") +public class RackLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + env.rack.setName("Updated rack"); + env.rack.update(); + + // Recover the updated rack + RackDto updated = env.infrastructureApi.getRack(env.datacenter.unwrap(), env.rack.getId()); + + assertEquals(updated.getName(), "Updated rack"); + } + + public void testListRacks() + { + Iterable racks = env.datacenter.listRacks(); + assertEquals(Iterables.size(racks), 1); + + racks = env.datacenter.listRacks(name(env.rack.getName())); + assertEquals(Iterables.size(racks), 1); + + racks = env.datacenter.listRacks(name(env.rack.getName() + "FAIL")); + assertEquals(Iterables.size(racks), 0); + } + + public void testFindRack() + { + Rack rack = env.datacenter.findRack(name(env.rack.getName())); + assertNotNull(rack); + + rack = env.datacenter.findRack(name(env.rack.getName() + "FAIL")); + assertNull(rack); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java new file mode 100644 index 0000000000..7cb1d1d3ec --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java @@ -0,0 +1,131 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.jclouds.abiquo.predicates.infrastructure.RemoteServicePredicates.type; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.net.URI; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.infrastructure.RemoteService.Builder; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.server.core.infrastructure.RemoteServiceDto; +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link RemoteService} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "RemoteServiceLiveApiTest") +public class RemoteServiceLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testUpdate() + { + // Update the remote service + RemoteService rs = + env.datacenter.findRemoteService(type(RemoteServiceType.VIRTUAL_FACTORY)); + rs.setUri(rs.getUri()); + rs.update(); + + // Recover the updated remote service + RemoteServiceDto updated = + env.infrastructureApi.getRemoteService(env.datacenter.unwrap(), + RemoteServiceType.VIRTUAL_FACTORY); + + assertEquals(updated.getUri(), rs.getUri()); + } + + public void testDelete() + { + RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.BPM_SERVICE)); + rs.delete(); + + // Recover the deleted remote service + RemoteServiceDto deleted = + env.infrastructureApi.getRemoteService(env.datacenter.unwrap(), + RemoteServiceType.BPM_SERVICE); + + assertNull(deleted); + + URI endpoint = URI.create(env.context.getApiContext().getProviderMetadata().getEndpoint()); + + // Restore rs + RemoteService bpm = + RemoteService.builder(env.context.getApiContext(), env.datacenter) + .type(RemoteServiceType.BPM_SERVICE).ip(endpoint.getHost()).build(); + bpm.save(); + } + + public void testIsAvailableNonCheckeable() + { + RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.DHCP_SERVICE)); + assertTrue(rs.isAvailable()); + } + + public void testIsAvailable() + { + RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.NODE_COLLECTOR)); + assertTrue(rs.isAvailable()); + } + + public void testCreateRepeated() + { + RemoteService repeated = Builder.fromRemoteService(env.remoteServices.get(1)).build(); + + try + { + repeated.save(); + fail("Should not be able to create duplicated remote services in the datacenter"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "RS-6"); + } + } + + public void testListRemoteServices() + { + Iterable remoteServices = env.datacenter.listRemoteServices(); + assertEquals(Iterables.size(remoteServices), env.remoteServices.size()); + + remoteServices = env.datacenter.listRemoteServices(type(RemoteServiceType.NODE_COLLECTOR)); + assertEquals(Iterables.size(remoteServices), 1); + } + + public void testFindRemoteService() + { + RemoteService remoteService = + env.datacenter.findRemoteService(type(RemoteServiceType.NODE_COLLECTOR)); + assertNotNull(remoteService); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java new file mode 100644 index 0000000000..4b3cf4ce4f --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java @@ -0,0 +1,85 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.StorageDevicePredicates; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link StorageDevice} domain class. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "StorageDeviceLiveApiTest") +public class StorageDeviceLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + env.storageDevice.setName("Updated storage device"); + env.storageDevice.update(); + + // Recover the updated storage device + StorageDeviceDto updated = + env.infrastructureApi.getStorageDevice(env.datacenter.unwrap(), + env.storageDevice.getId()); + + assertEquals(updated.getName(), "Updated storage device"); + } + + public void testListStorageDevices() + { + Iterable storageDevices = env.datacenter.listStorageDevices(); + assertEquals(Iterables.size(storageDevices), 1); + + storageDevices = + env.datacenter.listStorageDevices(StorageDevicePredicates.name(env.storageDevice + .getName())); + assertEquals(Iterables.size(storageDevices), 1); + + storageDevices = + env.datacenter.listStorageDevices(StorageDevicePredicates.name(env.storageDevice + .getName() + "FAIL")); + assertEquals(Iterables.size(storageDevices), 0); + } + + public void testFindStorageDevice() + { + StorageDevice storageDevice = + env.datacenter.findStorageDevice(StorageDevicePredicates.name(env.storageDevice + .getName())); + assertNotNull(storageDevice); + + storageDevice = + env.datacenter.findStorageDevice(StorageDevicePredicates.name(env.storageDevice + .getName() + "FAIL")); + assertNull(storageDevice); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java new file mode 100644 index 0000000000..4bfa7951aa --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java @@ -0,0 +1,103 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.StoragePoolPredicates; +import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link StorageDevice} domain class. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "StoragePoolLiveApiTest") +public class StoragePoolLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testGetDevice() + { + StorageDevice device = env.storagePool.getStorageDevice(); + assertNotNull(device); + assertEquals(device.getId(), env.storageDevice.getId()); + } + + public void testUpdate() + { + try + { + Tier tier3 = env.datacenter.findTier(TierPredicates.name("Default Tier 3")); + assertNotNull(tier3); + env.storagePool.setTier(tier3); + env.storagePool.update(); + + assertEquals(env.storagePool.getTier().getName(), "Default Tier 3"); + } + finally + { + // Restore the original tier + env.storagePool.setTier(env.tier); + env.storagePool.update(); + assertEquals(env.storagePool.getTier().getId(), env.tier.getId()); + } + } + + public void testListStoragePool() + { + Iterable storagePools = env.storageDevice.listStoragePools(); + assertEquals(Iterables.size(storagePools), 1); + + storagePools = + env.storageDevice + .listStoragePools(StoragePoolPredicates.name(env.storagePool.getName())); + assertEquals(Iterables.size(storagePools), 1); + + storagePools = + env.storageDevice.listStoragePools(StoragePoolPredicates.name(env.storagePool.getName() + + "FAIL")); + assertEquals(Iterables.size(storagePools), 0); + } + + public void testFindStoragePool() + { + StoragePool storagePool = + env.storageDevice + .findStoragePool(StoragePoolPredicates.name(env.storagePool.getName())); + assertNotNull(storagePool); + + storagePool = + env.storageDevice.findStoragePool(StoragePoolPredicates.name(env.storagePool.getName() + + "FAIL")); + assertNull(storagePool); + } + + public void testRefreshStoragePool() + { + env.storagePool.refresh(); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java new file mode 100644 index 0000000000..1599452536 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.infrastructure; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Live integration tests for the {@link StorageDevice} domain class. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "TierLiveApiTest") +public class TierLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + + public void testUpdate() + { + Tier tier = env.datacenter.listTiers().get(0); + assertNotNull(tier); + + String previousName = tier.getName(); + tier.setName("Updated tier"); + tier.update(); + + // Recover the updated tier + Tier updated = env.datacenter.findTier(TierPredicates.name("Updated tier")); + assertEquals(updated.getName(), "Updated tier"); + + // Set original name + tier.setName(previousName); + tier.update(); + } + + public void testListTiers() + { + Iterable tiers = env.datacenter.listTiers(); + assertEquals(Iterables.size(tiers), 4); + + tiers = env.datacenter.listTiers(TierPredicates.name("FAIL")); + assertEquals(Iterables.size(tiers), 0); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java new file mode 100644 index 0000000000..5c0c0454cb --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java @@ -0,0 +1,186 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.jclouds.abiquo.predicates.network.NetworkPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; + +/** + * Live integration tests for the {@link ExternalNetwork} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ExternalNetworkLiveApiTest") +public class ExternalNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private ExternalNetwork externalNetwork; + + @BeforeClass + public void setupNetwork() + { + externalNetwork = createNetwork(env.externalNetwork, PREFIX + "-externalnetwork-test"); + } + + @AfterClass + public void tearDownNetwork() + { + externalNetwork.delete(); + } + + public void testListIps() + { + ExternalIpsDto ipsDto = + env.context.getApiContext().getApi().getInfrastructureApi() + .listExternalIps(externalNetwork.unwrap(), IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = externalNetwork.listIps(); + + assertEquals(ips.size(), totalIps); + } + + public void testListIpsWithOptions() + { + List ips = externalNetwork.listIps(IpOptions.builder().limit(5).build()); + assertEquals(ips.size(), 5); + } + + public void testListUnusedIps() + { + ExternalIpsDto ipsDto = + env.context.getApiContext().getApi().getInfrastructureApi() + .listExternalIps(externalNetwork.unwrap(), IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = externalNetwork.listUnusedIps(); + assertEquals(ips.size(), totalIps); + } + + public void testUpdateBasicInfo() + { + externalNetwork.setName("External network Updated"); + externalNetwork.setPrimaryDNS("8.8.8.8"); + externalNetwork.setSecondaryDNS("8.8.8.8"); + externalNetwork.update(); + + assertEquals(externalNetwork.getName(), "External network Updated"); + assertEquals(externalNetwork.getPrimaryDNS(), "8.8.8.8"); + assertEquals(externalNetwork.getSecondaryDNS(), "8.8.8.8"); + + // Refresh the external network + ExternalNetwork en = + env.enterprise.findExternalNetwork(env.datacenter, + NetworkPredicates. name(externalNetwork.getName())); + + assertEquals(en.getId(), externalNetwork.getId()); + assertEquals(en.getName(), "External network Updated"); + assertEquals(en.getPrimaryDNS(), "8.8.8.8"); + assertEquals(en.getSecondaryDNS(), "8.8.8.8"); + } + + public void testUpdateReadOnlyFields() + { + ExternalNetwork toUpdate = createNetwork(externalNetwork, PREFIX + "-exttoupdate-test"); + + try + { + toUpdate.setTag(20); + toUpdate.setAddress("10.1.0.0"); + toUpdate.setMask(16); + toUpdate.update(); + + fail("Tag field should not be editable"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "VLAN-19"); + } + finally + { + toUpdate.delete(); + } + } + + public void testUpdateWithInvalidValues() + { + ExternalNetwork toUpdate = createNetwork(externalNetwork, PREFIX + "-exttoupdate-test"); + + try + { + toUpdate.setMask(60); + toUpdate.update(); + + fail("Invalid mask value"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); + } + finally + { + toUpdate.delete(); + } + } + + public void testGetEnterprise() + { + assertEquals(externalNetwork.getEnterprise().getId(), env.enterprise.getId()); + } + + public void testGetDatacenter() + { + assertEquals(externalNetwork.getDatacenter().getId(), env.datacenter.getId()); + } + + public void testGetNetworkFromIp() + { + ExternalIp ip = externalNetwork.findIp(IpPredicates. notUsed()); + ExternalNetwork network = ip.getNetwork(); + + assertEquals(network.getId(), externalNetwork.getId()); + } + + private ExternalNetwork createNetwork(final ExternalNetwork from, final String name) + { + ExternalNetwork network = ExternalNetwork.Builder.fromExternalNetwork(from).build(); + network.setName(name); + network.save(); + assertNotNull(network.getId()); + return network; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java new file mode 100644 index 0000000000..411af0ff30 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java @@ -0,0 +1,93 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.NetworkType; + +/** + * Live integration tests for the {@link Network} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "GenericNetworkLiveApiTest") +public class GenericNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + public void testListDatacenterNetworks() + { + // Make sure all network types are listed + List> networks = env.datacenter.listNetworks(); + assertNotNull(networks); + assertEquals(networks.size(), 3); + } + + public void testListPublicNetworks() + { + List> networks = env.datacenter.listNetworks(NetworkType.PUBLIC); + assertNotNull(networks); + assertEquals(networks.size(), 1); + + // Make sure it can be converted + networks.get(0).toPublicNetwork(); + } + + public void testListExternaletworks() + { + List> networks = env.datacenter.listNetworks(NetworkType.EXTERNAL); + assertNotNull(networks); + assertEquals(networks.size(), 1); + + // Make sure it can be converted + networks.get(0).toExternalNetwork(); + } + + public void testListUnmanagedNetworks() + { + List> networks = env.datacenter.listNetworks(NetworkType.UNMANAGED); + assertNotNull(networks); + assertEquals(networks.size(), 1); + + // Make sure it can be converted + networks.get(0).toUnmanagedNetwork(); + } + + public void testListPrivateNetworks() + { + try + { + env.datacenter.listNetworks(NetworkType.INTERNAL); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.BAD_REQUEST, "QUERY-1"); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java new file mode 100644 index 0000000000..ca6bbff464 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java @@ -0,0 +1,187 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; + +/** + * Live integration tests for the {@link PrivateNetwork} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "PrivateNetworkLiveApiTest") +public class PrivateNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private PrivateNetwork privateNetwork; + + @BeforeClass + public void setupNetwork() + { + privateNetwork = + createNetwork(env.virtualDatacenter, env.privateNetwork, PREFIX + + "-privatenetwork-test"); + } + + @AfterClass + public void tearDownNetwork() + { + privateNetwork.delete(); + } + + public void testListIps() + { + PrivateIpsDto ipsDto = + env.context + .getApiContext() + .getApi() + .getCloudApi() + .listPrivateNetworkIps(privateNetwork.unwrap(), + IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = privateNetwork.listIps(); + + assertEquals(ips.size(), totalIps); + } + + public void testListIpsWithOptions() + { + List ips = privateNetwork.listIps(IpOptions.builder().limit(5).build()); + assertEquals(ips.size(), 5); + } + + public void testListUnusedIps() + { + PrivateIpsDto ipsDto = + env.context + .getApiContext() + .getApi() + .getCloudApi() + .listPrivateNetworkIps(privateNetwork.unwrap(), + IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = privateNetwork.listUnusedIps(); + assertEquals(ips.size(), totalIps); + } + + public void testUpdateBasicInfo() + { + privateNetwork.setName("Private network Updated"); + privateNetwork.setPrimaryDNS("8.8.8.8"); + privateNetwork.setSecondaryDNS("8.8.8.8"); + privateNetwork.update(); + + assertEquals(privateNetwork.getName(), "Private network Updated"); + assertEquals(privateNetwork.getPrimaryDNS(), "8.8.8.8"); + assertEquals(privateNetwork.getSecondaryDNS(), "8.8.8.8"); + + // Refresh the private network + PrivateNetwork pn = env.virtualDatacenter.getPrivateNetwork(privateNetwork.getId()); + + assertEquals(pn.getName(), "Private network Updated"); + assertEquals(pn.getPrimaryDNS(), "8.8.8.8"); + assertEquals(pn.getSecondaryDNS(), "8.8.8.8"); + } + + public void testUpdateReadOnlyFields() + { + PrivateNetwork toUpdate = + createNetwork(env.virtualDatacenter, privateNetwork, PREFIX + "-privtoupdate-test"); + + try + { + toUpdate.setTag(20); + toUpdate.setAddress("10.1.1.0"); + toUpdate.setMask(16); + toUpdate.update(); + + fail("Tag field should not be editable"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "VLAN-10"); + } + finally + { + toUpdate.delete(); + } + } + + public void testUpdateWithInvalidValues() + { + PrivateNetwork toUpdate = + createNetwork(env.virtualDatacenter, privateNetwork, PREFIX + "-privtoupdate-test"); + + try + { + toUpdate.setMask(60); + toUpdate.update(); + + fail("Invalid mask value"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); + } + finally + { + toUpdate.delete(); + } + } + + public void testGetNetworkFromIp() + { + PrivateIp ip = privateNetwork.findIp(IpPredicates. notUsed()); + PrivateNetwork network = ip.getNetwork(); + + assertEquals(network.getId(), privateNetwork.getId()); + } + + private PrivateNetwork createNetwork(final VirtualDatacenter vdc, final PrivateNetwork from, + final String name) + { + PrivateNetwork network = + PrivateNetwork.Builder.fromPrivateNetwork(from).virtualDatacenter(vdc).build(); + network.setName(name); + network.save(); + assertNotNull(network.getId()); + return network; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java new file mode 100644 index 0000000000..4456a1bc21 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java @@ -0,0 +1,178 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; + +/** + * Live integration tests for the {@link PublicNetwork} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "PublicNetworkLiveApiTest") +public class PublicNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private PublicNetwork publicNetwork; + + @BeforeClass + public void setupNetwork() + { + publicNetwork = createNetwork(env.publicNetwork, PREFIX + "-publicnetwork-test"); + } + + @AfterClass + public void tearDownNetwork() + { + publicNetwork.delete(); + } + + public void testListIps() + { + PublicIpsDto ipsDto = + env.context.getApiContext().getApi().getInfrastructureApi() + .listPublicIps(publicNetwork.unwrap(), IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = publicNetwork.listIps(); + + assertEquals(ips.size(), totalIps); + } + + public void testListIpsWithOptions() + { + List ips = publicNetwork.listIps(IpOptions.builder().limit(5).build()); + assertEquals(ips.size(), 5); + } + + public void testListUnusedIps() + { + PublicIpsDto ipsDto = + env.context.getApiContext().getApi().getInfrastructureApi() + .listPublicIps(publicNetwork.unwrap(), IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = publicNetwork.listUnusedIps(); + assertEquals(ips.size(), totalIps); + } + + public void testUpdateBasicInfo() + { + publicNetwork.setName("Public network Updated"); + publicNetwork.setPrimaryDNS("8.8.8.8"); + publicNetwork.setSecondaryDNS("8.8.8.8"); + publicNetwork.update(); + + assertEquals(publicNetwork.getName(), "Public network Updated"); + assertEquals(publicNetwork.getPrimaryDNS(), "8.8.8.8"); + assertEquals(publicNetwork.getSecondaryDNS(), "8.8.8.8"); + + // Refresh the public network + PublicNetwork pn = env.datacenter.getNetwork(publicNetwork.getId()).toPublicNetwork(); + + assertEquals(pn.getId(), publicNetwork.getId()); + assertEquals(pn.getName(), "Public network Updated"); + assertEquals(pn.getPrimaryDNS(), "8.8.8.8"); + assertEquals(pn.getSecondaryDNS(), "8.8.8.8"); + } + + public void testUpdateReadOnlyFields() + { + PublicNetwork toUpdate = createNetwork(publicNetwork, PREFIX + "-pubtoupdate-test"); + + try + { + toUpdate.setTag(20); + toUpdate.setAddress("80.81.81.0"); + toUpdate.setMask(16); + toUpdate.update(); + + fail("Tag field should not be editable"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "VLAN-19"); + } + finally + { + toUpdate.delete(); + } + } + + public void testUpdateWithInvalidValues() + { + PublicNetwork toUpdate = createNetwork(publicNetwork, PREFIX + "-pubtoupdate-test"); + + try + { + toUpdate.setMask(60); + toUpdate.update(); + + fail("Invalid mask value"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); + } + finally + { + toUpdate.delete(); + } + } + + public void testGetDatacenter() + { + assertEquals(publicNetwork.getDatacenter().getId(), env.datacenter.getId()); + } + + public void testGetNetworkFromIp() + { + PublicIp ip = publicNetwork.findIp(IpPredicates. notUsed()); + PublicNetwork network = ip.getNetwork(); + + assertEquals(network.getId(), publicNetwork.getId()); + } + + private PublicNetwork createNetwork(final PublicNetwork from, final String name) + { + PublicNetwork network = PublicNetwork.Builder.fromPublicNetwork(from).build(); + network.setName(name); + network.save(); + assertNotNull(network.getId()); + return network; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java new file mode 100644 index 0000000000..596e54d719 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java @@ -0,0 +1,187 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.domain.network; + +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.jclouds.abiquo.util.Assert.assertHasError; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.fail; + +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.jclouds.abiquo.predicates.network.NetworkPredicates; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; + +/** + * Live integration tests for the {@link UnmanagedNetwork} domain class. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "UnmanagedNetworkLiveApiTest") +public class UnmanagedNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + private UnmanagedNetwork unmanagedNetwork; + + @BeforeClass + public void setupNetwork() + { + unmanagedNetwork = createNetwork(env.unmanagedNetwork, PREFIX + "-unmanagednetwork-test"); + } + + @AfterClass + public void tearDownNetwork() + { + unmanagedNetwork.delete(); + } + + public void testListIps() + { + UnmanagedIpsDto ipsDto = + env.context.getApiContext().getApi().getInfrastructureApi() + .listUnmanagedIps(unmanagedNetwork.unwrap(), IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = unmanagedNetwork.listIps(); + + assertEquals(ips.size(), totalIps); + } + + public void testListIpsWithOptions() + { + List ips = unmanagedNetwork.listIps(IpOptions.builder().limit(5).build()); + // Unmanaged networks do not have IPs until attached to VMs + assertEquals(ips.size(), 0); + } + + public void testListUnusedIps() + { + UnmanagedIpsDto ipsDto = + env.context.getApiContext().getApi().getInfrastructureApi() + .listUnmanagedIps(unmanagedNetwork.unwrap(), IpOptions.builder().limit(1).build()); + int totalIps = ipsDto.getTotalSize(); + + List ips = unmanagedNetwork.listUnusedIps(); + assertEquals(ips.size(), totalIps); + } + + public void testUpdateBasicInfo() + { + unmanagedNetwork.setName("Unmanaged network Updated"); + unmanagedNetwork.setPrimaryDNS("8.8.8.8"); + unmanagedNetwork.setSecondaryDNS("8.8.8.8"); + unmanagedNetwork.update(); + + assertEquals(unmanagedNetwork.getName(), "Unmanaged network Updated"); + assertEquals(unmanagedNetwork.getPrimaryDNS(), "8.8.8.8"); + assertEquals(unmanagedNetwork.getSecondaryDNS(), "8.8.8.8"); + + // Refresh the unmanaged network + UnmanagedNetwork en = + env.enterprise.findUnmanagedNetwork(env.datacenter, + NetworkPredicates. name(unmanagedNetwork.getName())); + + assertEquals(en.getId(), unmanagedNetwork.getId()); + assertEquals(en.getName(), "Unmanaged network Updated"); + assertEquals(en.getPrimaryDNS(), "8.8.8.8"); + assertEquals(en.getSecondaryDNS(), "8.8.8.8"); + } + + public void testUpdateReadOnlyFields() + { + UnmanagedNetwork toUpdate = createNetwork(unmanagedNetwork, PREFIX + "-umtoupdate-test"); + + try + { + toUpdate.setTag(20); + toUpdate.setAddress("10.2.0.0"); + toUpdate.setMask(16); + toUpdate.update(); + + fail("Tag field should not be editable"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.CONFLICT, "VLAN-19"); + } + finally + { + toUpdate.delete(); + } + } + + public void testUpdateWithInvalidValues() + { + UnmanagedNetwork toUpdate = createNetwork(unmanagedNetwork, PREFIX + "-umtoupdate-test"); + + try + { + toUpdate.setMask(60); + toUpdate.update(); + + fail("Invalid mask value"); + } + catch (AbiquoException ex) + { + assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); + } + finally + { + toUpdate.delete(); + } + } + + public void testGetEnterprise() + { + assertEquals(unmanagedNetwork.getEnterprise().getId(), env.enterprise.getId()); + } + + public void testGetDatacenter() + { + assertEquals(unmanagedNetwork.getDatacenter().getId(), env.datacenter.getId()); + } + + public void testGetNetworkFromIp() + { + UnmanagedIp ip = unmanagedNetwork.findIp(IpPredicates. notUsed()); + // Unmanaged networks do not have IPs until attached to VMs + assertNull(ip); + } + + private UnmanagedNetwork createNetwork(final UnmanagedNetwork from, final String name) + { + UnmanagedNetwork network = UnmanagedNetwork.Builder.fromUnmanagedNetwork(from).build(); + network.setName(name); + network.save(); + assertNotNull(network.getId()); + return network; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java new file mode 100644 index 0000000000..263f4aeeac --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java @@ -0,0 +1,250 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.environment; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import java.util.Collections; +import java.util.List; + +import org.jclouds.ContextBuilder; +import org.jclouds.abiquo.AbiquoApiMetadata; +import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PrivateNetwork; +import org.jclouds.abiquo.features.CloudApi; +import org.jclouds.abiquo.features.services.EventService; +import org.jclouds.abiquo.predicates.enterprise.EnterprisePredicates; +import org.jclouds.abiquo.predicates.network.NetworkPredicates; + +import com.google.common.collect.Ordering; +import com.google.common.primitives.Longs; + +/** + * Test environment for cloud live tests. + * + * @author Francesc Montserrat + */ +public class CloudTestEnvironment extends InfrastructureTestEnvironment +{ + + // Environment data made public so tests can use them easily + public CloudApi cloudApi; + + public EventService eventService; + + public VirtualDatacenter virtualDatacenter; + + public VirtualAppliance virtualAppliance; + + public VirtualMachine virtualMachine; + + public VirtualMachineTemplate template; + + public PrivateNetwork privateNetwork; + + public Enterprise defaultEnterprise; + + public AbiquoContext plainUserContext; + + public AbiquoContext enterpriseAdminContext; + + public CloudTestEnvironment(final AbiquoContext context) + { + super(context); + this.cloudApi = context.getApiContext().getApi().getCloudApi(); + this.eventService = context.getEventService(); + } + + @Override + public void setup() throws Exception + { + // Create base infrastructure + super.setup(); + + createUserContext(); + createEnterpriseAdminContext(); + + findDefaultEnterprise(); + createVirtualDatacenter(); + createVirtualAppliance(); + refreshTemplateRepository(); + createVirtualMachine(); + } + + @Override + public void tearDown() throws Exception + { + closeEnterpriseAdminContext(); + closeUserContext(); + + deleteVirtualMachine(); + deleteVirtualAppliance(); + deleteVirtualDatacenter(); + + // Delete base infrastructure + super.tearDown(); + } + + // Setup + + private void createUserContext() + { + String endpoint = + checkNotNull(System.getProperty("test.abiquo.endpoint"), "test.abiquo.endpoint"); + + plainUserContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // + .endpoint(endpoint) // + .credentials("abiquo", "jclouds") // + .build(AbiquoContext.class); + } + + private void createEnterpriseAdminContext() + { + String endpoint = + checkNotNull(System.getProperty("test.abiquo.endpoint"), "test.abiquo.endpoint"); + + enterpriseAdminContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // + .endpoint(endpoint) // + .credentials("jclouds-admin", "admin") // + .build(AbiquoContext.class); + } + + protected void findDefaultEnterprise() + { + defaultEnterprise = + context.getAdministrationService().findEnterprise(EnterprisePredicates.name("Abiquo")); + } + + protected void createVirtualDatacenter() + { + privateNetwork = + PrivateNetwork.builder(context.getApiContext()).name("DefaultNetwork") + .gateway("192.168.1.1").address("192.168.1.0").mask(24).build(); + + virtualDatacenter = + VirtualDatacenter.builder(context.getApiContext(), datacenter, defaultEnterprise) + .name(PREFIX + "Virtual Aloha").cpuCountLimits(18, 20) + .hdLimitsInMb(279172872, 279172872).publicIpsLimits(2, 3).ramLimits(19456, 20480) + .storageLimits(289910292, 322122547).vlansLimits(3, 4) + .hypervisorType(machine.getType()).network(privateNetwork).build(); + + virtualDatacenter.save(); + assertNotNull(virtualDatacenter.getId()); + + privateNetwork = + virtualDatacenter.findPrivateNetwork(NetworkPredicates. name(privateNetwork + .getName())); + } + + protected void createVirtualAppliance() + { + virtualAppliance = + VirtualAppliance.builder(context.getApiContext(), virtualDatacenter) + .name(PREFIX + "Virtual AppAloha").build(); + + virtualAppliance.save(); + assertNotNull(virtualAppliance.getId()); + } + + protected void createVirtualMachine() + { + List templates = virtualDatacenter.listAvailableTemplates(); + assertFalse(templates.isEmpty()); + + // Sort by size to use the smallest one + Collections.sort(templates, new Ordering() + { + @Override + public int compare(final VirtualMachineTemplate left, final VirtualMachineTemplate right) + { + return Longs.compare(left.getDiskFileSize(), right.getDiskFileSize()); + } + }); + + template = templates.get(0); + + virtualMachine = + VirtualMachine.builder(context.getApiContext(), virtualAppliance, template).cpu(2) + .nameLabel(PREFIX + "VM Aloha").ram(128).build(); + + virtualMachine.save(); + assertNotNull(virtualMachine.getId()); + + } + + protected void refreshTemplateRepository() + { + defaultEnterprise.refreshTemplateRepository(datacenter); + } + + // Tear down + + private void closeUserContext() + { + plainUserContext.close(); + } + + private void closeEnterpriseAdminContext() + { + enterpriseAdminContext.close(); + } + + protected void deleteVirtualDatacenter() + { + if (virtualDatacenter != null && enterprise != null && datacenter != null) + { + Integer idVirtualDatacenter = virtualDatacenter.getId(); + virtualDatacenter.delete(); + assertNull(cloudApi.getVirtualDatacenter(idVirtualDatacenter)); + } + } + + protected void deleteVirtualAppliance() + { + if (virtualAppliance != null && virtualDatacenter != null) + { + Integer idVirtualAppliance = virtualAppliance.getId(); + virtualAppliance.delete(); + assertNull(cloudApi.getVirtualAppliance(virtualDatacenter.unwrap(), idVirtualAppliance)); + } + } + + protected void deleteVirtualMachine() + { + if (virtualMachine != null && virtualAppliance != null && virtualDatacenter != null) + { + Integer idVirtualMachine = virtualMachine.getId(); + virtualMachine.delete(); + assertNull(cloudApi.getVirtualMachine(virtualAppliance.unwrap(), idVirtualMachine)); + } + + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java new file mode 100644 index 0000000000..ead8ac5ead --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java @@ -0,0 +1,531 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.environment; + +import static com.google.common.collect.Iterables.find; +import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.List; +import java.util.UUID; + +import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.abiquo.domain.config.License; +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.domain.enterprise.Limits; +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.domain.enterprise.User; +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.domain.infrastructure.Datastore; +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.domain.infrastructure.ManagedRack; +import org.jclouds.abiquo.domain.infrastructure.Rack; +import org.jclouds.abiquo.domain.infrastructure.RemoteService; +import org.jclouds.abiquo.domain.infrastructure.StorageDevice; +import org.jclouds.abiquo.domain.infrastructure.StorageDeviceMetadata; +import org.jclouds.abiquo.domain.infrastructure.StoragePool; +import org.jclouds.abiquo.domain.infrastructure.Tier; +import org.jclouds.abiquo.domain.network.ExternalNetwork; +import org.jclouds.abiquo.domain.network.PublicNetwork; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.abiquo.features.AdminApi; +import org.jclouds.abiquo.features.ConfigApi; +import org.jclouds.abiquo.features.EnterpriseApi; +import org.jclouds.abiquo.features.InfrastructureApi; +import org.jclouds.abiquo.features.services.AdministrationService; +import org.jclouds.abiquo.predicates.enterprise.RolePredicates; +import org.jclouds.abiquo.predicates.enterprise.UserPredicates; +import org.jclouds.abiquo.predicates.infrastructure.RemoteServicePredicates; +import org.jclouds.abiquo.predicates.infrastructure.StorageDeviceMetadataPredicates; +import org.jclouds.abiquo.predicates.infrastructure.StoragePoolPredicates; +import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; +import org.jclouds.abiquo.reference.AbiquoEdition; +import org.jclouds.abiquo.util.Config; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.RemoteServiceType; +import com.google.common.collect.Iterables; +import com.google.common.io.Resources; + +/** + * Test environment for infrastructure live tests. + * + * @author Ignasi Barrera + */ +public class InfrastructureTestEnvironment implements TestEnvironment +{ + /** The rest context. */ + public AbiquoContext context; + + // Environment data made public so tests can use them easily + + public AdministrationService administrationService; + + public InfrastructureApi infrastructureApi; + + public EnterpriseApi enterpriseApi; + + public AdminApi adminApi; + + public ConfigApi configApi; + + // Resources + + public License license; + + public Datacenter datacenter; + + public PublicNetwork publicNetwork; + + public ExternalNetwork externalNetwork; + + public UnmanagedNetwork unmanagedNetwork; + + public List remoteServices; + + public Rack rack; + + public Machine machine; + + public Enterprise enterprise; + + public StorageDevice storageDevice; + + public StoragePool storagePool; + + public Tier tier; + + public User user; + + public User enterpriseAdmin; + + public Role role; + + public Role anotherRole; + + public ManagedRack ucsRack; + + public InfrastructureTestEnvironment(final AbiquoContext context) + { + super(); + this.context = context; + this.administrationService = context.getAdministrationService(); + this.context = context; + this.enterpriseApi = context.getApiContext().getApi().getEnterpriseApi(); + this.infrastructureApi = context.getApiContext().getApi().getInfrastructureApi(); + this.adminApi = context.getApiContext().getApi().getAdminApi(); + this.configApi = context.getApiContext().getApi().getConfigApi(); + } + + @Override + public void setup() throws Exception + { + // Configuration + createLicense(); + + // Intrastructure + createDatacenter(); + createRack(); + createMachine(); + createStorageDevice(); + createStoragePool(); + createPublicNetwork(); + + // Enterprise + createEnterprise(); + createRoles(); + createUsers(); + + // Networking + createExternalNetwork(); + createUnmanagedNetwork(); + } + + @Override + public void tearDown() throws Exception + { + deleteUsers(); + + deleteRole(role); + deleteRole(anotherRole); + + deleteUnmanagedNetwork(); + deleteExternalNetwork(); + deletePublicNetwork(); + deleteStoragePool(); + deleteStorageDevice(); + deleteMachine(); + deleteUcsRack(); + deleteRack(); + deleteDatacenter(); + deleteEnterprise(); + + deleteLicense(); + } + + // Setup + + protected void createLicense() throws IOException + { + license = License.builder(context.getApiContext(), readLicense()).build(); + + license.add(); + assertNotNull(license.getId()); + } + + protected void createDatacenter() + { + // Assume a monolithic install + URI endpoint = URI.create(context.getApiContext().getProviderMetadata().getEndpoint()); + String remoteServicesAddress = endpoint.getHost(); + + datacenter = + Datacenter.builder(context.getApiContext()).name(randomName()).location("Honolulu") + .remoteServices(remoteServicesAddress, AbiquoEdition.ENTERPRISE).build(); + datacenter.save(); + assertNotNull(datacenter.getId()); + + remoteServices = datacenter.listRemoteServices(); + assertEquals(remoteServices.size(), 7); + } + + protected void createMachine() + { + String ip = Config.get("abiquo.hypervisor.address"); + HypervisorType type = HypervisorType.valueOf(Config.get("abiquo.hypervisor.type")); + String user = Config.get("abiquo.hypervisor.user"); + String pass = Config.get("abiquo.hypervisor.pass"); + + machine = datacenter.discoverSingleMachine(ip, type, user, pass); + + String vswitch = + machine.findAvailableVirtualSwitch(Config.get("abiquo.hypervisor.vswitch")); + machine.setVirtualSwitch(vswitch); + + Datastore datastore = machine.findDatastore(Config.get("abiquo.hypervisor.datastore")); + datastore.setEnabled(true); + + machine.setRack(rack); + machine.save(); + assertNotNull(machine.getId()); + } + + protected void createRack() + { + rack = Rack.builder(context.getApiContext(), datacenter).name(PREFIX + "Aloha").build(); + rack.save(); + assertNotNull(rack.getId()); + } + + public void createUcsRack() + { + String ip = Config.get("abiquo.ucs.address"); + Integer port = Integer.parseInt(Config.get("abiquo.ucs.port")); + String user = Config.get("abiquo.ucs.user"); + String pass = Config.get("abiquo.ucs.pass"); + + ucsRack = + ManagedRack.builder(context.getApiContext(), datacenter).ipAddress(ip).port(port) + .user(user).name("ucs rack").password(pass).build(); + + ucsRack.save(); + assertNotNull(ucsRack.getId()); + } + + protected void createStorageDevice() + { + String ip = Config.get("abiquo.storage.address"); + String type = Config.get("abiquo.storage.type"); + String user = Config.get("abiquo.storage.user"); + String pass = Config.get("abiquo.storage.pass"); + + List devices = datacenter.listSupportedStorageDevices(); + StorageDeviceMetadata metadata = + Iterables.find(devices, StorageDeviceMetadataPredicates.type(type)); + + storageDevice = StorageDevice.builder(context.getApiContext(), datacenter) // + .name(PREFIX + "Storage Device")// + .type(type)// + .managementIp(ip).managementPort(metadata.getDefaultManagementPort())// + .iscsiIp(ip).iscsiPort(metadata.getDefaultIscsiPort()) // + .username(user)// + .password(pass) // + .build(); + + storageDevice.save(); + assertNotNull(storageDevice.getId()); + } + + protected void createStoragePool() + { + String pool = Config.get("abiquo.storage.pool"); + + storagePool = storageDevice.findRemoteStoragePool(StoragePoolPredicates.name(pool)); + tier = datacenter.findTier(TierPredicates.name("Default Tier 1")); + + storagePool.setTier(tier); + storagePool.save(); + + assertNotNull(storagePool.getUUID()); + } + + protected void createUsers() + { + Role userRole = administrationService.findRole(RolePredicates.name("USER")); + Role enterpriseAdminRole = + administrationService.findRole(RolePredicates.name("ENTERPRISE_ADMIN")); + + user = + User.builder(context.getApiContext(), enterprise, userRole) + .name(randomName(), randomName()).nick("jclouds").authType("ABIQUO") + .description(randomName()).email(randomName() + "@abiquo.com").locale("en_US") + .password("user").build(); + + user.save(); + assertNotNull(user.getId()); + assertEquals(userRole.getId(), user.getRole().getId()); + + enterpriseAdmin = + User.builder(context.getApiContext(), enterprise, enterpriseAdminRole) + .name(randomName(), randomName()).nick("jclouds-admin").authType("ABIQUO") + .description(randomName()).email(randomName() + "@abiquo.com").locale("en_US") + .password("admin").build(); + + enterpriseAdmin.save(); + assertNotNull(enterpriseAdmin.getId()); + assertEquals(enterpriseAdminRole.getId(), enterpriseAdmin.getRole().getId()); + } + + protected void createRoles() + { + role = Role.builder(context.getApiContext()).name(randomName()).blocked(false).build(); + role.save(); + + anotherRole = Role.Builder.fromRole(role).build(); + anotherRole.setName("Another role"); + anotherRole.save(); + + assertNotNull(role.getId()); + assertNotNull(anotherRole.getId()); + } + + protected void createEnterprise() + { + enterprise = Enterprise.builder(context.getApiContext()).name(randomName()).build(); + enterprise.save(); + assertNotNull(enterprise.getId()); + Limits limits = enterprise.allowDatacenter(datacenter); + assertNotNull(limits); + } + + protected void createPublicNetwork() + { + publicNetwork = + PublicNetwork.builder(context.getApiContext(), datacenter).name("PublicNetwork") + .gateway("80.80.80.1").address("80.80.80.0").mask(24).tag(5).build(); + publicNetwork.save(); + assertNotNull(publicNetwork.getId()); + } + + protected void createExternalNetwork() + { + externalNetwork = + ExternalNetwork.builder(context.getApiContext(), datacenter, enterprise) + .name("ExternalNetwork").gateway("10.0.0.1").address("10.0.0.0").mask(24).tag(7) + .build(); + externalNetwork.save(); + assertNotNull(externalNetwork.getId()); + } + + protected void createUnmanagedNetwork() + { + unmanagedNetwork = + UnmanagedNetwork.builder(context.getApiContext(), datacenter, enterprise) + .name("UnmanagedNetwork").gateway("10.0.1.1").address("10.0.1.0").mask(24).tag(8) + .build(); + unmanagedNetwork.save(); + assertNotNull(unmanagedNetwork.getId()); + } + + // Tear down + + protected void deleteUnmanagedNetwork() + { + if (unmanagedNetwork != null) + { + Integer id = unmanagedNetwork.getId(); + unmanagedNetwork.delete(); + assertNull(datacenter.getNetwork(id)); + } + } + + protected void deleteExternalNetwork() + { + if (externalNetwork != null) + { + Integer id = externalNetwork.getId(); + externalNetwork.delete(); + assertNull(datacenter.getNetwork(id)); + } + } + + protected void deletePublicNetwork() + { + if (publicNetwork != null) + { + Integer id = publicNetwork.getId(); + publicNetwork.delete(); + assertNull(datacenter.getNetwork(id)); + } + } + + protected void deleteUsers() + { + if (user != null) + { + String nick = user.getNick(); + user.delete(); + // Nick is unique in an enterprise + assertNull(enterprise.findUser(UserPredicates.nick(nick))); + } + + if (enterpriseAdmin != null) + { + String nick = enterpriseAdmin.getNick(); + enterpriseAdmin.delete(); + // Nick is unique in an enterprise + assertNull(enterprise.findUser(UserPredicates.nick(nick))); + } + } + + protected void deleteRole(final Role role) + { + if (role != null) + { + Integer roleId = role.getId(); + role.delete(); + assertNull(adminApi.getRole(roleId)); + } + } + + protected void deleteStoragePool() + { + if (storagePool != null) + { + String idStoragePool = storagePool.getUUID(); + storagePool.delete(); + assertNull(infrastructureApi.getStoragePool(storageDevice.unwrap(), idStoragePool)); + } + + } + + protected void deleteStorageDevice() + { + if (storageDevice != null) + { + Integer idStorageDevice = storageDevice.getId(); + storageDevice.delete(); + assertNull(infrastructureApi.getStorageDevice(datacenter.unwrap(), idStorageDevice)); + } + } + + protected void deleteMachine() + { + if (machine != null && rack != null) + { + Integer idMachine = machine.getId(); + machine.delete(); + assertNull(infrastructureApi.getMachine(rack.unwrap(), idMachine)); + } + } + + protected void deleteRack() + { + if (rack != null && datacenter != null) + { + Integer idRack = rack.getId(); + rack.delete(); + assertNull(infrastructureApi.getRack(datacenter.unwrap(), idRack)); + } + } + + protected void deleteUcsRack() + { + if (ucsRack != null && datacenter != null) + { + Integer idRack = ucsRack.getId(); + ucsRack.delete(); + assertNull(infrastructureApi.getManagedRack(datacenter.unwrap(), idRack)); + } + } + + protected void deleteDatacenter() + { + if (datacenter != null) + { + // Remove limits first + enterprise.prohibitDatacenter(datacenter); + + Integer idDatacenter = datacenter.getId(); + datacenter.delete(); // Abiquo API will delete remote services too + assertNull(infrastructureApi.getDatacenter(idDatacenter)); + } + } + + protected void deleteEnterprise() + { + if (enterprise != null) + { + Integer idEnterprise = enterprise.getId(); + enterprise.delete(); + assertNull(enterpriseApi.getEnterprise(idEnterprise)); + } + } + + protected void deleteLicense() + { + license.remove(); + } + + protected static String randomName() + { + return PREFIX + UUID.randomUUID().toString().substring(0, 12); + } + + // Utility methods + + public static String readLicense() throws IOException + { + URL url = CloudTestEnvironment.class.getResource("/license/expired"); + + return Resources.toString(url, Charset.defaultCharset()); + } + + public RemoteService findRemoteService(final RemoteServiceType type) + { + return find(remoteServices, RemoteServicePredicates.type(type)); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java new file mode 100644 index 0000000000..5f74ddb479 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java @@ -0,0 +1,40 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.environment; + +/** + * Base class fot test environment populators. + *

+ * This class should be used to populate and clean the test environment used in live tests. + * + * @author Ignasi Barrera + */ +public interface TestEnvironment +{ + /** + * Builds the test environment. + */ + public void setup() throws Exception; + + /** + * Cleans the test environment. + */ + public void tearDown() throws Exception; +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java new file mode 100644 index 0000000000..181157ff49 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java @@ -0,0 +1,125 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.events.handlers; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.events.monitor.MonitorEvent; +import org.jclouds.abiquo.events.monitor.MonitorEvent.Type; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BlockingEventHandler} handler. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BlockingEventHandlerTest") +public class BlockingEventHandlerTest +{ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testConstructorWithoutObjects() + { + new BlockingEventHandler(); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testConstructorWithNullObjects() + { + new BlockingEventHandler((Object[]) null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testConstructorWithtEmptyObjects() + { + new BlockingEventHandler(new Object[] {}); + } + + public void testHandles() + { + Object object = new Object(); + BlockingEventHandler handler = new BlockingEventHandler(object); + + assertTrue(handler.handles(new MonitorEvent(Type.COMPLETED, object))); + assertFalse(handler.handles(new MonitorEvent(Type.COMPLETED, new Object()))); + } + + public void testReleaseDoesNothingIfNotLocked() + { + Object object = new Object(); + BlockingEventHandler handler = new BlockingEventHandler(object); + handler.release(object); + } + + public void testRelease() + { + final Object object = new Object(); + final BlockingEventHandler handler = new BlockingEventHandler(object); + + // Unlock the handler (in a separate thread) after a certain delay + Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() + { + @Override + public void run() + { + handler.release(object); + assertTrue(handler.lockedObjects.isEmpty()); + } + + }, 500L, TimeUnit.MILLISECONDS); + + handler.lock(); + } + + public void testHandle() + { + final Object object = new Object(); + final BlockingEventHandler handler = new BlockingEventHandler(object); + + // Unlock the handler (in a separate thread) after a certain delay + Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() + { + @Override + public void run() + { + handler.handle(new MonitorEvent(Type.COMPLETED, object)); + assertTrue(handler.lockedObjects.isEmpty()); + } + + }, 500L, TimeUnit.MILLISECONDS); + + handler.lock(); + } + + public void testLockDoesNothingIfNoObjects() + { + Object object = new Object(); + BlockingEventHandler handler = new BlockingEventHandler(object); + handler.lockedObjects.clear(); + + handler.lock(); // Lock should do nothing + + assertNull(handler.completeSignal); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/AdminAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/AdminAsyncApiTest.java new file mode 100644 index 0000000000..03021b6d0e --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/AdminAsyncApiTest.java @@ -0,0 +1,196 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.AdminResources; +import org.jclouds.abiquo.domain.EnterpriseResources; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.abiquo.server.core.enterprise.RoleDto; +import com.abiquo.server.core.enterprise.RolesDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code AdminAsyncApi} + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "AdminAsyncApiTest") +public class AdminAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + /*********************** Role ***********************/ + + public void testListRoles() throws SecurityException, NoSuchMethodException, IOException + { + Method method = AdminAsyncApi.class.getMethod("listRoles"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/roles HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RolesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetRoleFromUser() throws SecurityException, NoSuchMethodException, IOException + { + Method method = AdminAsyncApi.class.getMethod("getRole", UserDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.userPut()); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/roles/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateRole() throws SecurityException, NoSuchMethodException, IOException + { + Method method = AdminAsyncApi.class.getMethod("createRole", RoleDto.class); + GeneratedHttpRequest request = processor.createRequest(method, AdminResources.rolePost()); + + assertRequestLineEquals(request, "POST http://localhost/api/admin/roles HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(AdminResources.rolePostPayload()), RoleDto.class, + RoleDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteRole() throws SecurityException, NoSuchMethodException + { + Method method = AdminAsyncApi.class.getMethod("deleteRole", RoleDto.class); + GeneratedHttpRequest request = processor.createRequest(method, AdminResources.rolePut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/admin/roles/1 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 testUpdateRole() throws SecurityException, NoSuchMethodException, IOException + { + Method method = AdminAsyncApi.class.getMethod("updateRole", RoleDto.class); + GeneratedHttpRequest request = processor.createRequest(method, AdminResources.rolePut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/admin/roles/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(AdminResources.rolePutPayload()), RoleDto.class, + RoleDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetRoleById() throws SecurityException, NoSuchMethodException, IOException + { + Method method = AdminAsyncApi.class.getMethod("getRole", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/roles/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testListPrivilegesByRoles() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = AdminAsyncApi.class.getMethod("listPrivileges", RoleDto.class); + GeneratedHttpRequest request = processor.createRequest(method, AdminResources.rolePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/roles/1/action/privileges HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PrivilegesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Current User **********************/ + + public void testGetCurrentUser() throws SecurityException, NoSuchMethodException, IOException + { + Method method = AdminAsyncApi.class.getMethod("getCurrentUser"); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/login HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UserDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoAsyncApiTest.java new file mode 100644 index 0000000000..9308fbbbb5 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoAsyncApiTest.java @@ -0,0 +1,100 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.Constants.PROPERTY_PRETTY_PRINT_PAYLOADS; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.Properties; + +import org.jclouds.abiquo.AbiquoApiMetadata; +import org.jclouds.abiquo.config.AbiquoRestClientModule; +import org.jclouds.abiquo.http.filters.AbiquoAuthentication; +import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; +import org.jclouds.http.HttpRequest; +import org.jclouds.providers.AnonymousProviderMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.internal.BaseAsyncClientTest; +import org.jclouds.xml.XMLParser; +import org.testng.annotations.BeforeClass; + +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.google.inject.Module; + +/** + * Tests annotation parsing of {@code AbiquoAsyncApi}. + * + * @author Ignasi Barrera + */ +public abstract class BaseAbiquoAsyncApiTest extends BaseAsyncClientTest +{ + private XMLParser xml; + + @BeforeClass + @Override + protected void setupFactory() throws IOException + { + super.setupFactory(); + xml = injector.getInstance(XMLParser.class); + } + + @Override + protected void checkFilters(final HttpRequest request) + { + assertEquals(request.getFilters().size(), 2); + assertEquals(request.getFilters().get(0).getClass(), AbiquoAuthentication.class); + assertEquals(request.getFilters().get(1).getClass(), AppendApiVersionToMediaType.class); + } + + @Override + protected Module createModule() + { + return new AbiquoRestClientModule(); + } + + @Override + protected ProviderMetadata createProviderMetadata() + { + return AnonymousProviderMetadata.forApiWithEndpoint(new AbiquoApiMetadata(), + "http://localhost/api"); + } + + @Override + protected Properties setupProperties() + { + Properties props = super.setupProperties(); + // Do not pretty print payloads in tests + props.setProperty(PROPERTY_PRETTY_PRINT_PAYLOADS, "false"); + return props; + } + + protected void assertPayloadEquals(final HttpRequest request, final String toMatch, + final Class< ? extends SingleResourceTransportDto> entityClass, final String contentType, + final boolean contentMD5) throws IOException + { + // Make sure we don't have formatting issues + SingleResourceTransportDto entity = xml.fromXML(toMatch, entityClass); + String stringToMatch = xml.toXML(entity, entityClass); + + super.assertPayloadEquals(request, stringToMatch, contentType, contentMD5); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java new file mode 100644 index 0000000000..873be24fd5 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/CloudAsyncApiTest.java @@ -0,0 +1,1572 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.abiquo.domain.EnterpriseResources; +import org.jclouds.abiquo.domain.InfrastructureResources; +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.domain.options.search.reference.OrderBy; +import org.jclouds.abiquo.functions.ReturnTaskReferenceOrNull; +import org.jclouds.abiquo.functions.cloud.ReturnMovedVolume; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.model.transport.LinksDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceStateDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacenterDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachineDto; +import com.abiquo.server.core.cloud.VirtualMachineStateDto; +import com.abiquo.server.core.cloud.VirtualMachineTaskDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpDto; +import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VMNetworkConfigurationsDto; +import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; +import com.abiquo.server.core.infrastructure.storage.DisksManagementDto; +import com.abiquo.server.core.infrastructure.storage.MovedVolumeDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code CloudAsyncApi} + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "CloudAsyncApiTest") +public class CloudAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + /*********************** Virtual Datacenter ***********************/ + + public void testListVirtualDatacentersParams() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVirtualDatacenters", VirtualDatacenterOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, VirtualDatacenterOptions.builder().datacenterId(1) + .enterpriseId(1).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters?datacenter=1&enterprise=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualDatacentersDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVirtualDatacentersNoParams() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVirtualDatacenters", VirtualDatacenterOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, VirtualDatacenterOptions.builder().build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualDatacentersDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateVirtualDatacenter() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("createVirtualDatacenter", VirtualDatacenterDto.class, + DatacenterDto.class, EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPost(), + InfrastructureResources.datacenterPut(), EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters?enterprise=1&datacenter=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualDatacenterDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualDatacenterPostPayload()), + VirtualDatacenterDto.class, VirtualDatacenterDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVirtualDatacenter() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = CloudAsyncApi.class.getMethod("getVirtualDatacenter", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualDatacenterDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateVirtualDatacenter() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("updateVirtualDatacenter", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualDatacenterDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualDatacenterPutPayload()), + VirtualDatacenterDto.class, VirtualDatacenterDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVirtualDatacenter() throws SecurityException, NoSuchMethodException + { + Method method = + CloudAsyncApi.class.getMethod("deleteVirtualDatacenter", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Ips ***********************/ + + public void testListAvailablePublicIpsWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + IpOptions options = IpOptions.builder().limit(5).build(); + Method method = + CloudAsyncApi.class.getMethod("listAvailablePublicIps", VirtualDatacenterDto.class, + IpOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase?limit=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListPurchasedPublicIpsWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + IpOptions options = IpOptions.builder().limit(5).build(); + Method method = + CloudAsyncApi.class.getMethod("listPurchasedPublicIps", VirtualDatacenterDto.class, + IpOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased?limit=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testPurchasePublicIp() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("purchasePublicIp", PublicIpDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicIpToPurchase()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/5/publicips/purchased/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testReleasePublicIp() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("releasePublicIp", PublicIpDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicIpToRelease()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/5/publicips/topurchase/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Available templates ***********************/ + + public void testListAvailableTemplates() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listAvailableTemplates", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/action/templates HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplatesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListAvailableTemplatesWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("listAvailableTemplates", VirtualDatacenterDto.class, + VirtualMachineTemplateOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + VirtualMachineTemplateOptions.builder().hypervisorType(HypervisorType.XENSERVER) + .categoryName("Firewalls").idTemplate(1).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/action/templates" + + "?hypervisorTypeName=XENSERVER&categoryName=Firewalls&idTemplate=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplatesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Storage Tiers ***********************/ + + public void testListStorageTiers() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("listStorageTiers", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/tiers HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TiersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetStorageTier() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("getStorageTier", VirtualDatacenterDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/tiers/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TierDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetDefaultNetwork() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getDefaultNetwork", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testSetDefaultNetworkInternal() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("setDefaultNetwork", VirtualDatacenterDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + NetworkResources.privateNetworkPut()); + + RESTLink netLink = NetworkResources.privateNetworkPut().getEditLink(); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/action/defaultvlan HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, withHeader(""), LinksDto.class, LinksDto.BASE_MEDIA_TYPE, + false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testSetDefaultNetworkExternal() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("setDefaultNetwork", VirtualDatacenterDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + NetworkResources.externalNetworkPut()); + + RESTLink netLink = NetworkResources.externalNetworkPut().getEditLink(); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/action/defaultvlan HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, withHeader(""), LinksDto.class, LinksDto.BASE_MEDIA_TYPE, + false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Private Network ***********************/ + + public void testListPrivateNetworks() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listPrivateNetworks", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/privatenetworks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetPrivateNetwork() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getPrivateNetwork", VirtualDatacenterDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreatePrivateNetwork() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("createPrivateNetwork", VirtualDatacenterDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + NetworkResources.vlanPost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/privatenetworks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(NetworkResources.vlanNetworkPostPayload()), + VLANNetworkDto.class, VLANNetworkDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdatePrivateNetwork() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = CloudAsyncApi.class.getMethod("updatePrivateNetwork", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.privateNetworkPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(NetworkResources.privateNetworkPutPayload()), + VLANNetworkDto.class, VLANNetworkDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeletePrivateNetwork() throws SecurityException, NoSuchMethodException + { + Method method = CloudAsyncApi.class.getMethod("deletePrivateNetwork", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.privateNetworkPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Private Network IPs ***********************/ + + public void testListPrivateNetworkIps() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listPrivateNetworkIps", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.privateNetworkPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PrivateIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListPrivateNetworkIpsWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + IpOptions options = IpOptions.builder().startWith(10).build(); + Method method = + CloudAsyncApi.class.getMethod("listPrivateNetworkIps", VLANNetworkDto.class, + IpOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.privateNetworkPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips?startwith=10 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PrivateIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetPrivateNetworkIp() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getPrivateNetworkIp", VLANNetworkDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.privateNetworkPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PrivateIpDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Virtual Appliance ***********************/ + + public void testListVirtualAppliances() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVirtualAppliances", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualAppliancesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVirtualAppliance() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVirtualAppliance", VirtualDatacenterDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualApplianceDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetVirtualApplianceState() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVirtualApplianceState", VirtualApplianceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/state HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualApplianceStateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateVirtualAppliance() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("createVirtualAppliance", VirtualDatacenterDto.class, + VirtualApplianceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + CloudResources.virtualAppliancePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualApplianceDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualAppliancePostPayload()), + VirtualApplianceDto.class, VirtualApplianceDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateVirtualAppliance() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("updateVirtualAppliance", VirtualApplianceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualApplianceDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualAppliancePutPayload()), + VirtualApplianceDto.class, VirtualApplianceDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVirtualAppliance() throws SecurityException, NoSuchMethodException + { + Method method = + CloudAsyncApi.class.getMethod("deleteVirtualAppliance", VirtualApplianceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1 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 testDeployVirtualAppliance() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("deployVirtualAppliance", VirtualApplianceDto.class, + VirtualMachineTaskDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut(), + CloudResources.deployOptions()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/deploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.deployPayload()), + VirtualMachineTaskDto.class, VirtualMachineTaskDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUndeployVirtualAppliance() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("undeployVirtualAppliance", VirtualApplianceDto.class, + VirtualMachineTaskDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut(), + CloudResources.undeployOptions()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/action/undeploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.undeployPayload()), + VirtualMachineTaskDto.class, VirtualMachineTaskDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Virtual Machine ***********************/ + + public void testListVirtualMachines() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVirtualMachines", VirtualApplianceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVirtualMachinesWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVirtualMachines", VirtualApplianceDto.class, + VirtualMachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut(), + VirtualMachineOptions.builder().disablePagination().build()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines?limit=0 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVirtualMachine", VirtualApplianceDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut(), 1); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("createVirtualMachine", VirtualApplianceDto.class, + VirtualMachineWithNodeExtendedDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualAppliancePut(), + CloudResources.virtualMachinePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualMachinePostPayload()), + VirtualMachineWithNodeExtendedDto.class, + VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("updateVirtualMachine", + VirtualMachineWithNodeExtendedDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualMachinePutPayload()), + VirtualMachineWithNodeExtendedDto.class, + VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateVirtualMachineWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("updateVirtualMachine", + VirtualMachineWithNodeExtendedDto.class, VirtualMachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut(), + VirtualMachineOptions.builder().force(true).build()); + + assertRequestLineEquals( + request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1?force=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualMachinePutPayload()), + VirtualMachineWithNodeExtendedDto.class, + VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testChangeVirtualMachineState() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("changeVirtualMachineState", VirtualMachineDto.class, + VirtualMachineStateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut(), + CloudResources.virtualMachineState()); + + assertRequestLineEquals( + request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/state HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualMachineStatePayload()), + VirtualMachineStateDto.class, VirtualMachineStateDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVirtualMachine() throws SecurityException, NoSuchMethodException + { + Method method = + CloudAsyncApi.class.getMethod("deleteVirtualMachine", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1 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 testGetVirtualMachineState() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVirtualMachineState", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/state HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualMachineStateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeployVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("deployVirtualMachine", VirtualMachineDto.class, + VirtualMachineTaskDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut(), + CloudResources.deployOptions()); + + assertRequestLineEquals( + request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/deploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.deployPayload()), + VirtualMachineTaskDto.class, VirtualMachineTaskDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUndeployVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("undeployVirtualMachine", VirtualMachineDto.class, + VirtualMachineTaskDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut(), + CloudResources.undeployOptions()); + + assertRequestLineEquals( + request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/undeploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.undeployPayload()), + VirtualMachineTaskDto.class, VirtualMachineTaskDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testRebootVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("rebootVirtualMachine", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "POST http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/reset HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListNetworkConfigurations() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listNetworkConfigurations", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/configurations HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VMNetworkConfigurationsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testSetGatewayNetwork() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("setGatewayNetwork", VirtualMachineDto.class, + VLANNetworkDto.class); + + VirtualMachineDto vm = CloudResources.virtualMachinePut(); + VLANNetworkDto network = NetworkResources.privateNetworkPut(); + + GeneratedHttpRequest request = processor.createRequest(method, vm, network); + + String configLink = vm.searchLink("configurations").getHref() + "/" + network.getId(); + + assertRequestLineEquals( + request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/network/configurations HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, withHeader(""), LinksDto.class, + LinksDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Virtual Machine Template ***********************/ + + public void testGetVirtualMachineTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVirtualMachineTemplate", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListAttachedVolumes() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listAttachedVolumes", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/volumes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VolumesManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDetachAllVolumes() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("detachAllVolumes", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/volumes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testReplaceVolumes() throws SecurityException, NoSuchMethodException, IOException + { + VolumeManagementDto first = CloudResources.volumePut(); + VolumeManagementDto second = CloudResources.volumePut(); + second.getEditLink().setHref(second.getEditLink().getHref() + "second"); + + Method method = + CloudAsyncApi.class.getMethod("replaceVolumes", VirtualMachineDto.class, + VirtualMachineOptions.class, VolumeManagementDto[].class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut(), + VirtualMachineOptions.builder().force(true).build(), new VolumeManagementDto[] { + first, second}); + + String editLink = CloudResources.volumePut().getEditLink().getHref(); + assertRequestLineEquals( + request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/volumes?force=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(""), + LinksDto.class, LinksDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListAttachedHardDisks() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listAttachedHardDisks", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/disks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DisksManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDetachAllHardDisks() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("detachAllHardDisks", VirtualMachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/disks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testReplaceHardDisks() throws SecurityException, NoSuchMethodException, IOException + { + DiskManagementDto first = CloudResources.hardDiskPut(); + DiskManagementDto second = CloudResources.hardDiskPut(); + second.getEditLink().setHref(second.getEditLink().getHref() + "second"); + + Method method = + CloudAsyncApi.class.getMethod("replaceHardDisks", VirtualMachineDto.class, + DiskManagementDto[].class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut(), + new DiskManagementDto[] {first, second}); + + String editLink = CloudResources.hardDiskPut().getEditLink().getHref(); + assertRequestLineEquals( + request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/storage/disks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(""), + LinksDto.class, LinksDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Hard disks ***********************/ + + public void testListHardDisks() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("listHardDisks", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/disks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DisksManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetHardDisk() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("getHardDisk", VirtualDatacenterDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/disks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DiskManagementDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateHardDisk() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("createHardDisk", VirtualDatacenterDto.class, + DiskManagementDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + CloudResources.hardDiskPost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/disks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DiskManagementDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.hardDiskPostPayload()), + DiskManagementDto.class, DiskManagementDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteHardDisk() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("deleteHardDisk", DiskManagementDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.hardDiskPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/disks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Volumes ***********************/ + + public void testListVolumes() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("listVolumes", VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/volumes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VolumesManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVolumesWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVolumes", VirtualDatacenterDto.class, + VolumeOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), VolumeOptions + .builder().onlyAvailable(true).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/volumes?available=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VolumesManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVolumesWithFilterOptions() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + CloudAsyncApi.class.getMethod("listVolumes", VirtualDatacenterDto.class, + VolumeOptions.class); + + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), VolumeOptions + .builder().has("vol").orderBy(OrderBy.NAME).ascendant(true).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/volumes?has=vol&by=name&asc=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VolumesManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVolume() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("getVolume", VirtualDatacenterDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/cloud/virtualdatacenters/1/volumes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VolumeManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("createVolume", VirtualDatacenterDto.class, + VolumeManagementDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualDatacenterPut(), + CloudResources.volumePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/volumes HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VolumeManagementDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.volumePostPayload()), + VolumeManagementDto.class, VolumeManagementDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateVolume() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("updateVolume", VolumeManagementDto.class); + GeneratedHttpRequest request = processor.createRequest(method, CloudResources.volumePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/cloud/virtualdatacenters/1/volumes/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.volumePutPayload()), + VolumeManagementDto.class, VolumeManagementDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException + { + Method method = CloudAsyncApi.class.getMethod("deleteVolume", VolumeManagementDto.class); + GeneratedHttpRequest request = processor.createRequest(method, CloudResources.volumePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/cloud/virtualdatacenters/1/volumes/1 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 testMoveVolume() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + CloudAsyncApi.class.getMethod("moveVolume", VolumeManagementDto.class, + VirtualDatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.volumePut(), + CloudResources.virtualDatacenterPut()); + + assertRequestLineEquals(request, + "POST http://localhost/api/cloud/virtualdatacenters/1/volumes/1/action/move HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MovedVolumeDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(CloudResources.virtualDatacenterRefPayload()), + LinksDto.class, LinksDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnMovedVolume.class); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/ConfigAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/ConfigAsyncApiTest.java new file mode 100644 index 0000000000..0352472bc1 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/ConfigAsyncApiTest.java @@ -0,0 +1,317 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.ConfigResources; +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.server.core.appslibrary.CategoriesDto; +import com.abiquo.server.core.appslibrary.CategoryDto; +import com.abiquo.server.core.config.LicenseDto; +import com.abiquo.server.core.config.LicensesDto; +import com.abiquo.server.core.config.SystemPropertiesDto; +import com.abiquo.server.core.config.SystemPropertyDto; +import com.abiquo.server.core.enterprise.PrivilegeDto; +import com.abiquo.server.core.enterprise.PrivilegesDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code AdminAsyncApi}. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "ConfigAsyncApiTest") +public class ConfigAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + /*********************** License ***********************/ + + public void testListLicenses() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("listLicenses"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/config/licenses HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LicensesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListLicenseWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = ConfigAsyncApi.class.getMethod("listLicenses", LicenseOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, LicenseOptions.builder().active(true).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/licenses?active=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LicensesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testAddLicense() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("addLicense", LicenseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, ConfigResources.licensePost()); + + assertRequestLineEquals(request, "POST http://localhost/api/config/licenses HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LicenseDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(ConfigResources.licensePostPayload()), + LicenseDto.class, LicenseDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testRemoveLicense() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("removeLicense", LicenseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, ConfigResources.licensePut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/config/licenses/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Privilege ***********************/ + + public void testListPrivileges() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("listPrivileges"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/config/privileges HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PrivilegesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetPrivilege() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("getPrivilege", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/config/privileges/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PrivilegeDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + /*********************** System Properties ***********************/ + + public void testListSystemProperties() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = ConfigAsyncApi.class.getMethod("listSystemProperties"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/config/properties HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + SystemPropertiesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListSystemPropertiesWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + ConfigAsyncApi.class.getMethod("listSystemProperties", PropertyOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, PropertyOptions.builder().component("api").build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/config/properties?component=api HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + SystemPropertiesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateSystemProperty() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + ConfigAsyncApi.class.getMethod("updateSystemProperty", SystemPropertyDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, ConfigResources.propertyPut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/config/properties/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + SystemPropertyDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(ConfigResources.propertyPutPayload()), + SystemPropertyDto.class, SystemPropertyDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Category ***********************/ + + public void testListCategories() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("listCategories"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/config/categories HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CategoriesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetCategory() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("getCategory", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/config/categories/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CategoryDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateCategory() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("createCategory", CategoryDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, ConfigResources.categoryPost()); + + assertRequestLineEquals(request, "POST http://localhost/api/config/categories HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CategoryDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(ConfigResources.categoryPostPayload()), + CategoryDto.class, CategoryDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateCategory() throws SecurityException, NoSuchMethodException, IOException + { + Method method = ConfigAsyncApi.class.getMethod("updateCategory", CategoryDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, ConfigResources.categoryPut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/config/categories/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CategoryDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(ConfigResources.categoryPutPayload()), + CategoryDto.class, CategoryDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteCategory() throws SecurityException, NoSuchMethodException + { + Method method = ConfigAsyncApi.class.getMethod("deleteCategory", CategoryDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, ConfigResources.categoryPut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/config/categories/1 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 TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/EnterpriseAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/EnterpriseAsyncApiTest.java new file mode 100644 index 0000000000..2a6a79caf9 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/EnterpriseAsyncApiTest.java @@ -0,0 +1,807 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.EnterpriseResources; +import org.jclouds.abiquo.domain.InfrastructureResources; +import org.jclouds.abiquo.domain.enterprise.options.EnterpriseOptions; +import org.jclouds.abiquo.domain.options.search.reference.OrderBy; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.am.model.TemplatesStateDto; +import com.abiquo.server.core.appslibrary.DatacenterRepositoryDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto; +import com.abiquo.server.core.appslibrary.TemplateDefinitionListsDto; +import com.abiquo.server.core.cloud.VirtualAppliancesDto; +import com.abiquo.server.core.cloud.VirtualDatacentersDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacenterLimitsDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.enterprise.EnterprisePropertiesDto; +import com.abiquo.server.core.enterprise.EnterprisesDto; +import com.abiquo.server.core.enterprise.UserDto; +import com.abiquo.server.core.enterprise.UsersDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code EnterpriseAsyncApi} + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "EnterpriseAsyncApiTest") +public class EnterpriseAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + /*********************** Enterprise ********************** */ + + public void testListEnterprises() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("listEnterprises"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/enterprises HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterprisesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListEnterprisesWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + EnterpriseOptions options = + EnterpriseOptions.builder().has("abi").orderBy(OrderBy.NAME).ascendant(true).build(); + + Method method = + EnterpriseAsyncApi.class.getMethod("listEnterprises", EnterpriseOptions.class); + GeneratedHttpRequest request = processor.createRequest(method, options); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises?has=abi&by=name&asc=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterprisesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListEnterprisesByDatacenter() throws SecurityException, NoSuchMethodException, + IOException + { + EnterpriseOptions options = + EnterpriseOptions.builder().startWith(0).limit(25).network(true).build(); + + Method method = + EnterpriseAsyncApi.class.getMethod("listEnterprises", DatacenterDto.class, + EnterpriseOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), options); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/datacenters/1/action/enterprises?network=true&startwith=0&limit=25 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterprisesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateEnterprise() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("createEnterprise", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePost()); + + assertRequestLineEquals(request, "POST http://localhost/api/admin/enterprises HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterpriseDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.enterprisePostPayload()), + EnterpriseDto.class, EnterpriseDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetEnterprise() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("getEnterprise", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/enterprises/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterpriseDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateEnterprise() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("updateEnterprise", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/admin/enterprises/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterpriseDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.enterprisePutPayload()), + EnterpriseDto.class, EnterpriseDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteEnterprise() throws SecurityException, NoSuchMethodException + { + Method method = EnterpriseAsyncApi.class.getMethod("deleteEnterprise", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/admin/enterprises/1 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 testListAllowedDatacenters() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("listAllowedDatacenters", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters?idEnterprise=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVirtualDatacentersFromEnterprise() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listVirtualDatacenters", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/action/virtualdatacenters HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualDatacentersDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Enterprise Properties ********************** */ + + public void testGetEnterpriseProperties() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("getEnterpriseProperties", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/properties HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterprisePropertiesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + public void testUpdateEnterpriseProperties() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("updateEnterpriseProperties", + EnterprisePropertiesDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePropertiesPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/enterprises/1/properties HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EnterprisePropertiesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, + withHeader(EnterpriseResources.enterprisePropertiesPutPayload()), + EnterprisePropertiesDto.class, EnterprisePropertiesDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Enterprise Limits ********************** */ + + public void testCreateLimits() throws SecurityException, NoSuchMethodException, IOException + { + EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); + DatacenterDto datacenter = InfrastructureResources.datacenterPut(); + DatacenterLimitsDto limits = EnterpriseResources.datacenterLimitsPost(); + + Method method = + EnterpriseAsyncApi.class.getMethod("createLimits", EnterpriseDto.class, + DatacenterDto.class, DatacenterLimitsDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, enterprise, datacenter, limits); + + String limitsUri = enterprise.searchLink("limits").getHref(); + String requestURI = + String.format("POST %s?datacenter=%d HTTP/1.1", limitsUri, datacenter.getId()); + + assertRequestLineEquals(request, requestURI); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterLimitsDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.datacenterLimitsPostPayload()), + DatacenterLimitsDto.class, DatacenterLimitsDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetLimits() throws SecurityException, NoSuchMethodException, IOException + { + EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); + DatacenterDto datacenter = InfrastructureResources.datacenterPut(); + + Method method = + EnterpriseAsyncApi.class.getMethod("getLimits", EnterpriseDto.class, + DatacenterDto.class); + GeneratedHttpRequest request = processor.createRequest(method, enterprise, datacenter); + + String limitsUri = enterprise.searchLink("limits").getHref(); + String requestURI = + String.format("GET %s?datacenter=%d HTTP/1.1", limitsUri, datacenter.getId()); + + assertRequestLineEquals(request, requestURI); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersLimitsDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateLimits() throws SecurityException, NoSuchMethodException, IOException + { + EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); + + Method method = + EnterpriseAsyncApi.class.getMethod("updateLimits", DatacenterLimitsDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.datacenterLimitsPut(enterprise)); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/enterprises/1/limits/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterLimitsDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, + withHeader(EnterpriseResources.datacenterLimitsPutPayload(enterprise)), + DatacenterLimitsDto.class, DatacenterLimitsDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteLimits() throws SecurityException, NoSuchMethodException + { + EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); + + Method method = + EnterpriseAsyncApi.class.getMethod("deleteLimits", DatacenterLimitsDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.datacenterLimitsPut(enterprise)); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/enterprises/1/limits/1 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 testListLimitsEnterprise() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("listLimits", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/limits HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersLimitsDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** User ***********************/ + + public void testGetUser() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("getUser", EnterpriseDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/users/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UserDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testListUsers() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("listUsers", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/users HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UsersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateUser() throws SecurityException, NoSuchMethodException, IOException + { + EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); + UserDto user = EnterpriseResources.userPost(); + + Method method = + EnterpriseAsyncApi.class.getMethod("createUser", EnterpriseDto.class, UserDto.class); + GeneratedHttpRequest request = processor.createRequest(method, enterprise, user); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/enterprises/1/users HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UserDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.userPostPayload()), + UserDto.class, UserDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateUser() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("updateUser", UserDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.userPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/enterprises/1/users/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UserDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.userPutPayload()), + UserDto.class, UserDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteUser() throws SecurityException, NoSuchMethodException + { + Method method = EnterpriseAsyncApi.class.getMethod("deleteUser", UserDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.userPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/enterprises/1/users/1 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 testListVirtualMachinesByUser() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = EnterpriseAsyncApi.class.getMethod("listVirtualMachines", UserDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.userPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/users/1/action/virtualmachines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Datacenter Repository ********************** */ + + public void testGetDatacenterRepository() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("getDatacenterRepository", EnterpriseDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut(), + InfrastructureResources.datacenterPut().getId()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterRepositoryDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testRefreshTemplateRepository() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("refreshTemplateRepository", Integer.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut().getId(), + InfrastructureResources.datacenterPut().getId()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/enterprises/1/datacenterrepositories/1/actions/refresh HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** External Network ********************** */ + + public void testListExternalNetworks() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listExternalNetworks", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/action/externalnetworks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Cloud ********************** */ + + public void testListVirtualMachines() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listVirtualMachines", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/action/virtualmachines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVirtualAppliances() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listVirtualAppliances", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/action/virtualappliances HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VirtualAppliancesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Machine ********************** */ + + public void testListReservedMachines() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listReservedMachines", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/reservedmachines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachinesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Template definition list ***********************/ + + public void testListTemplateDefinitionLists() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listTemplateDefinitionLists", EnterpriseDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + TemplateDefinitionListsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateTemplateDefinitionList() throws SecurityException, NoSuchMethodException, + IOException + { + EnterpriseDto enterprise = EnterpriseResources.enterprisePut(); + TemplateDefinitionListDto template = EnterpriseResources.templateListPost(); + + Method method = + EnterpriseAsyncApi.class.getMethod("createTemplateDefinitionList", EnterpriseDto.class, + TemplateDefinitionListDto.class); + GeneratedHttpRequest request = processor.createRequest(method, enterprise, template); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + TemplateDefinitionListDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.templateListPostPayload()), + TemplateDefinitionListDto.class, TemplateDefinitionListDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateTemplateDefinitionList() throws SecurityException, NoSuchMethodException, + IOException + { + TemplateDefinitionListDto template = EnterpriseResources.templateListPut(); + + Method method = + EnterpriseAsyncApi.class.getMethod("updateTemplateDefinitionList", + TemplateDefinitionListDto.class); + GeneratedHttpRequest request = processor.createRequest(method, template); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + TemplateDefinitionListDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(EnterpriseResources.templateListPutPayload()), + TemplateDefinitionListDto.class, TemplateDefinitionListDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteTemplateDefinitionList() throws SecurityException, NoSuchMethodException + { + Method method = + EnterpriseAsyncApi.class.getMethod("deleteTemplateDefinitionList", + TemplateDefinitionListDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.templateListPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists/1 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 testGetTemplateDefinitionList() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("getTemplateDefinitionList", EnterpriseDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + TemplateDefinitionListDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testListTemplateListStatus() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + EnterpriseAsyncApi.class.getMethod("listTemplateListStatus", + TemplateDefinitionListDto.class, DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.templateListPut(), + InfrastructureResources.datacenterPut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/appslib/templateDefinitionLists/1/actions/repositoryStatus?datacenterId=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TemplatesStateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/EventAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/EventAsyncApiTest.java new file mode 100644 index 0000000000..bd837ff141 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/EventAsyncApiTest.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.server.core.event.EventsDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code EventAsyncApi} + * + * @author Ignasi Barrera + * @author Vivien Mahé + */ +@Test(groups = "unit", testName = "EventAsyncApiTest") +public class EventAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + public void testListEvents() throws SecurityException, NoSuchMethodException, IOException + { + Method method = EventAsyncApi.class.getMethod("listEvents"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/events HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + EventsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/FeatureCoverageTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/FeatureCoverageTest.java new file mode 100644 index 0000000000..5215f0fd6a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/FeatureCoverageTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.jclouds.abiquo.config.AbiquoRestClientModule; +import org.jclouds.abiquo.rest.internal.AbiquoHttpAsyncClient; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +/** + * Tests that all features have a unit test. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "FeatureCoverageTest") +public class FeatureCoverageTest +{ + /** A collection with all async api classes. */ + private Collection> featureClasses; + + @BeforeMethod + public void setup() + { + featureClasses = new ArrayList>(); + featureClasses.addAll(AbiquoRestClientModule.DELEGATE_MAP.values()); + featureClasses.add(AbiquoHttpAsyncClient.class); + } + + public void testAllFeaturesHaveTest() throws ClassNotFoundException + { + List missingTests = new ArrayList(); + + for (Class< ? > featureClass : featureClasses) + { + try + { + Class< ? > testClass = loadTestClass(featureClass); + Iterable testMethodNames = methodNames(testClass); + + for (Method method : featureClass.getMethods()) + { + if (!hasTest(testMethodNames, method)) + { + missingTests.add(method.getDeclaringClass().getSimpleName() + "." + + method.getName()); + } + } + } + catch (ClassNotFoundException ex) + { + fail("Missing tests for class: " + featureClass.getName()); + } + } + + assertTrue(missingTests.isEmpty(), "Missing tests: " + Joiner.on(", ").join(missingTests)); + } + + private Class< ? > loadTestClass(final Class< ? > featureClass) throws ClassNotFoundException + { + String testClassName = featureClass.getName() + "Test"; + return Thread.currentThread().getContextClassLoader().loadClass(testClassName); + } + + private static Iterable methodNames(final Class< ? > clazz) + { + return Iterables.transform(Arrays.asList(clazz.getMethods()), + new Function() + { + @Override + public String apply(final Method input) + { + return input.getName(); + } + }); + } + + private static boolean hasTest(final Iterable testMethodNames, final Method method) + { + String testMethod = Iterables.find(testMethodNames, new Predicate() + { + @Override + public boolean apply(final String input) + { + return input.toLowerCase().contains(method.getName().toLowerCase()); + } + }, null); + + return testMethod != null; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureAsyncApiTest.java new file mode 100644 index 0000000000..ab5b294af7 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureAsyncApiTest.java @@ -0,0 +1,2137 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.abiquo.domain.EnterpriseResources; +import org.jclouds.abiquo.domain.InfrastructureResources; +import org.jclouds.abiquo.domain.NetworkResources; +import org.jclouds.abiquo.domain.infrastructure.options.DatacenterOptions; +import org.jclouds.abiquo.domain.infrastructure.options.IpmiOptions; +import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; +import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions; +import org.jclouds.abiquo.domain.network.options.IpOptions; +import org.jclouds.abiquo.domain.network.options.NetworkOptions; +import org.jclouds.abiquo.domain.options.search.FilterOptions; +import org.jclouds.abiquo.functions.ReturnAbiquoExceptionOnNotFoundOr4xx; +import org.jclouds.abiquo.functions.ReturnFalseIfNotAvailable; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.http.functions.ReturnTrueIf2xx; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.NetworkType; +import com.abiquo.model.enumerator.RemoteServiceType; +import com.abiquo.server.core.cloud.HypervisorTypesDto; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; +import com.abiquo.server.core.enterprise.DatacentersLimitsDto; +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.abiquo.server.core.infrastructure.BladeLocatorLedDto; +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.abiquo.server.core.infrastructure.FsmsDto; +import com.abiquo.server.core.infrastructure.LogicServerDto; +import com.abiquo.server.core.infrastructure.LogicServersDto; +import com.abiquo.server.core.infrastructure.MachineDto; +import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; +import com.abiquo.server.core.infrastructure.MachineStateDto; +import com.abiquo.server.core.infrastructure.MachinesDto; +import com.abiquo.server.core.infrastructure.OrganizationDto; +import com.abiquo.server.core.infrastructure.OrganizationsDto; +import com.abiquo.server.core.infrastructure.RackDto; +import com.abiquo.server.core.infrastructure.RacksDto; +import com.abiquo.server.core.infrastructure.RemoteServiceDto; +import com.abiquo.server.core.infrastructure.RemoteServicesDto; +import com.abiquo.server.core.infrastructure.UcsRackDto; +import com.abiquo.server.core.infrastructure.UcsRacksDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpDto; +import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; +import com.abiquo.server.core.infrastructure.network.PublicIpDto; +import com.abiquo.server.core.infrastructure.network.PublicIpsDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; +import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; +import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; +import com.abiquo.server.core.infrastructure.network.VlanTagAvailabilityDto; +import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesDto; +import com.abiquo.server.core.infrastructure.storage.StorageDevicesMetadataDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolDto; +import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto; +import com.abiquo.server.core.infrastructure.storage.TierDto; +import com.abiquo.server.core.infrastructure.storage.TiersDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code InfrastructureAsyncApi} + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "InfrastructureAsyncApiTest") +public class InfrastructureAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + /*********************** Datacenter ***********************/ + + public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listDatacenters"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/datacenters HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateDatacenter() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("createDatacenter", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPost()); + + assertRequestLineEquals(request, "POST http://localhost/api/admin/datacenters HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.datacenterPostPayload()), + DatacenterDto.class, DatacenterDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetDatacenter() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("getDatacenter", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/admin/datacenters/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateDatacenter() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("updateDatacenter", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/admin/datacenters/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacenterDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.datacenterPutPayload()), + DatacenterDto.class, DatacenterDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteDatacenter() throws SecurityException, NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("deleteDatacenter", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/admin/datacenters/1 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 testListLimitsDatacenter() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listLimits", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/action/getLimits HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersLimitsDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Hypervisor ***********************/ + + public void testGetHypervisorTypeFromMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getHypervisorTypeFromMachine", + DatacenterDto.class, DatacenterOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + DatacenterOptions.builder().ip("10.60.1.120").build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/action/hypervisor?ip=10.60.1.120 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MediaType.TEXT_PLAIN + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReturnStringIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetHypervisorTypesFromDatacenter() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getHypervisorTypes", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/hypervisors HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + HypervisorTypesDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Managed Rack ***********************/ + + public void testListRacks() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listRacks", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RacksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateRack() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class + .getMethod("createRack", DatacenterDto.class, RackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + InfrastructureResources.rackPost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/racks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RackDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.rackPostPayload()), + RackDto.class, RackDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetRack() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getRack", DatacenterDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RackDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateRack() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("updateRack", RackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.rackPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/racks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RackDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.rackPutPayload()), + RackDto.class, RackDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteRack() throws SecurityException, NoSuchMethodException + { + Method method = InfrastructureAsyncApi.class.getMethod("deleteRack", RackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.rackPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/datacenters/1/racks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Managed Rack ***********************/ + + public void testListManagedRacks() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listManagedRacks", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UcsRacksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateManagedRack() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("createManagedRack", DatacenterDto.class, + UcsRackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + InfrastructureResources.managedRackPost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/racks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UcsRackDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.managedRackPostPayload()), + UcsRackDto.class, UcsRackDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetManagedRack() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getManagedRack", DatacenterDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UcsRackDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateManagedRack() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("updateManagedRack", UcsRackDto.class); + + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/racks/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UcsRackDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.managedRackPutPayload()), + UcsRackDto.class, UcsRackDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListServiceProfiles() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listServiceProfiles", UcsRackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/logicservers HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LogicServersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListServiceProfilesWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + FilterOptions options = FilterOptions.builder().startWith(1).limit(2).build(); + + Method method = + InfrastructureAsyncApi.class.getMethod("listServiceProfiles", UcsRackDto.class, + FilterOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/logicservers?startwith=1&limit=2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LogicServersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListOrganizations() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listOrganizations", UcsRackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/organizations HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + OrganizationsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListOrganizationsWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + FilterOptions options = FilterOptions.builder().has("org").build(); + + Method method = + InfrastructureAsyncApi.class.getMethod("listOrganizations", UcsRackDto.class, + FilterOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/organizations?has=org HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + OrganizationsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListServiceProfileTemplates() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listServiceProfileTemplates", UcsRackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/lstemplates HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LogicServersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListServiceProfileTemplatesWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + FilterOptions options = FilterOptions.builder().ascendant(true).build(); + + Method method = + InfrastructureAsyncApi.class.getMethod("listServiceProfileTemplates", UcsRackDto.class, + FilterOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/lstemplates?asc=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LogicServersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testAssociateLogicServer() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("associateLogicServer", UcsRackDto.class, + LogicServerDto.class, OrganizationDto.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), + InfrastructureResources.logicServerPut(), + InfrastructureResources.organizationPut(), "blade"); + + assertRequestLineEquals( + request, + "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/associate?bladeDn=blade&org=org-root%2Forg-Finance&lsName=server 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 testAssociateTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("associateTemplate", UcsRackDto.class, + LogicServerDto.class, OrganizationDto.class, String.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), + InfrastructureResources.logicServerPut(), + InfrastructureResources.organizationPut(), "newname", "blade"); + + assertRequestLineEquals( + request, + "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/associatetemplate?newName=newname&bladeDn=blade&org=org-root%2Forg-Finance&lsName=server 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 testCloneAndAssociateLogicServer() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("cloneAndAssociateLogicServer", + UcsRackDto.class, LogicServerDto.class, OrganizationDto.class, String.class, + String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), + InfrastructureResources.logicServerPut(), + InfrastructureResources.organizationPut(), "newname", "blade"); + + assertRequestLineEquals( + request, + "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/assocclone?newName=newname&bladeDn=blade&org=org-root%2Forg-Finance&lsName=server 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 testDissociateLogicServer() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("dissociateLogicServer", UcsRackDto.class, + LogicServerDto.class); + GeneratedHttpRequest request = + processor + .createRequest(method, InfrastructureResources.managedRackPut(), + InfrastructureResources.logicServerPut(), + InfrastructureResources.organizationPut()); + + assertRequestLineEquals( + request, + "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/dissociate?lsName=server 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 testCloneLogicServer() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("cloneLogicServer", UcsRackDto.class, + LogicServerDto.class, OrganizationDto.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), + InfrastructureResources.logicServerPut(), + InfrastructureResources.organizationPut(), "name"); + + assertRequestLineEquals( + request, + "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/clone?newName=name&org=org-root%2Forg-Finance&lsName=server 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 testDeleteLogicServer() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("deleteLogicServer", UcsRackDto.class, + LogicServerDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), + InfrastructureResources.logicServerPut()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/delete?lsName=server 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 testListFsms() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listFsms", UcsRackDto.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.managedRackPut(), "dn"); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/fsm?dn=dn HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + FsmsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Remote Service **********************/ + + public void testListRemoteServices() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listRemoteServices", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/remoteservices HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RemoteServicesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateRemoteService() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("createRemoteService", DatacenterDto.class, + RemoteServiceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + InfrastructureResources.remoteServicePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/remoteservices HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RemoteServiceDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, + withHeader(InfrastructureResources.remoteServicePostPayload()), RemoteServiceDto.class, + RemoteServiceDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetRemoteService() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getRemoteService", DatacenterDto.class, + RemoteServiceType.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + RemoteServiceType.STORAGE_SYSTEM_MONITOR); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/remoteservices/storagesystemmonitor HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RemoteServiceDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateRemoteService() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("updateRemoteService", RemoteServiceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.remoteServicePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/remoteservices/nodecollector HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + RemoteServiceDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.remoteServicePutPayload()), + RemoteServiceDto.class, RemoteServiceDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteRemoteService() throws SecurityException, NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("deleteRemoteService", RemoteServiceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.remoteServicePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/datacenters/1/remoteservices/nodecollector 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 testIsAvailableRemoteService() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("isAvailable", RemoteServiceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.remoteServicePut()); + + String checkUri = InfrastructureResources.remoteServicePut().searchLink("check").getHref(); + assertRequestLineEquals(request, String.format("GET %s HTTP/1.1", checkUri)); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnFalseIfNotAvailable.class); + + checkFilters(request); + } + + /*********************** Machine ***********************/ + + public void testDiscoverSingleMachineWithoutOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("discoverSingleMachine", DatacenterDto.class, + String.class, HypervisorType.class, String.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "10.60.1.222", + HypervisorType.XENSERVER, "user", "pass"); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/discoversingle"; + String query = "hypervisor=XENSERVER&ip=10.60.1.222&user=user&password=pass"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testDiscoverSingleMachineAllParams() throws SecurityException, + NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("discoverSingleMachine", DatacenterDto.class, + String.class, HypervisorType.class, String.class, String.class, + MachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "80.80.80.80", + HypervisorType.KVM, "user", "pass", MachineOptions.builder().port(8889).build()); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/discoversingle"; + String query = "hypervisor=KVM&ip=80.80.80.80&user=user&password=pass&port=8889"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testDiscoverSingleMachineDefaultValues() throws SecurityException, + NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("discoverSingleMachine", DatacenterDto.class, + String.class, HypervisorType.class, String.class, String.class, + MachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "80.80.80.80", + HypervisorType.KVM, "user", "pass", MachineOptions.builder().build()); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/discoversingle"; + String query = "hypervisor=KVM&ip=80.80.80.80&user=user&password=pass"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testDiscoverMultipleMachinesWithoutOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("discoverMultipleMachines", DatacenterDto.class, + String.class, String.class, HypervisorType.class, String.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "10.60.1.222", + "10.60.1.250", HypervisorType.XENSERVER, "user", "pass"); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/discovermultiple"; + String query = + "password=pass&ipTo=10.60.1.250&ipFrom=10.60.1.222&hypervisor=XENSERVER&user=user"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachinesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testDiscoverMultipleMachinesAllParams() throws SecurityException, + NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("discoverMultipleMachines", DatacenterDto.class, + String.class, String.class, HypervisorType.class, String.class, String.class, + MachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "80.80.80.80", + "80.80.80.86", HypervisorType.KVM, "user", "pass", + MachineOptions.builder().port(8889).build()); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/discovermultiple"; + String query = + "password=pass&ipTo=80.80.80.86&ipFrom=80.80.80.80&hypervisor=KVM&user=user&port=8889"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachinesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testCheckMachineStateWithoutOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkMachineState", DatacenterDto.class, + String.class, HypervisorType.class, String.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "10.60.1.222", + HypervisorType.XENSERVER, "user", "pass"); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/checkmachinestate"; + String query = "hypervisor=XENSERVER&ip=10.60.1.222&user=user&password=pass"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineStateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testCheckMachineStateAllParams() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkMachineState", DatacenterDto.class, + String.class, HypervisorType.class, String.class, String.class, + MachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "10.60.1.222", + HypervisorType.XENSERVER, "user", "pass", MachineOptions.builder().port(8889) + .build()); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/checkmachinestate"; + String query = "hypervisor=XENSERVER&ip=10.60.1.222&user=user&password=pass&port=8889"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineStateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testCheckMachineIpmiStateWithoutOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkMachineIpmiState", DatacenterDto.class, + String.class, String.class, String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "10.60.1.222", + "user", "pass"); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/checkmachineipmistate"; + String query = "user=user&ip=10.60.1.222&password=pass"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineIpmiStateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testCheckMachineIpmiStateWithALLOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkMachineIpmiState", DatacenterDto.class, + String.class, String.class, String.class, IpmiOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), "10.60.1.222", + "user", "pass", IpmiOptions.builder().port(8889).build()); + + String baseUrl = "http://localhost/api/admin/datacenters/1/action/checkmachineipmistate"; + String query = "user=user&ip=10.60.1.222&password=pass&port=8889"; + String expectedRequest = String.format("GET %s?%s HTTP/1.1", baseUrl, query); + + assertRequestLineEquals(request, expectedRequest); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineIpmiStateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnAbiquoExceptionOnNotFoundOr4xx.class); + + checkFilters(request); + } + + public void testListMachines() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listMachines", RackDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.rackPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachinesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetMachine() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getMachine", RackDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.rackPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCheckMachineState() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkMachineState", MachineDto.class, + boolean.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut(), true); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/checkstate?sync=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineStateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCheckMachineIpmiState() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkMachineIpmiState", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/checkipmistate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineIpmiStateDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateMachine() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class + .getMethod("createMachine", RackDto.class, MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.rackPut(), + InfrastructureResources.machinePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/racks/1/machines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.machinePostPayload()), + MachineDto.class, MachineDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateMachine() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("updateMachine", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/racks/1/machines/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.machinePutPayload()), + MachineDto.class, MachineDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteMachine() throws SecurityException, NoSuchMethodException + { + Method method = InfrastructureAsyncApi.class.getMethod("deleteMachine", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/datacenters/1/racks/1/machines/1 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 testReserveMachine() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("reserveMachine", EnterpriseDto.class, + MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut(), + InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/enterprises/1/reservedmachines HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + MachineDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.machinePutPayload()), + MachineDto.class, MachineDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCancelReservation() throws SecurityException, NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("cancelReservation", EnterpriseDto.class, + MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, EnterpriseResources.enterprisePut(), + InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/enterprises/1/reservedmachines/1 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 testListVirtualMachinesByMachine() throws SecurityException, NoSuchMethodException, + IOException + { + MachineOptions options = MachineOptions.builder().sync(true).build(); + + Method method = + InfrastructureAsyncApi.class.getMethod("listVirtualMachinesByMachine", + MachineDto.class, MachineOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut(), options); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1/virtualmachines?sync=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachinesWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVirtualMachineByMachine() throws SecurityException, NoSuchMethodException, + IOException + { + + Method method = + InfrastructureAsyncApi.class.getMethod("getVirtualMachine", MachineDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1/virtualmachines/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + /*********************** Blade ***********************/ + + public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("powerOff", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/poweroff 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 testPowerOn() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("powerOn", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/poweron 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 testGetLogicServer() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("getLogicServer", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1/logicserver HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + LogicServerDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testLedOn() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("ledOn", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/ledon 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 testLedOff() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("ledOff", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/racks/1/machines/1/action/ledoff 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 testGetLocatorLed() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("getLocatorLed", MachineDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.machinePut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/racks/1/machines/1/led HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + BladeLocatorLedDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Storage Device ***********************/ + + public void testListStorageDevices() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listStorageDevices", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/devices HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StorageDevicesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListSupportedStorageDevices() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listSupportedStorageDevices", + DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/devices/action/supported HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + StorageDevicesMetadataDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateStorageDevice() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("createStorageDevice", DatacenterDto.class, + StorageDeviceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + InfrastructureResources.storageDevicePost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/storage/devices HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StorageDeviceDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, + withHeader(InfrastructureResources.storageDevicePostPayload()), StorageDeviceDto.class, + StorageDeviceDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteStorageDevice() throws SecurityException, NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("deleteStorageDevice", StorageDeviceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storageDevicePut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/datacenters/1/storage/devices/1 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 testUpdateStorageDevice() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("updateStorageDevice", StorageDeviceDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storageDevicePut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/storage/devices/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StorageDeviceDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.storageDevicePutPayload()), + StorageDeviceDto.class, StorageDeviceDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetStorageDevice() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getStorageDevice", DatacenterDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/devices/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StorageDeviceDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + /*********************** Tier ***********************/ + + public void testListTiers() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listTiers", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/tiers HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TiersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateTier() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("updateTier", TierDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.tierPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/storage/tiers/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TierDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.tierPutPayload()), + TierDto.class, TierDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetTier() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getTier", DatacenterDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/tiers/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TierDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + /*********************** StoragePool ***********************/ + + public void testListSyncStoragePools() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listStoragePools", StorageDeviceDto.class, + StoragePoolOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storageDevicePut(), + StoragePoolOptions.builder().sync(true).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/devices/1/pools?sync=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListStoragePoolsFromTier() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listStoragePools", TierDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.tierPut(), StoragePoolOptions + .builder().sync(true).build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/tiers/1/pools HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListStoragePoolsNoParams() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listStoragePools", StorageDeviceDto.class, + StoragePoolOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storageDevicePut(), + StoragePoolOptions.builder().build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/devices/1/pools HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCreateStoragePool() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("createStoragePool", StorageDeviceDto.class, + StoragePoolDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storageDevicePut(), + InfrastructureResources.storagePoolPost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/storage/devices/1/pools HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.storagePoolPostPayload()), + StoragePoolDto.class, StoragePoolDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateStoragePool() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("updateStoragePool", StoragePoolDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storagePoolPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/storage/devices/1/pools/tururututu HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(InfrastructureResources.storagePoolPutPayload()), + StoragePoolDto.class, StoragePoolDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteStoragePool() throws SecurityException, NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("deleteStoragePool", StoragePoolDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storagePoolPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/datacenters/1/storage/devices/1/pools/tururututu 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 testGetStoragePool() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getStoragePool", StorageDeviceDto.class, + String.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storageDevicePut(), + InfrastructureResources.storagePoolPut().getIdStorage()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/storage/devices/1/pools/tururututu HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testRefreshStoragePool() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("refreshStoragePool", StoragePoolDto.class, + StoragePoolOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.storagePoolPut(), + StoragePoolOptions.builder().sync(true).build()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/datacenters/1/storage/devices/1/pools/tururututu?sync=true HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + StoragePoolDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + /*********************** Network ***********************/ + + public void testListNetworks() throws SecurityException, NoSuchMethodException, IOException + { + Method method = InfrastructureAsyncApi.class.getMethod("listNetworks", DatacenterDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListNetworksWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + NetworkOptions options = NetworkOptions.builder().type(NetworkType.PUBLIC).build(); + + Method method = + InfrastructureAsyncApi.class.getMethod("listNetworks", DatacenterDto.class, + NetworkOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network?type=PUBLIC HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetNetworks() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class + .getMethod("getNetwork", DatacenterDto.class, Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateNetwork() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("createNetwork", DatacenterDto.class, + VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), + NetworkResources.vlanPost()); + + assertRequestLineEquals(request, + "POST http://localhost/api/admin/datacenters/1/network HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(NetworkResources.vlanNetworkPostPayload()), + VLANNetworkDto.class, VLANNetworkDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateNetwork() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("updateNetwork", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicNetworkPut()); + + assertRequestLineEquals(request, + "PUT http://localhost/api/admin/datacenters/1/network/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VLANNetworkDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(NetworkResources.publicNetworkPutPayload()), + VLANNetworkDto.class, VLANNetworkDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteNetwork() throws SecurityException, NoSuchMethodException + { + Method method = + InfrastructureAsyncApi.class.getMethod("deleteNetwork", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicNetworkPut()); + + assertRequestLineEquals(request, + "DELETE http://localhost/api/admin/datacenters/1/network/1 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 testCheckTagAvailability() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("checkTagAvailability", DatacenterDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, InfrastructureResources.datacenterPut(), 2); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network/action/checkavailability?tag=2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + VlanTagAvailabilityDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + /*********************** Network IPs ***********************/ + + public void testListPublicIps() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listPublicIps", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicNetworkPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network/1/ips HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListPublicIpsWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + IpOptions options = IpOptions.builder().startWith(10).build(); + Method method = + InfrastructureAsyncApi.class.getMethod("listPublicIps", VLANNetworkDto.class, + IpOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicNetworkPut(), options); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network/1/ips?startwith=10 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetPublicIp() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getPublicIp", VLANNetworkDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.publicNetworkPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/datacenters/1/network/1/ips/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + PublicIpDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListExternalIps() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listExternalIps", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.externalNetworkPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + ExternalIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListExternalIpsWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + IpOptions options = IpOptions.builder().startWith(10).build(); + Method method = + InfrastructureAsyncApi.class.getMethod("listExternalIps", VLANNetworkDto.class, + IpOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.externalNetworkPut(), options); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips?startwith=10 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + ExternalIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetExternalIp() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getExternalIp", VLANNetworkDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.externalNetworkPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + ExternalIpDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListUnmanagedIps() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("listUnmanagedIps", VLANNetworkDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.unmanagedNetworkPut()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UnmanagedIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListUnmanagedIpsWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + IpOptions options = IpOptions.builder().startWith(10).build(); + Method method = + InfrastructureAsyncApi.class.getMethod("listUnmanagedIps", VLANNetworkDto.class, + IpOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.unmanagedNetworkPut(), options); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips?startwith=10 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UnmanagedIpsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetUnmanagedIp() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + InfrastructureAsyncApi.class.getMethod("getUnmanagedIp", VLANNetworkDto.class, + Integer.class); + GeneratedHttpRequest request = + processor.createRequest(method, NetworkResources.externalNetworkPut(), 1); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/limits/1/externalnetworks/1/ips/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + UnmanagedIpDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java new file mode 100644 index 0000000000..2fcaaf35c8 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java @@ -0,0 +1,143 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.PricingResources; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.server.core.pricing.CurrenciesDto; +import com.abiquo.server.core.pricing.CurrencyDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code PricingAsyncApi}. + * + * @author Ignasi Barrera + * @author Susana Acedo + */ +@Test(groups = "unit", testName = "PricingAsyncApiTest") +public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + + /*********************** Currency ***********************/ + + public void testListCurrencies() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("listCurrencies"); + GeneratedHttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET http://localhost/api/config/currencies HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CurrenciesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetCurrency() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("getCurrency", Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1); + + assertRequestLineEquals(request, "GET http://localhost/api/config/currencies/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CurrencyDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCreateCurrency() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("createCurrency", CurrencyDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.currencyPost()); + + assertRequestLineEquals(request, "POST http://localhost/api/config/currencies HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CurrencyDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.currencyPostPayload()), + CurrencyDto.class, CurrencyDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testUpdateCurrency() throws SecurityException, NoSuchMethodException, IOException + { + Method method = PricingAsyncApi.class.getMethod("updateCurrency", CurrencyDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.currencyPut()); + + assertRequestLineEquals(request, "PUT http://localhost/api/config/currencies/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + CurrencyDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, withHeader(PricingResources.currencyPutPayload()), + CurrencyDto.class, CurrencyDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteCurrency() throws SecurityException, NoSuchMethodException + { + Method method = PricingAsyncApi.class.getMethod("deleteCurrency", CurrencyDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, PricingResources.currencyPut()); + + assertRequestLineEquals(request, "DELETE http://localhost/api/config/currencies/1 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 TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/TaskAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/TaskAsyncApiTest.java new file mode 100644 index 0000000000..906a85166a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/TaskAsyncApiTest.java @@ -0,0 +1,145 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.CloudResources; +import org.jclouds.abiquo.domain.TemplateResources; +import org.jclouds.abiquo.functions.ReturnNullOn303; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.abiquo.server.core.task.TaskDto; +import com.abiquo.server.core.task.TasksDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code TaskAsyncApi} + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "TaskAsyncApiTest") +public class TaskAsyncApiTest extends BaseAbiquoAsyncApiTest +{ + /*********************** Task ***********************/ + + public void testGetTaskVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = TaskAsyncApi.class.getMethod("getTask", RESTLink.class); + GeneratedHttpRequest request = + processor + .createRequest( + method, + new RESTLink("task", + "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/tasks/169f1877-5f17-4f62-9563-974001295c54")); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/tasks/169f1877-5f17-4f62-9563-974001295c54 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TaskDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOn303.class); + + checkFilters(request); + } + + public void testListTasksVirtualMachine() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = TaskAsyncApi.class.getMethod("listTasks", SingleResourceTransportDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, CloudResources.virtualMachinePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/tasks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TasksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetTaskVirtualMachineTemplate() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = TaskAsyncApi.class.getMethod("getTask", RESTLink.class); + GeneratedHttpRequest request = + processor + .createRequest( + method, + new RESTLink("task", + "http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/tasks/169f1877-5f17-4f62-9563-974001295c54")); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/tasks/169f1877-5f17-4f62-9563-974001295c54 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TaskDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOn303.class); + + checkFilters(request); + } + + public void testListTasksVirtualMachineTemplate() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = TaskAsyncApi.class.getMethod("listTasks", SingleResourceTransportDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/tasks HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + TasksDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApiTest.java new file mode 100644 index 0000000000..b77477ac75 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/VirtualMachineTemplateAsyncApiTest.java @@ -0,0 +1,304 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.features; + +import static org.jclouds.abiquo.domain.DomainUtils.withHeader; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.domain.TemplateResources; +import org.jclouds.abiquo.domain.cloud.options.ConversionOptions; +import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; +import org.jclouds.abiquo.functions.ReturnTaskReferenceOrNull; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.model.enumerator.DiskFormatType; +import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.transport.AcceptedRequestDto; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.abiquo.server.core.appslibrary.ConversionsDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto; +import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code VirtualMachineTemplateAsyncApi} + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "VirtualMachineTemplateAsyncApiTest") +public class VirtualMachineTemplateAsyncApiTest extends + BaseAbiquoAsyncApiTest +{ + /*********************** Virtual Machine Template ***********************/ + + public void testListVirtualMachineTemplates() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("listVirtualMachineTemplates", + Integer.class, Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1, 1); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplatesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListVirtualMachineTemplatesWithOptions() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("listVirtualMachineTemplates", + Integer.class, Integer.class, VirtualMachineTemplateOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, 1, 1, VirtualMachineTemplateOptions.builder() + .hypervisorType(HypervisorType.XENSERVER).categoryName("Firewalls").build()); + + assertRequestLineEquals(request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates" + + "?hypervisorTypeName=XENSERVER&categoryName=Firewalls HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplatesDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVirtualMachineTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("getVirtualMachineTemplate", + Integer.class, Integer.class, Integer.class); + GeneratedHttpRequest request = processor.createRequest(method, 1, 1, 1); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUpdateVirtualMachineTemplate() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("updateVirtualMachineTemplate", + VirtualMachineTemplateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut()); + + assertRequestLineEquals( + request, + "PUT http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + + VirtualMachineTemplateDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, + withHeader(TemplateResources.virtualMachineTemplatePutPayload()), + VirtualMachineTemplateDto.class, VirtualMachineTemplateDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVirtualMachineTemplate() throws SecurityException, NoSuchMethodException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("deleteVirtualMachineTemplate", + VirtualMachineTemplateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut()); + + assertRequestLineEquals( + request, + "DELETE http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1 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 testCreatePersistentVirtualMachineTemplate() throws SecurityException, + NoSuchMethodException, IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod( + "createPersistentVirtualMachineTemplate", Integer.class, Integer.class, + VirtualMachineTemplatePersistentDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, 1, 1, TemplateResources.persistentData()); + + assertRequestLineEquals( + request, + "POST http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(TemplateResources.persistentPayload()), + VirtualMachineTemplatePersistentDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + /*********************** Conversions ***********************/ + + public void testRequestConversion() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("requestConversion", + VirtualMachineTemplateDto.class, DiskFormatType.class, ConversionDto.class); + + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut(), + DiskFormatType.VMDK_STREAM_OPTIMIZED, TemplateResources.conversionPut()); + + assertRequestLineEquals( + request, + "PUT http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions/VMDK_STREAM_OPTIMIZED HTTP/1.1"); + + assertNonPayloadHeadersEqual(request, "Accept: " + AcceptedRequestDto.BASE_MEDIA_TYPE + + "\n"); + assertPayloadEquals(request, withHeader(TemplateResources.conversionPutPlayload()), + ConversionDto.BASE_MEDIA_TYPE, false); + + assertResponseParserClassEquals(method, request, ReturnTaskReferenceOrNull.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListConversions() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("listConversions", + VirtualMachineTemplateDto.class); + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + ConversionsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testListConversionsWithOptions() throws SecurityException, NoSuchMethodException, + IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("listConversions", + VirtualMachineTemplateDto.class, ConversionOptions.class); + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut(), + ConversionOptions.builder().hypervisorType(HypervisorType.XENSERVER) + .conversionState(ConversionState.FINISHED).build()); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions" + + "?hypervisor=XENSERVER&state=FINISHED HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + ConversionsDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetConversion() throws SecurityException, NoSuchMethodException, IOException + { + Method method = + VirtualMachineTemplateAsyncApi.class.getMethod("getConversion", + VirtualMachineTemplateDto.class, DiskFormatType.class); + GeneratedHttpRequest request = + processor.createRequest(method, TemplateResources.virtualMachineTemplatePut(), + DiskFormatType.RAW); + + assertRequestLineEquals( + request, + "GET http://localhost/api/admin/enterprises/1/datacenterrepositories/1/virtualmachinetemplates/1/conversions/RAW HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + ConversionDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeTypeTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeTypeTest.java new file mode 100644 index 0000000000..115e551af7 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/AppendApiVersionToAbiquoMimeTypeTest.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.testng.annotations.Test; + +import com.google.common.base.Function; + +/** + * Unit tests for the {@link AppendApiVersionToAbiquoMimeType} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AppendApiVersionToAbiquoMimeTypeTest") +public class AppendApiVersionToAbiquoMimeTypeTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testApplyWithNullInput() + { + Function function = + new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION); + function.apply(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testApplyWithInvalidMediaType() + { + Function function = + new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION); + function.apply("foo"); + } + + public void testApplyToStandardMediaType() + { + Function function = + new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION); + assertEquals(function.apply("application/xml"), "application/xml"); + } + + public void testApplyToAbiquoMediaTypeWithVersion() + { + Function function = + new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION); + assertEquals(function.apply("application/vnd.abiquo.datacenters+xml;version=1.8.5"), + "application/vnd.abiquo.datacenters+xml;version=1.8.5"); + } + + public void testApplyToAbiquoMediaTypeWithoutVersion() + { + Function function = + new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION); + assertEquals(function.apply("application/vnd.abiquo.datacenters+xml"), + "application/vnd.abiquo.datacenters+xml;version=" + AbiquoAsyncApi.API_VERSION); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xxTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xxTest.java new file mode 100644 index 0000000000..5f3b6eb56d --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnAbiquoExceptionOnNotFoundOr4xxTest.java @@ -0,0 +1,86 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.testng.Assert.assertEquals; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.error.ErrorsDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ReturnAbiquoExceptionOnNotFoundOr4xx} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ReturnAbiquoExceptionOnNotFoundOr4xxTest") +public class ReturnAbiquoExceptionOnNotFoundOr4xxTest +{ + public void testReturnOriginalExceptionIfNotResourceNotFound() + { + Function function = new ReturnAbiquoExceptionOnNotFoundOr4xx(); + RuntimeException exception = new RuntimeException(); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + } + + public void testReturnOriginalExceptionIfNotAbiquoException() + { + Function function = new ReturnAbiquoExceptionOnNotFoundOr4xx(); + ResourceNotFoundException exception = new ResourceNotFoundException(); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + } + + public void testReturnAbiquoException() + { + Function function = new ReturnAbiquoExceptionOnNotFoundOr4xx(); + AbiquoException abiquoException = new AbiquoException(Status.NOT_FOUND, new ErrorsDto()); + ResourceNotFoundException exception = new ResourceNotFoundException(abiquoException); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, abiquoException); + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailableTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailableTest.java new file mode 100644 index 0000000000..423c095297 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseIfNotAvailableTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ReturnFalseIfNotAvailable} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ReturnFalseIfNotAvailableTest") +public class ReturnFalseIfNotAvailableTest +{ + public void testReturnOriginalExceptionIfUnknownException() + { + Function function = new ReturnFalseIfNotAvailable(); + RuntimeException exception = new RuntimeException(); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + } + + public void testReturnFalseIf5xx() + { + Function function = new ReturnFalseIfNotAvailable(); + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + + // Status code is called twice + expect(response.getStatusCode()).andReturn(503); + expect(response.getStatusCode()).andReturn(503); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + assertEquals(function.apply(exception), false); + + verify(response); + verify(exception); + } + + public void testReturnExceptionIfNot5xx() + { + Function function = new ReturnFalseIfNotAvailable(); + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + + // Status code is called twice + expect(response.getStatusCode()).andReturn(600); + expect(response.getStatusCode()).andReturn(600); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + + verify(response); + verify(exception); + } + + public void testReturnFalseIfResourceNotFound() + { + Function function = new ReturnFalseIfNotAvailable(); + ResourceNotFoundException exception = new ResourceNotFoundException(); + + assertEquals(function.apply(exception), false); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseOn5xxTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseOn5xxTest.java new file mode 100644 index 0000000000..8cab916359 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnFalseOn5xxTest.java @@ -0,0 +1,111 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.testng.annotations.Test; + +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ReturnFalseOn5xx} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ReturnFalseOn5xxTest") +public class ReturnFalseOn5xxTest +{ + public void testReturnOriginalExceptionIfNotHttpResponseException() + { + Function function = new ReturnFalseOn5xx(); + RuntimeException exception = new RuntimeException(); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + } + + public void testReturnFalseIf5xx() + { + Function function = new ReturnFalseOn5xx(); + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + + // Status code is called twice + expect(response.getStatusCode()).andReturn(503); + expect(response.getStatusCode()).andReturn(503); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + assertEquals(function.apply(exception), false); + + verify(response); + verify(exception); + } + + public void testReturnExceptionIfNot5xx() + { + Function function = new ReturnFalseOn5xx(); + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + + // Status code is called twice + expect(response.getStatusCode()).andReturn(600); + expect(response.getStatusCode()).andReturn(600); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + + verify(response); + verify(exception); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnNullOn303Test.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnNullOn303Test.java new file mode 100644 index 0000000000..c79f5349f5 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnNullOn303Test.java @@ -0,0 +1,110 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import org.easymock.EasyMock; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.testng.annotations.Test; + +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ReturnNullOn303} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ReturnNullOn303Test") +public class ReturnNullOn303Test +{ + public void testReturnOriginalExceptionIfNotHttpResponseException() + { + Function function = new ReturnNullOn303(); + RuntimeException exception = new RuntimeException(); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + } + + public void testReturnNullIf303() + { + Function function = new ReturnNullOn303(); + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + + // Status code is called once + expect(response.getStatusCode()).andReturn(303); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + assertNull(function.apply(exception)); + + verify(response); + verify(exception); + } + + public void testReturnExceptionIfNot303() + { + Function function = new ReturnNullOn303(); + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + + // Status code is called once + expect(response.getStatusCode()).andReturn(600); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + + verify(response); + verify(exception); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNullTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNullTest.java new file mode 100644 index 0000000000..0fb2db3a64 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/ReturnTaskReferenceOrNullTest.java @@ -0,0 +1,98 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.io.IOException; + +import javax.ws.rs.core.Response.Status; + +import org.easymock.EasyMock; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.model.transport.AcceptedRequestDto; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * Unit tests for the {@link ReturnTaskReferenceOrNull} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ReturnTaskReferenceOrNullTest") +public class ReturnTaskReferenceOrNullTest +{ + public void testReturnNullIfNoContent() + { + Function> function = + new ReturnTaskReferenceOrNull(new JAXBParser("false"), createTypeLiteral()); + + HttpResponse response = EasyMock.createMock(HttpResponse.class); + + expect(response.getStatusCode()).andReturn(Status.NO_CONTENT.getStatusCode()); + expect(response.getPayload()).andReturn(null); + + replay(response); + + assertNull(function.apply(response)); + + verify(response); + } + + public void testReturnTaskIfAccepted() throws IOException + { + JAXBParser parser = new JAXBParser("false"); + AcceptedRequestDto< ? > task = new AcceptedRequestDto(); + Payload payload = Payloads.newPayload(parser.toXML(task)); + + Function> function = + new ReturnTaskReferenceOrNull(parser, createTypeLiteral()); + + HttpResponse response = EasyMock.createMock(HttpResponse.class); + + expect(response.getStatusCode()).andReturn(Status.ACCEPTED.getStatusCode()); + // Get payload is called three times: one to deserialize it, and twice to release it + expect(response.getPayload()).andReturn(payload); + expect(response.getPayload()).andReturn(payload); + expect(response.getPayload()).andReturn(payload); + + replay(response); + + assertTrue(function.apply(response) instanceof AcceptedRequestDto); + + verify(response); + } + + private static TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolumeTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolumeTest.java new file mode 100644 index 0000000000..a86b2302dd --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/cloud/ReturnMovedVolumeTest.java @@ -0,0 +1,106 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.cloud; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; + +import javax.ws.rs.core.Response.Status; + +import org.easymock.EasyMock; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.xml.internal.JAXBParser; +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.storage.MovedVolumeDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * Unit tests for the {@link ReturnMovedVolume} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ReturnMovedVolumeTest") +public class ReturnMovedVolumeTest +{ + public void testReturnOriginalExceptionIfNotHttpResponseException() + { + Function function = + new ReturnMovedVolume(new ReturnMoveVolumeReference(new JAXBParser("false"), + TypeLiteral.get(MovedVolumeDto.class))); + + RuntimeException exception = new RuntimeException(); + + try + { + function.apply(exception); + } + catch (Exception ex) + { + assertEquals(ex, exception); + } + } + + public void testReturnVolume() throws IOException + { + JAXBParser xmlParser = new JAXBParser("false"); + Function function = + new ReturnMovedVolume(new ReturnMoveVolumeReference(new JAXBParser("false"), + TypeLiteral.get(MovedVolumeDto.class))); + + VolumeManagementDto volume = new VolumeManagementDto(); + volume.setName("Test volume"); + MovedVolumeDto movedRef = new MovedVolumeDto(); + movedRef.setVolume(volume); + + HttpResponse response = EasyMock.createMock(HttpResponse.class); + HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); + Payload payload = Payloads.newPayload(xmlParser.toXML(movedRef)); + + // Status code is called once + expect(response.getStatusCode()).andReturn(Status.MOVED_PERMANENTLY.getStatusCode()); + // Get response gets called twice + expect(exception.getResponse()).andReturn(response); + expect(exception.getResponse()).andReturn(response); + // Get payload is called three times: one to deserialize it, and twice to release it + expect(response.getPayload()).andReturn(payload); + expect(response.getPayload()).andReturn(payload); + expect(response.getPayload()).andReturn(payload); + // Get cause is called to determine the root cause + expect(exception.getCause()).andReturn(null); + + replay(response); + replay(exception); + + function.apply(exception); + + verify(response); + verify(exception); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseIdTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseIdTest.java new file mode 100644 index 0000000000..2822fae898 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/enterprise/ParseEnterpriseIdTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.enterprise; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.EnterpriseDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ParseEnterpriseId} function. + * + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "ParseEnterpriseIdTest") +public class ParseEnterpriseIdTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + Function parser = new ParseEnterpriseId(); + parser.apply(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidInputType() + { + Function parser = new ParseEnterpriseId(); + parser.apply(new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidId() + { + Function parser = new ParseEnterpriseId(); + parser.apply(new EnterpriseDto()); + } + + public void testValidId() + { + Function parser = new ParseEnterpriseId(); + + EnterpriseDto enterprise = new EnterpriseDto(); + enterprise.setId(5); + assertEquals(parser.apply(enterprise), "5"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterIdTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterIdTest.java new file mode 100644 index 0000000000..bf93734732 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseDatacenterIdTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.infrastructure; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.DatacenterDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ParseDatacenterId} function. + * + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "ParseDatacenterIdTest") +public class ParseDatacenterIdTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + Function parser = new ParseDatacenterId(); + parser.apply(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidInputType() + { + Function parser = new ParseDatacenterId(); + parser.apply(new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidId() + { + Function parser = new ParseDatacenterId(); + parser.apply(new DatacenterDto()); + } + + public void testValidId() + { + Function parser = new ParseDatacenterId(); + + DatacenterDto datacenter = new DatacenterDto(); + datacenter.setId(5); + assertEquals(parser.apply(datacenter), "5"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineIdTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineIdTest.java new file mode 100644 index 0000000000..2d1a938959 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseMachineIdTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.infrastructure; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.abiquo.server.core.infrastructure.MachineDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ParseMachineId} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ParseMachineIdTest") +public class ParseMachineIdTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + Function parser = new ParseMachineId(); + parser.apply(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidInputType() + { + Function parser = new ParseMachineId(); + parser.apply(new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidId() + { + Function parser = new ParseMachineId(); + parser.apply(new MachineDto()); + } + + public void testValidId() + { + Function parser = new ParseMachineId(); + + MachineDto machine = new MachineDto(); + machine.setId(5); + assertEquals(parser.apply(machine), "5"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceTypeTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceTypeTest.java new file mode 100644 index 0000000000..828ae42f19 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/functions/infrastructure/ParseRemoteServiceTypeTest.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.functions.infrastructure; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.RemoteServiceType; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ParseRemoteServiceType} functions. + * + * @author Francesc Montserrat + */ +@Test(groups = "unit", testName = "ParseRemoteServiceTypeTest") +public class ParseRemoteServiceTypeTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() + { + Function parser = new ParseRemoteServiceType(); + parser.apply(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidInputType() + { + Function parser = new ParseRemoteServiceType(); + parser.apply(new Object()); + } + + public void testValidId() + { + Function parser = new ParseRemoteServiceType(); + assertEquals(parser.apply(RemoteServiceType.BPM_SERVICE), "bpmservice"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java new file mode 100644 index 0000000000..baf418593c --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java @@ -0,0 +1,199 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.http.filters; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpUtils.releasePayload; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.Collection; +import java.util.Properties; + +import javax.ws.rs.core.Cookie; +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.ContextBuilder; +import org.jclouds.abiquo.AbiquoApiMetadata; +import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.abiquo.reference.AbiquoConstants; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.rest.AuthorizationException; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.abiquo.server.core.enterprise.UserDto; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Live tests for the {@link AbiquoAuthentication} filter. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "AbiquoAuthenticationLiveApiTest") +public class AbiquoAuthenticationLiveApiTest +{ + private String identity; + + private String credential; + + private String endpoint; + + @BeforeMethod + public void setupToken() + { + identity = checkNotNull(System.getProperty("test.abiquo.identity"), "test.abiquo.identity"); + credential = + checkNotNull(System.getProperty("test.abiquo.credential"), "test.abiquo.credential"); + endpoint = checkNotNull(System.getProperty("test.abiquo.endpoint"), "test.abiquo.endpoint"); + } + + @Test + public void testAuthenticateWithToken() throws IOException + { + String token = getAuthtenticationToken(); + + Properties props = new Properties(); + props.setProperty(AbiquoConstants.CREDENTIAL_IS_TOKEN, "true"); + + // Create a new context that uses the generated token to perform the API calls + AbiquoContext tokenContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // + .endpoint(endpoint) // + .credentials("token", token) // + .modules(ImmutableSet. of(new SLF4JLoggingModule())) // + .overrides(props) // + .build(AbiquoContext.class); + + try + { + // Perform a call to get the logged user and verify the identity + UserDto user = tokenContext.getApiContext().getApi().getAdminApi().getCurrentUser(); + assertNotNull(user); + assertEquals(user.getNick(), identity); + } + finally + { + if (tokenContext != null) + { + tokenContext.close(); + } + } + } + + @Test + public void testAuthenticateWithInvalidToken() throws IOException + { + String token = getAuthtenticationToken() + "INVALID"; + + Properties props = new Properties(); + props.setProperty(AbiquoConstants.CREDENTIAL_IS_TOKEN, "true"); + + // Create a new context that uses the generated token to perform the API calls + AbiquoContext tokenContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // + .endpoint(endpoint) // + .credentials("token", token) // + .modules(ImmutableSet. of(new SLF4JLoggingModule())) // + .overrides(props) // + .build(AbiquoContext.class); + + // Perform a call to get the logged user. It should fail + try + { + tokenContext.getApiContext().getApi().getAdminApi().getCurrentUser(); + } + catch (AuthorizationException ex) + { + // Test succeeded + return; + } + finally + { + if (tokenContext != null) + { + tokenContext.close(); + } + } + + fail("Token authentication should have failed"); + } + + private String getAuthtenticationToken() throws UnsupportedEncodingException + { + String token = null; + + AbiquoContext context = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // + .endpoint(endpoint) // + .credentials(identity, credential) // + .modules(ImmutableSet. of(new SLF4JLoggingModule())) // + .build(AbiquoContext.class); + + try + { + // Create a request to authenticate to the API and generate the token + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create(endpoint)).build(); + String auth = AbiquoAuthentication.basicAuth(identity, credential); + request = request.toBuilder().replaceHeader(HttpHeaders.AUTHORIZATION, auth).build(); + + // Execute the request and read the generated token + HttpResponse response = context.utils().http().invoke(request); + assertEquals(response.getStatusCode(), 200); + + token = readAuthenticationToken(response); + assertNotNull(token); + + releasePayload(response); + } + finally + { + if (context != null) + { + context.close(); + } + } + + return token; + } + + private String readAuthenticationToken(final HttpResponse response) + { + Collection cookies = response.getHeaders().get(HttpHeaders.SET_COOKIE); + assertFalse(cookies.isEmpty()); + + for (String cookie : cookies) + { + Cookie c = Cookie.valueOf(cookie); + if (c.getName().equals(AbiquoAuthentication.AUTH_TOKEN_NAME)) + { + return c.getValue(); + } + } + + return null; + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationTest.java new file mode 100644 index 0000000000..2bfce5e1a6 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationTest.java @@ -0,0 +1,99 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.http.filters; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; + +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link AbiquoAuthentication} filter. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AbiquoAuthenticationTest") +public class AbiquoAuthenticationTest +{ + + public void testBasicAuthentication() throws UnsupportedEncodingException, + NoSuchAlgorithmException, CertificateException + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).build(); + + AbiquoAuthentication filter = new AbiquoAuthentication("identity", "credential", "false"); + HttpRequest filtered = filter.filter(request); + HttpRequest expected = + request + .toBuilder() + .replaceHeader(HttpHeaders.AUTHORIZATION, + AbiquoAuthentication.basicAuth("identity", "credential")).build(); + + assertFalse(filtered.getHeaders().containsKey(HttpHeaders.COOKIE)); + assertEquals(filtered, expected); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testBasicAuthenticationWithoutIdentity() throws UnsupportedEncodingException, + NoSuchAlgorithmException, CertificateException + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).build(); + + AbiquoAuthentication filter = new AbiquoAuthentication(null, "credential", "false"); + filter.filter(request); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testBasicAuthenticationWithoutCredential() throws UnsupportedEncodingException, + NoSuchAlgorithmException, CertificateException + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).build(); + + AbiquoAuthentication filter = new AbiquoAuthentication("identity", null, "false"); + filter.filter(request); + } + + public void testTokenAuthentication() throws UnsupportedEncodingException, + NoSuchAlgorithmException, CertificateException + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).build(); + + AbiquoAuthentication filter = new AbiquoAuthentication("token-identity", "token", "true"); + HttpRequest filtered = filter.filter(request); + HttpRequest expected = + request.toBuilder() + .replaceHeader(HttpHeaders.COOKIE, AbiquoAuthentication.tokenAuth("token")).build(); + + assertFalse(filtered.getHeaders().containsKey(HttpHeaders.AUTHORIZATION)); + assertEquals(filtered, expected); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaTypeTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaTypeTest.java new file mode 100644 index 0000000000..02ce2827b9 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AppendApiVersionToMediaTypeTest.java @@ -0,0 +1,310 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.http.filters; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Collection; + +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.functions.AppendApiVersionToAbiquoMimeType; +import org.jclouds.http.HttpRequest; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.testng.annotations.Test; + +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Multimap; + +/** + * Unit tests for the {@link AppendApiVersionToMediaType} filter. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AppendApiVersionToMediaTypeTest") +public class AppendApiVersionToMediaTypeTest +{ + + public void testAppendVersionToNonPayloadHeadersWithoutHeaders() + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToNonPayloadHeaders(request); + + assertTrue(filtered.getHeaders().get(HttpHeaders.ACCEPT).isEmpty()); + } + + public void testAppendVersionToNonPayloadHeadersWithStandardMediaType() + { + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/xml"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToNonPayloadHeaders(request); + + Collection contentType = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(contentType.size(), 1); + assertEquals(contentType.iterator().next(), "application/xml"); + } + + public void testAppendVersionToNonPayloadHeadersWithVersionInMediaType() + { + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/vnd.abiquo.racks+xml;version=2.1-SNAPSHOT"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToNonPayloadHeaders(request); + + Collection contentType = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(contentType.size(), 1); + assertEquals(contentType.iterator().next(), + "application/vnd.abiquo.racks+xml;version=2.1-SNAPSHOT"); + } + + public void testAppendVersionToNonPayloadHeadersWithoutVersionInMediaType() + { + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/vnd.abiquo.racks+xml"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToNonPayloadHeaders(request); + + Collection accept = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(accept.size(), 1); + assertEquals(accept.iterator().next(), "application/vnd.abiquo.racks+xml;version=" + + AbiquoAsyncApi.API_VERSION); + } + + public void testAppendVersionToPayloadHeadersWithoutPayload() + { + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToPayloadHeaders(request); + + assertNull(filtered.getPayload()); + } + + public void testAppendVersionToPayloadHeadersWithStandardPayload() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType("application/xml"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).payload(payload) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToPayloadHeaders(request); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), "application/xml"); + } + + public void testAppendVersionToPayloadHeadersWithDefaultPayload() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).payload(payload) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToPayloadHeaders(request); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/unknown"); + } + + public void testAppendVersionToPayloadHeadersWithVersionInPayload() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType( + "application/vnd.abiquo.racks+xml;version=1.8.5"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).payload(payload) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToPayloadHeaders(request); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/vnd.abiquo.racks+xml;version=1.8.5"); + } + + public void testAppendVersionToPayloadHeadersWithoutVersionInPayload() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType("application/vnd.abiquo.racks+xml"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).payload(payload) + .build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.appendVersionToPayloadHeaders(request); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/vnd.abiquo.racks+xml;version=" + AbiquoAsyncApi.API_VERSION); + } + + public void testFilterWithAcceptAndContentTypeWithVersion() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType( + "application/vnd.abiquo.racks+xml;version=2.1-SNAPSHOT"); + + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/vnd.abiquo.racks+xml;version=2.1-SNAPSHOT"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .payload(payload).build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.filter(request); + + Collection accept = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(accept.size(), 1); + assertEquals(accept.iterator().next(), + "application/vnd.abiquo.racks+xml;version=2.1-SNAPSHOT"); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/vnd.abiquo.racks+xml;version=2.1-SNAPSHOT"); + } + + public void testFilterWithAcceptAndContentTypeWithoutVersion() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType("application/vnd.abiquo.racks+xml"); + + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/vnd.abiquo.racks+xml"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .payload(payload).build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.filter(request); + + Collection accept = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(accept.size(), 1); + assertEquals(accept.iterator().next(), "application/vnd.abiquo.racks+xml;version=" + + AbiquoAsyncApi.API_VERSION); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/vnd.abiquo.racks+xml;version=" + AbiquoAsyncApi.API_VERSION); + } + + public void testFilterWithversionInAccept() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType("application/vnd.abiquo.racks+xml"); + + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/vnd.abiquo.racks+xml;version=1.8.5"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .payload(payload).build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.filter(request); + + Collection accept = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(accept.size(), 1); + assertEquals(accept.iterator().next(), "application/vnd.abiquo.racks+xml;version=1.8.5"); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/vnd.abiquo.racks+xml;version=" + AbiquoAsyncApi.API_VERSION); + } + + public void testFilterWithversionInContentType() + { + Payload payload = Payloads.newByteArrayPayload(new byte[] {}); + payload.getContentMetadata().setContentType( + "application/vnd.abiquo.racks+xml;version=1.8.5"); + + Multimap headers = LinkedHashMultimap. create(); + headers.put(HttpHeaders.ACCEPT, "application/vnd.abiquo.racks+xml"); + + HttpRequest request = + HttpRequest.builder().method("GET").endpoint(URI.create("http://foo")).headers(headers) + .payload(payload).build(); + + AppendApiVersionToMediaType filter = + new AppendApiVersionToMediaType(new AppendApiVersionToAbiquoMimeType(AbiquoAsyncApi.API_VERSION)); + + HttpRequest filtered = filter.filter(request); + + Collection accept = filtered.getHeaders().get(HttpHeaders.ACCEPT); + assertEquals(accept.size(), 1); + assertEquals(accept.iterator().next(), "application/vnd.abiquo.racks+xml;version=" + + AbiquoAsyncApi.API_VERSION); + + assertEquals(filtered.getPayload().getContentMetadata().getContentType(), + "application/vnd.abiquo.racks+xml;version=1.8.5"); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java new file mode 100644 index 0000000000..0a45f0a2fd --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java @@ -0,0 +1,523 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static org.easymock.EasyMock.anyLong; +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.events.monitor.MonitorEvent; +import org.jclouds.abiquo.internal.BaseMonitoringService.AsyncMonitor; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +/** + * Unit tests for the {@link AsyncMonitor} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AsyncMonitorTest") +public class AsyncMonitorTest +{ + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testStartMonitoringWithoutTimeout() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testStartMonitoringWithTimeout() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(100L); + + assertNotNull(monitor.getFuture()); + assertNotNull(monitor.getTimeout()); + assertTrue(monitor.getTimeout() > 100L); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testIsTimeoutWhenNullTimeout() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + assertFalse(monitor.isTimeout()); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testIsTimeoutReturnsFalseWhenNotFinished() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(60000L); + assertNotNull(monitor.getFuture()); + assertNotNull(monitor.getTimeout()); + assertFalse(monitor.isTimeout()); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testIsTimeoutReturnsTrueWhenFinished() throws InterruptedException + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(1L); + Thread.sleep(2L); + assertNotNull(monitor.getFuture()); + assertNotNull(monitor.getTimeout()); + assertTrue(monitor.isTimeout()); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testStopMonitoringWhenFutureIsCancelled() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + expect(mockFuture.isCancelled()).andReturn(true); + + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.stopMonitoring(); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testStopMonitoringWhenFutureIsDone() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + expect(mockFuture.isCancelled()).andReturn(false); + expect(mockFuture.isDone()).andReturn(true); + + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.stopMonitoring(); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testStopMonitoringWhenFutureIsNotComplete() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + expect(mockFuture.isCancelled()).andReturn(false); + expect(mockFuture.isDone()).andReturn(false); + expect(mockFuture.cancel(false)).andReturn(true); + + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), + new EventBus()); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.stopMonitoring(); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testMonitorAndDone() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + expect(mockFuture.isCancelled()).andReturn(true); + + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + CoutingEventHandler handler = new CoutingEventHandler(); + EventBus eventBus = new EventBus(); + eventBus.register(handler); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.DONE), eventBus); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.run(); + assertEquals(handler.numCompletes, 1); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 0); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testMonitorAndFail() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + expect(mockFuture.isCancelled()).andReturn(true); + + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + CoutingEventHandler handler = new CoutingEventHandler(); + EventBus eventBus = new EventBus(); + eventBus.register(handler); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.FAILED), eventBus); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.run(); + assertEquals(handler.numCompletes, 0); + assertEquals(handler.numFailures, 1); + assertEquals(handler.numTimeouts, 0); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testMonitorAndContinueWithoutTimeout() + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + CoutingEventHandler handler = new CoutingEventHandler(); + EventBus eventBus = new EventBus(); + eventBus.register(handler); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.CONTINUE), eventBus); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(null); + assertNotNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.run(); + assertEquals(handler.numCompletes, 0); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 0); + + verify(mockFuture); + verify(schedulerMock); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testMonitorAndContinueWithtTimeout() throws InterruptedException + { + ScheduledFuture mockFuture = EasyMock.createMock(ScheduledFuture.class); + expect(mockFuture.isCancelled()).andReturn(true); + + ScheduledExecutorService schedulerMock = + EasyMock.createMock(ScheduledExecutorService.class); + expect( + schedulerMock.scheduleWithFixedDelay(anyObject(Runnable.class), anyLong(), anyLong(), + anyObject(TimeUnit.class))).andReturn(mockFuture); + + replay(mockFuture); + replay(schedulerMock); + + CoutingEventHandler handler = new CoutingEventHandler(); + EventBus eventBus = new EventBus(); + eventBus.register(handler); + + AsyncMonitor monitor = + mockMonitor(schedulerMock, new Object(), mockFunction(MonitorStatus.CONTINUE), eventBus); + + assertNull(monitor.getFuture()); + assertNull(monitor.getTimeout()); + + monitor.startMonitoring(1L); + assertNotNull(monitor.getFuture()); + assertNotNull(monitor.getTimeout()); + + Thread.sleep(2L); + monitor.run(); + assertEquals(handler.numCompletes, 0); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 1); + + verify(mockFuture); + verify(schedulerMock); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testCreateMonitorWithNullObject() + { + mockMonitor(null, null, new Function() + { + @Override + public MonitorStatus apply(final Object input) + { + return MonitorStatus.DONE; + } + }, new EventBus()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testCreateMonitorWithNullFunction() + { + mockMonitor(null, new Object(), null, new EventBus()); + } + + @SuppressWarnings("unchecked") + private AsyncMonitor mockMonitor(final ScheduledExecutorService scheduler, + final Object object, final Function function, final EventBus eventBus) + { + BaseMonitoringService monitorService = + new BaseMonitoringService(EasyMock.createMock(RestContext.class), + scheduler, + 100L, + eventBus); + + return monitorService.new AsyncMonitor(object, function); + } + + private Function mockFunction(final MonitorStatus status) + { + return new Function() + { + @Override + public MonitorStatus apply(final Object input) + { + return status; + } + }; + } + + private static class CoutingEventHandler + { + public int numCompletes = 0; + + public int numFailures = 0; + + public int numTimeouts = 0; + + @Subscribe + @SuppressWarnings("unused") + public void handle(final MonitorEvent< ? > event) + { + switch (event.getType()) + { + case COMPLETED: + numCompletes++; + break; + case FAILED: + numFailures++; + break; + case TIMEOUT: + numTimeouts++; + break; + } + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java new file mode 100644 index 0000000000..40fc5fafa5 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java @@ -0,0 +1,105 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import org.jclouds.abiquo.environment.CloudTestEnvironment; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +/** + * Base class for live and domain tests. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "BaseAbiquoApiLiveApiTest", singleThreaded = true) +public abstract class BaseAbiquoApiLiveApiTest extends BaseAbiquoLiveApiTest +{ + /** The test environment. */ + protected static CloudTestEnvironment env; + + @Override + @BeforeSuite(groups = "api") + public void setupContext() + { + super.setupContext(); + setupEnvironment(); + } + + // @BeforeSuite(groups = "ucs", dependsOnMethods = "setupContext") + protected void setupUcsEnvironment() throws Exception + { + if (env != null) + { + env.createUcsRack(); + } + } + + @Override + @AfterSuite(groups = "api") + protected void tearDownContext() + { + try + { + tearDownEnvironment(); + } + finally + { + // Make sure we close the context + super.tearDownContext(); + } + } + + protected void setupEnvironment() + { + if (env == null) + { + try + { + env = new CloudTestEnvironment(view); + env.setup(); + } + catch (Exception ex) + { + super.tearDownContext(); // Make sure we close the context setup fails + throw new RuntimeException("Could not create environment", ex); + } + } + } + + protected void tearDownEnvironment() + { + if (env != null) + { + try + { + env.tearDown(); + + // Wait a bit before closing context, to avoid executor shutdown while + // there are still open threads + Thread.sleep(1000L); + } + catch (Exception ex) + { + throw new RuntimeException("Could not tear down environment", ex); + } + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoLiveApiTest.java new file mode 100644 index 0000000000..290c4493fb --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoLiveApiTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import java.util.Properties; + +import org.jclouds.Constants; +import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.apis.BaseViewLiveTest; +import org.jclouds.logging.config.LoggingModule; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; + +import com.google.common.reflect.TypeToken; + +/** + * Base class for Abiquo live tests. + * + * @author Ignasi Barrera + */ +public abstract class BaseAbiquoLiveApiTest extends BaseViewLiveTest +{ + public BaseAbiquoLiveApiTest() + { + provider = "abiquo"; + } + + @Override + protected Properties setupProperties() + { + Properties overrides = super.setupProperties(); + overrides.put(Constants.PROPERTY_MAX_RETRIES, "0"); + overrides.put(Constants.PROPERTY_MAX_REDIRECTS, "0"); + // Wait at most one minute in Machine discovery + overrides.put("jclouds.timeouts.InfrastructureApi.discoverSingleMachine", "60000"); + overrides.put("jclouds.timeouts.InfrastructureApi.discoverMultipleMachines", "60000"); + overrides.put("jclouds.timeouts.InfrastructureApi.createMachine", "60000"); + overrides.put("jclouds.timeouts.InfrastructureApi.updateMachine", "60000"); + overrides.put("jclouds.timeouts.InfrastructureApi.checkMachineState", "60000"); + overrides.put("jclouds.timeouts.CloudApi.listVirtualMachines", "60000"); + return overrides; + } + + @Override + protected LoggingModule getLoggingModule() + { + return new SLF4JLoggingModule(); + } + + @Override + protected TypeToken viewType() + { + return TypeToken.of(AbiquoContext.class); + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAdministrationServiceTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAdministrationServiceTest.java new file mode 100644 index 0000000000..f95f5deaef --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAdministrationServiceTest.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.features.services.AdministrationService; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseAdministrationService} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseAdministrationServiceTest") +public class BaseAdministrationServiceTest extends BaseInjectionTest +{ + + public void testAllPropertiesInjected() + { + BaseAdministrationService service = + (BaseAdministrationService) injector.getInstance(AdministrationService.class); + + assertNotNull(service.context); + assertNotNull(service.listDatacenters); + assertNotNull(service.listMachines); + assertNotNull(service.listEnterprises); + assertNotNull(service.listLicenses); + assertNotNull(service.listPrivileges); + assertNotNull(service.listRoles); + assertNotNull(service.currentUser); + assertNotNull(service.currentEnterprise); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseCloudServiceTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseCloudServiceTest.java new file mode 100644 index 0000000000..e90806b064 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseCloudServiceTest.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.features.services.CloudService; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseCloudService} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseCloudServiceTest") +public class BaseCloudServiceTest extends BaseInjectionTest +{ + + public void testAllPropertiesInjected() + { + BaseCloudService service = (BaseCloudService) injector.getInstance(CloudService.class); + + assertNotNull(service.context); + assertNotNull(service.listVirtualDatacenters); + assertNotNull(service.listVirtualAppliances); + assertNotNull(service.listVirtualMachines); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseEventServiceTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseEventServiceTest.java new file mode 100644 index 0000000000..39a6fd318b --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseEventServiceTest.java @@ -0,0 +1,42 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.features.services.EventService; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseEventService} class. + * + * @author Vivien Mahé + */ +@Test(groups = "unit", testName = "BaseEventServiceTest") +public class BaseEventServiceTest extends BaseInjectionTest +{ + public void testAllPropertiesInjected() + { + BaseEventService service = (BaseEventService) injector.getInstance(EventService.class); + + assertNotNull(service.context); + assertNotNull(service.listEvents); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseInjectionTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseInjectionTest.java new file mode 100644 index 0000000000..3749a80e8e --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseInjectionTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import java.util.Properties; + +import org.jclouds.ContextBuilder; +import org.jclouds.abiquo.AbiquoApiMetadata; +import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.lifecycle.Closer; +import org.jclouds.logging.config.NullLoggingModule; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Injector; +import com.google.inject.Module; + +/** + * Unit tests for the {@link BaseCloudService} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseEventServiceTest") +public class BaseInjectionTest +{ + protected Injector injector; + + @BeforeClass + public void setup() + { + injector = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // + .credentials("identity", "credential") // + .modules(ImmutableSet. of(new NullLoggingModule())) // + .overrides(buildProperties()) // + .build(AbiquoContext.class).getUtils().getInjector(); + } + + protected Properties buildProperties() + { + return new Properties(); + } + + @AfterClass + public void tearDown() throws Exception + { + if (injector != null) + { + injector.getInstance(Closer.class).close(); + } + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java new file mode 100644 index 0000000000..9d7ca5520b --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java @@ -0,0 +1,260 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import org.jclouds.abiquo.events.handlers.BlockingEventHandler; +import org.jclouds.abiquo.events.monitor.MonitorEvent; +import org.jclouds.abiquo.features.services.MonitoringService; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.testng.annotations.Test; + +import com.google.common.base.Function; + +/** + * Unit tests for the {@link BaseMonitoringService} class. + * + * @author Ignasi Barrera + */ +// Since these tests block the thread, mark them as failed after the given timeout +@Test(groups = "unit", testName = "BaseMonitoringServiceTest", timeOut = 10000L) +public class BaseMonitoringServiceTest extends BaseInjectionTest +{ + // The polling interval used in tests (in ms) + private static final long TEST_MONITOR_POLLING = 100L; + + @Override + protected Properties buildProperties() + { + // Use a small monitor polling interval in tests (in ms) + Properties props = super.buildProperties(); + props.setProperty(ASYNC_TASK_MONITOR_DELAY, String.valueOf(TEST_MONITOR_POLLING)); + return props; + } + + public void testAllPropertiesInjected() + { + BaseMonitoringService service = + (BaseMonitoringService) injector.getInstance(MonitoringService.class); + + assertNotNull(service.context); + assertNotNull(service.scheduler); + assertNotNull(service.pollingDelay); + assertNotNull(service.eventBus); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testAwaitCompletionWithNullFunction() + { + monitoringService().awaitCompletion(null, new Object[] {}); + } + + public void testAwaitCompletionWithoutTasks() + { + BaseMonitoringService service = monitoringService(); + + service.awaitCompletion(new MockMonitor()); + service.awaitCompletion(new MockMonitor(), (Object[]) null); + service.awaitCompletion(new MockMonitor(), new Object[] {}); + } + + public void testAwaitCompletion() + { + BaseMonitoringService service = monitoringService(); + service.awaitCompletion(new MockMonitor(), new Object()); + } + + public void testAwaitCompletionMultipleTasks() + { + BaseMonitoringService service = monitoringService(); + service.awaitCompletion(new MockMonitor(), new Object(), new Object()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testMonitorWithNullCompletecondition() + { + monitoringService().monitor(null, (Object[]) null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testBlockingHandlerWithoutArguments() + { + new BlockingEventHandler(); + } + + public void testMonitor() + { + BaseMonitoringService service = monitoringService(); + + Object monitoredObject = new Object(); + CountingHandler handler = new CountingHandler(monitoredObject); + service.register(handler); + + service.monitor(new MockMonitor(), monitoredObject); + handler.lock(); + + service.unregister(handler); + + assertEquals(handler.numCompletes, 1); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 0); + } + + public void testMonitorMultipleTasks() + { + BaseMonitoringService service = monitoringService(); + + Object monitoredObject1 = new Object(); + Object monitoredObject2 = new Object(); + CountingHandler handler = new CountingHandler(monitoredObject1, monitoredObject2); + service.register(handler); + + service.monitor(new MockMonitor(), monitoredObject1, monitoredObject2); + handler.lock(); + + service.unregister(handler); + + assertEquals(handler.numCompletes, 2); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 0); + } + + public void testMonitorReachesTimeout() + { + BaseMonitoringService service = monitoringService(); + + Object monitoredObject = new Object(); + CountingHandler handler = new CountingHandler(monitoredObject); + service.register(handler); + + service.monitor(TEST_MONITOR_POLLING + 10L, TimeUnit.MILLISECONDS, + new MockInfiniteMonitor(), monitoredObject); + handler.lock(); + + service.unregister(handler); + + assertEquals(handler.numCompletes, 0); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 1); + } + + public void testMonitorMultipleTasksReachesTimeout() + { + BaseMonitoringService service = monitoringService(); + + Object monitoredObject1 = new Object(); + Object monitoredObject2 = new Object(); + CountingHandler handler = new CountingHandler(monitoredObject1, monitoredObject2); + service.register(handler); + + service.monitor(TEST_MONITOR_POLLING + 10L, TimeUnit.MILLISECONDS, + new MockInfiniteMonitor(), monitoredObject1, monitoredObject2); + handler.lock(); + + service.unregister(handler); + + assertEquals(handler.numCompletes, 0); + assertEquals(handler.numFailures, 0); + assertEquals(handler.numTimeouts, 2); + } + + public void testDelegateToVirtualMachineMonitor() + { + assertNotNull(monitoringService().getVirtualMachineMonitor()); + } + + public void testDelegateToVirtualApplianceMonitor() + { + assertNotNull(monitoringService().getVirtualApplianceMonitor()); + } + + public void testDelegateToAsyncTaskMonitor() + { + assertNotNull(monitoringService().getAsyncTaskMonitor()); + } + + private BaseMonitoringService monitoringService() + { + return injector.getInstance(BaseMonitoringService.class); + } + + private static class MockMonitor implements Function + { + private int finishAfterCount; + + public MockMonitor() + { + this.finishAfterCount = 1; // Simulate task completion after one refresh + } + + @Override + public MonitorStatus apply(final Object object) + { + return finishAfterCount-- <= 0 ? MonitorStatus.DONE : MonitorStatus.CONTINUE; + } + } + + private static class MockInfiniteMonitor implements Function + { + @Override + public MonitorStatus apply(final Object object) + { + return MonitorStatus.CONTINUE; + } + } + + private static class CountingHandler extends BlockingEventHandler + { + public int numCompletes = 0; + + public int numFailures = 0; + + public int numTimeouts = 0; + + public CountingHandler(final Object... lockedObjects) + { + super(lockedObjects); + } + + @Override + protected void doBeforeRelease(final MonitorEvent event) + { + switch (event.getType()) + { + case COMPLETED: + numCompletes++; + break; + case FAILED: + numFailures++; + break; + case TIMEOUT: + numTimeouts++; + break; + } + } + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseSearchServiceTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseSearchServiceTest.java new file mode 100644 index 0000000000..1bd84c6e35 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseSearchServiceTest.java @@ -0,0 +1,42 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.features.services.SearchService; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseSearchService} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseSearchServiceTest") +public class BaseSearchServiceTest extends BaseInjectionTest +{ + + public void testAllPropertiesInjected() + { + BaseSearchService service = (BaseSearchService) injector.getInstance(SearchService.class); + + assertNotNull(service.context); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitorTest.java new file mode 100644 index 0000000000..4c7b626ce7 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitorTest.java @@ -0,0 +1,118 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.task.AsyncTask; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.server.core.task.TaskDto; +import com.abiquo.server.core.task.enums.TaskState; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link AsyncTaskStatusMonitor} function. + * + * @author Serafin Sedano + */ +@Test(groups = "unit", testName = "AsyncTaskStatusMonitorTest") +public class AsyncTaskStatusMonitorTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = new AsyncTaskStatusMonitor(); + function.apply(null); + } + + public void testReturnDone() + { + TaskState[] states = {TaskState.FINISHED_SUCCESSFULLY}; + + checkStatesReturn(new MockAsyncTask(), new AsyncTaskStatusMonitor(), states, + MonitorStatus.DONE); + } + + public void testReturnFail() + { + TaskState[] states = {TaskState.ABORTED, TaskState.FINISHED_UNSUCCESSFULLY}; + + checkStatesReturn(new MockAsyncTask(), new AsyncTaskStatusMonitor(), states, + MonitorStatus.FAILED); + } + + public void testReturnContinue() + { + TaskState[] states = {TaskState.STARTED, TaskState.PENDING}; + + checkStatesReturn(new MockAsyncTask(), new AsyncTaskStatusMonitor(), states, + MonitorStatus.CONTINUE); + + checkStatesReturn(new MockAsyncTaskFailing(), new AsyncTaskStatusMonitor(), states, + MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockAsyncTask task, + final Function function, final TaskState[] states, + final MonitorStatus expectedStatus) + { + for (TaskState state : states) + { + task.setState(state); + assertEquals(function.apply(task), expectedStatus); + } + } + + private static class MockAsyncTask extends AsyncTask + { + @SuppressWarnings("unchecked") + public MockAsyncTask() + { + super(EasyMock.createMock(RestContext.class), new TaskDto()); + } + + @Override + public void refresh() + { + // Do not perform any API call + } + + public void setState(final TaskState state) + { + target.setState(state); + } + } + + private static class MockAsyncTaskFailing extends MockAsyncTask + { + @Override + public void refresh() + { + throw new RuntimeException("This mock class always fails to refresh"); + } + + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitorTest.java new file mode 100644 index 0000000000..912e155041 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitorTest.java @@ -0,0 +1,118 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.model.enumerator.ConversionState; +import com.abiquo.server.core.appslibrary.ConversionDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link ConversionStatusMonitor} function. + * + * @author Sergi Castro + */ +@Test(groups = "unit", testName = "ConversionStatusMonitorTest") +public class ConversionStatusMonitorTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = new ConversionStatusMonitor(); + function.apply(null); + } + + public void testReturnDone() + { + ConversionState[] states = {ConversionState.FINISHED}; + + checkStatesReturn(new MockConversion(), new ConversionStatusMonitor(), states, + MonitorStatus.DONE); + } + + public void testReturnFail() + { + ConversionState[] states = {ConversionState.FAILED}; + + checkStatesReturn(new MockConversion(), new ConversionStatusMonitor(), states, + MonitorStatus.FAILED); + } + + public void testReturnContinue() + { + ConversionState[] states = {ConversionState.ENQUEUED}; + + checkStatesReturn(new MockConversion(), new ConversionStatusMonitor(), states, + MonitorStatus.CONTINUE); + + checkStatesReturn(new MockConversionFailing(), new ConversionStatusMonitor(), states, + MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockConversion task, + final Function function, final ConversionState[] states, + final MonitorStatus expectedStatus) + { + for (ConversionState state : states) + { + task.setState(state); + assertEquals(function.apply(task), expectedStatus); + } + } + + private static class MockConversion extends Conversion + { + @SuppressWarnings("unchecked") + public MockConversion() + { + super(EasyMock.createMock(RestContext.class), new ConversionDto()); + } + + @Override + public void refresh() + { + // Do not perform any API call + } + + public void setState(final ConversionState state) + { + target.setState(state); + } + } + + private static class MockConversionFailing extends MockConversion + { + @Override + public void refresh() + { + throw new RuntimeException("This mock class always fails to refresh"); + } + + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitorTest.java new file mode 100644 index 0000000000..261597887a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitorTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceState; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link VirtualApplianceDeployMonitor} function. + * + * @author Serafin Sedano + */ +@Test(groups = "unit", testName = "VirtualApplianceDeployMonitorTest") +public class VirtualApplianceDeployMonitorTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = new VirtualApplianceDeployMonitor(); + function.apply(null); + } + + public void testReturnDone() + { + VirtualApplianceState[] states = {VirtualApplianceState.DEPLOYED}; + + checkStatesReturn(new MockVirtualAppliance(), new VirtualApplianceDeployMonitor(), states, + MonitorStatus.DONE); + } + + public void testReturnFail() + { + VirtualApplianceState[] states = + {VirtualApplianceState.NEEDS_SYNC, VirtualApplianceState.UNKNOWN, + VirtualApplianceState.NOT_DEPLOYED}; + + checkStatesReturn(new MockVirtualAppliance(), new VirtualApplianceDeployMonitor(), states, + MonitorStatus.FAILED); + } + + public void testReturnContinue() + { + VirtualApplianceState[] states = {VirtualApplianceState.LOCKED}; + + checkStatesReturn(new MockVirtualAppliance(), new VirtualApplianceDeployMonitor(), states, + MonitorStatus.CONTINUE); + + checkStatesReturn(new MockVirtualApplianceFailing(), new VirtualApplianceDeployMonitor(), + states, MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockVirtualAppliance vapp, + final Function function, + final VirtualApplianceState[] states, final MonitorStatus expectedStatus) + { + for (VirtualApplianceState state : states) + { + vapp.setState(state); + assertEquals(function.apply(vapp), expectedStatus); + } + } + + private static class MockVirtualAppliance extends VirtualAppliance + { + private VirtualApplianceState state; + + @SuppressWarnings("unchecked") + public MockVirtualAppliance() + { + super(EasyMock.createMock(RestContext.class), new VirtualApplianceDto()); + } + + @Override + public VirtualApplianceState getState() + { + return state; + } + + public void setState(final VirtualApplianceState state) + { + this.state = state; + } + } + + private static class MockVirtualApplianceFailing extends MockVirtualAppliance + { + @Override + public VirtualApplianceState getState() + { + throw new RuntimeException("This mock class always fails to get the state"); + } + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitorTest.java new file mode 100644 index 0000000000..103b76b457 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitorTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualApplianceDto; +import com.abiquo.server.core.cloud.VirtualApplianceState; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link VirtualApplianceUndeployMonitor} function. + * + * @author Serafin Sedano + */ +@Test(groups = "unit", testName = "VirtualApplianceUndeployMonitorTest") +public class VirtualApplianceUndeployMonitorTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = new VirtualApplianceUndeployMonitor(); + function.apply(null); + } + + public void testReturnDone() + { + VirtualApplianceState[] states = {VirtualApplianceState.NOT_DEPLOYED}; + + checkStatesReturn(new MockVirtualAppliance(), new VirtualApplianceUndeployMonitor(), + states, MonitorStatus.DONE); + } + + public void testReturnFail() + { + VirtualApplianceState[] states = + {VirtualApplianceState.DEPLOYED, VirtualApplianceState.NEEDS_SYNC, + VirtualApplianceState.UNKNOWN}; + + checkStatesReturn(new MockVirtualAppliance(), new VirtualApplianceUndeployMonitor(), + states, MonitorStatus.FAILED); + } + + public void testReturnContinue() + { + VirtualApplianceState[] states = {VirtualApplianceState.LOCKED}; + + checkStatesReturn(new MockVirtualAppliance(), new VirtualApplianceUndeployMonitor(), + states, MonitorStatus.CONTINUE); + + checkStatesReturn(new MockVirtualApplianceFailing(), new VirtualApplianceUndeployMonitor(), + states, MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockVirtualAppliance vapp, + final Function function, + final VirtualApplianceState[] states, final MonitorStatus expectedStatus) + { + for (VirtualApplianceState state : states) + { + vapp.setState(state); + assertEquals(function.apply(vapp), expectedStatus); + } + } + + private static class MockVirtualAppliance extends VirtualAppliance + { + private VirtualApplianceState state; + + @SuppressWarnings("unchecked") + public MockVirtualAppliance() + { + super(EasyMock.createMock(RestContext.class), new VirtualApplianceDto()); + } + + @Override + public VirtualApplianceState getState() + { + return state; + } + + public void setState(final VirtualApplianceState state) + { + this.state = state; + } + } + + private static class MockVirtualApplianceFailing extends MockVirtualAppliance + { + @Override + public VirtualApplianceState getState() + { + throw new RuntimeException("This mock class always fails to get the state"); + } + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitorTest.java new file mode 100644 index 0000000000..2f0d08dbf3 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitorTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link VirtualMachineDeployMonitor} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineDeployMonitorTest") +public class VirtualMachineDeployMonitorTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = new VirtualMachineDeployMonitor(); + function.apply(null); + } + + public void testReturnDone() + { + VirtualMachineState[] states = {VirtualMachineState.ON}; + + checkStatesReturn(new MockVirtualMachine(), new VirtualMachineDeployMonitor(), states, + MonitorStatus.DONE); + } + + public void testReturnFail() + { + VirtualMachineState[] states = + {VirtualMachineState.NOT_ALLOCATED, VirtualMachineState.UNKNOWN}; + + checkStatesReturn(new MockVirtualMachine(), new VirtualMachineDeployMonitor(), states, + MonitorStatus.FAILED); + } + + public void testReturnContinue() + { + VirtualMachineState[] states = + {VirtualMachineState.ALLOCATED, VirtualMachineState.CONFIGURED, + VirtualMachineState.LOCKED, VirtualMachineState.OFF, VirtualMachineState.PAUSED}; + + checkStatesReturn(new MockVirtualMachine(), new VirtualMachineDeployMonitor(), states, + MonitorStatus.CONTINUE); + + checkStatesReturn(new MockVirtualMachineFailing(), new VirtualMachineDeployMonitor(), + states, MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockVirtualMachine vm, + final Function function, final VirtualMachineState[] states, + final MonitorStatus expectedStatus) + { + for (VirtualMachineState state : states) + { + vm.setState(state); + assertEquals(function.apply(vm), expectedStatus); + } + } + + private static class MockVirtualMachine extends VirtualMachine + { + private VirtualMachineState state; + + @SuppressWarnings("unchecked") + public MockVirtualMachine() + { + super(EasyMock.createMock(RestContext.class), new VirtualMachineWithNodeExtendedDto()); + } + + @Override + public VirtualMachineState getState() + { + return state; + } + + public void setState(final VirtualMachineState state) + { + this.state = state; + } + } + + private static class MockVirtualMachineFailing extends MockVirtualMachine + { + @Override + public VirtualMachineState getState() + { + throw new RuntimeException("This mock class always fails to get the state"); + } + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitorTest.java new file mode 100644 index 0000000000..0ec4307f2a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitorTest.java @@ -0,0 +1,120 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link VirtualMachineStateMonitor} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineStateMonitorTest") +public class VirtualMachineStateMonitorTest +{ + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullState() + { + new VirtualMachineStateMonitor(null); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = + new VirtualMachineStateMonitor(VirtualMachineState.ON); + function.apply(null); + } + + public void testReturnDone() + { + VirtualMachineState[] states = {VirtualMachineState.ON}; + + checkStatesReturn(new MockVirtualMachine(), + new VirtualMachineStateMonitor(VirtualMachineState.ON), states, MonitorStatus.DONE); + } + + public void testReturnContinue() + { + VirtualMachineState[] states = + {VirtualMachineState.ALLOCATED, VirtualMachineState.CONFIGURED, + VirtualMachineState.LOCKED, VirtualMachineState.OFF, VirtualMachineState.PAUSED, + VirtualMachineState.NOT_ALLOCATED, VirtualMachineState.UNKNOWN}; + + checkStatesReturn(new MockVirtualMachine(), + new VirtualMachineStateMonitor(VirtualMachineState.ON), states, MonitorStatus.CONTINUE); + + checkStatesReturn(new MockVirtualMachineFailing(), + new VirtualMachineStateMonitor(VirtualMachineState.ON), states, MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockVirtualMachine vm, + final Function function, final VirtualMachineState[] states, + final MonitorStatus expectedStatus) + { + for (VirtualMachineState state : states) + { + vm.setState(state); + assertEquals(function.apply(vm), expectedStatus); + } + } + + private static class MockVirtualMachine extends VirtualMachine + { + private VirtualMachineState state; + + @SuppressWarnings("unchecked") + public MockVirtualMachine() + { + super(EasyMock.createMock(RestContext.class), new VirtualMachineWithNodeExtendedDto()); + } + + @Override + public VirtualMachineState getState() + { + return state; + } + + public void setState(final VirtualMachineState state) + { + this.state = state; + } + } + + private static class MockVirtualMachineFailing extends MockVirtualMachine + { + @Override + public VirtualMachineState getState() + { + throw new RuntimeException("This mock class always fails to get the state"); + } + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitorTest.java new file mode 100644 index 0000000000..e5a2dba938 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitorTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.functions; + +import static org.testng.Assert.assertEquals; + +import org.easymock.EasyMock; +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.monitor.MonitorStatus; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.abiquo.server.core.cloud.VirtualMachineState; +import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; +import com.google.common.base.Function; + +/** + * Unit tests for the {@link VirtualMachineUndeployMonitor} function. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "VirtualMachineUndeployMonitorTest") +public class VirtualMachineUndeployMonitorTest +{ + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullArgument() + { + Function function = new VirtualMachineUndeployMonitor(); + function.apply(null); + } + + public void testReturnDone() + { + VirtualMachineState[] states = {VirtualMachineState.NOT_ALLOCATED}; + + checkStatesReturn(new MockVirtualMachine(), new VirtualMachineUndeployMonitor(), states, + MonitorStatus.DONE); + } + + public void testReturnFail() + { + VirtualMachineState[] states = + {VirtualMachineState.ON, VirtualMachineState.CONFIGURED, VirtualMachineState.OFF, + VirtualMachineState.PAUSED, VirtualMachineState.UNKNOWN}; + + checkStatesReturn(new MockVirtualMachine(), new VirtualMachineUndeployMonitor(), states, + MonitorStatus.FAILED); + } + + public void testReturnContinue() + { + VirtualMachineState[] states = {VirtualMachineState.ALLOCATED, VirtualMachineState.LOCKED}; + + checkStatesReturn(new MockVirtualMachine(), new VirtualMachineUndeployMonitor(), states, + MonitorStatus.CONTINUE); + + checkStatesReturn(new MockVirtualMachineFailing(), new VirtualMachineUndeployMonitor(), + states, MonitorStatus.CONTINUE); + } + + private void checkStatesReturn(final MockVirtualMachine vm, + final Function function, final VirtualMachineState[] states, + final MonitorStatus expectedStatus) + { + for (VirtualMachineState state : states) + { + vm.setState(state); + assertEquals(function.apply(vm), expectedStatus); + } + } + + private static class MockVirtualMachine extends VirtualMachine + { + private VirtualMachineState state; + + @SuppressWarnings("unchecked") + public MockVirtualMachine() + { + super(EasyMock.createMock(RestContext.class), new VirtualMachineWithNodeExtendedDto()); + } + + @Override + public VirtualMachineState getState() + { + return state; + } + + public void setState(final VirtualMachineState state) + { + this.state = state; + } + } + + private static class MockVirtualMachineFailing extends MockVirtualMachine + { + @Override + public VirtualMachineState getState() + { + throw new RuntimeException("This mock class always fails to get the state"); + } + + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitorTest.java new file mode 100644 index 0000000000..729148a220 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitorTest.java @@ -0,0 +1,44 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.internal.BaseInjectionTest; +import org.jclouds.abiquo.monitor.AsyncTaskMonitor; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseAsyncTaskMonitor} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseAsyncTaskMonitorTest") +public class BaseAsyncTaskMonitorTest extends BaseInjectionTest +{ + + public void testAllPropertiesInjected() + { + BaseAsyncTaskMonitor monitor = + (BaseAsyncTaskMonitor) injector.getInstance(AsyncTaskMonitor.class); + + assertNotNull(monitor.taskMonitor); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitorTest.java new file mode 100644 index 0000000000..eb8bf9f160 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitorTest.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.internal.BaseInjectionTest; +import org.jclouds.abiquo.monitor.VirtualApplianceMonitor; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseVirtualApplianceMonitor} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseVirtualApplianceMonitorTest") +public class BaseVirtualApplianceMonitorTest extends BaseInjectionTest +{ + + public void testAllPropertiesInjected() + { + BaseVirtualApplianceMonitor monitor = + (BaseVirtualApplianceMonitor) injector.getInstance(VirtualApplianceMonitor.class); + + assertNotNull(monitor.deployMonitor); + assertNotNull(monitor.undeployMonitor); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitorTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitorTest.java new file mode 100644 index 0000000000..a07d75b31a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitorTest.java @@ -0,0 +1,45 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.monitor.internal; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.abiquo.internal.BaseInjectionTest; +import org.jclouds.abiquo.monitor.VirtualMachineMonitor; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BaseVirtualMachineMonitor} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BaseVirtualMachineMonitorTest") +public class BaseVirtualMachineMonitorTest extends BaseInjectionTest +{ + + public void testAllPropertiesInjected() + { + BaseVirtualMachineMonitor monitor = + (BaseVirtualMachineMonitor) injector.getInstance(VirtualMachineMonitor.class); + + assertNotNull(monitor.deployMonitor); + assertNotNull(monitor.undeployMonitor); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/reference/AbiquoTestConstants.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/reference/AbiquoTestConstants.java new file mode 100644 index 0000000000..0a3fcf41e0 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/reference/AbiquoTestConstants.java @@ -0,0 +1,31 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.reference; + +/** + * Configuration constants and properties used in Abiquo tests. + * + * @author Ignasi Barrera + */ +public interface AbiquoTestConstants +{ + /** The prefix for test object names. */ + public static final String PREFIX = "JC-"; +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClientTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClientTest.java new file mode 100644 index 0000000000..fc49bb2125 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/rest/internal/AbiquoHttpAsyncClientTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.rest.internal; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.abiquo.features.BaseAbiquoAsyncApiTest; +import org.jclouds.functions.IdentityFunction; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.DatacentersDto; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code AbiquoHttpAsyncApi}. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "AbiquoHttpAsyncClientTest") +public class AbiquoHttpAsyncClientTest extends BaseAbiquoAsyncApiTest +{ + public void testGet() throws SecurityException, NoSuchMethodException, IOException + { + RESTLink link = new RESTLink("edit", "http://foo/bar"); + link.setType(DatacentersDto.BASE_MEDIA_TYPE); + + Method method = AbiquoHttpAsyncClient.class.getMethod("get", RESTLink.class); + GeneratedHttpRequest request = processor.createRequest(method, link); + + assertRequestLineEquals(request, "GET http://foo/bar HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersDto.BASE_MEDIA_TYPE + "\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, IdentityFunction.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() + { + return new TypeLiteral>() + { + }; + } + +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/BaseAbiquoStrategyLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/BaseAbiquoStrategyLiveApiTest.java new file mode 100644 index 0000000000..06d10f1c13 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/BaseAbiquoStrategyLiveApiTest.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy; + +import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; +import org.testng.annotations.BeforeClass; + +/** + * Base class for strategy live tests. + * + * @author Ignasi Barrera + */ +public abstract class BaseAbiquoStrategyLiveApiTest extends BaseAbiquoApiLiveApiTest +{ + @BeforeClass(groups = "api") + protected abstract void setupStrategy(); +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImplLiveApiTest.java new file mode 100644 index 0000000000..9e3ec7fd4a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/admin/internal/ListRolesImplLiveApiTest.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.admin.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.enterprise.Role; +import org.jclouds.abiquo.predicates.enterprise.RolePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListRolesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListRolesImplLiveApiTest") +public class ListRolesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListRolesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListRolesImpl.class); + } + + public void testExecute() + { + Iterable roles = strategy.execute(); + assertNotNull(roles); + assertTrue(size(roles) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable roles = strategy.execute(RolePredicates.name("UNEXISTING")); + assertNotNull(roles); + assertEquals(size(roles), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable roles = strategy.execute(RolePredicates.name(env.role.getName())); + assertNotNull(roles); + assertEquals(size(roles), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImplLiveApiTest.java new file mode 100644 index 0000000000..997a73da9a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListAttachedNicsImplLiveApiTest.java @@ -0,0 +1,114 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.network.ExternalIp; +import org.jclouds.abiquo.domain.network.Ip; +import org.jclouds.abiquo.domain.network.PrivateIp; +import org.jclouds.abiquo.domain.network.PublicIp; +import org.jclouds.abiquo.domain.network.UnmanagedNetwork; +import org.jclouds.abiquo.predicates.network.IpPredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.Lists; + +/** + * Live tests for the {@link ListAttachedNicsImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListAttachedNicsImplLiveApiTest") +public class ListAttachedNicsImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListAttachedNicsImpl strategy; + + private PrivateIp privateIp; + + private ExternalIp externalIp; + + private PublicIp publicIp; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = + env.context.getUtils().getInjector().getInstance(ListAttachedNicsImpl.class); + + privateIp = env.privateNetwork.listUnusedIps().get(0); + assertNotNull(privateIp); + + externalIp = env.externalNetwork.listUnusedIps().get(0); + assertNotNull(externalIp); + + publicIp = env.virtualDatacenter.listAvailablePublicIps().get(0); + env.virtualDatacenter.purchasePublicIp(publicIp); + publicIp = + env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(publicIp + .getIp())); + assertNotNull(publicIp); + + env.virtualMachine.setNics( + Lists.> newArrayList(privateIp, externalIp, publicIp), + Lists. newArrayList(env.unmanagedNetwork)); + } + + @AfterClass(groups = "api") + protected void tearDownStrategy() + { + env.virtualMachine.setNics(Lists.> newArrayList(privateIp)); + String address = publicIp.getIp(); + env.virtualDatacenter.releaseePublicIp(publicIp); + assertNull(env.virtualDatacenter.findPurchasedPublicIp(IpPredicates + . address(address))); + } + + public void testExecute() + { + Iterable> vapps = strategy.execute(env.virtualMachine); + assertNotNull(vapps); + assertTrue(size(vapps) == 4); + } + + public void testExecutePredicateWithoutResults() + { + Iterable> vapps = + strategy.execute(env.virtualMachine, IpPredicates.address("UNEXISTING")); + assertNotNull(vapps); + assertEquals(size(vapps), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable> vapps = + strategy.execute(env.virtualMachine, IpPredicates.address(publicIp.getIp())); + assertNotNull(vapps); + assertEquals(size(vapps), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImplLiveApiTest.java new file mode 100644 index 0000000000..faa063355c --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualAppliancesImplLiveApiTest.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.cloud.VirtualAppliance; +import org.jclouds.abiquo.predicates.cloud.VirtualAppliancePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListVirtualAppliancesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListVirtualAppliancesImplLiveApiTest") +public class ListVirtualAppliancesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListVirtualAppliancesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = + env.context.getUtils().getInjector().getInstance(ListVirtualAppliancesImpl.class); + } + + public void testExecute() + { + Iterable vapps = strategy.execute(); + assertNotNull(vapps); + assertTrue(size(vapps) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable vapps = + strategy.execute(VirtualAppliancePredicates.name("UNEXISTING")); + assertNotNull(vapps); + assertEquals(size(vapps), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable vapps = + strategy.execute(VirtualAppliancePredicates.name(env.virtualAppliance.getName())); + assertNotNull(vapps); + assertEquals(size(vapps), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImplLiveApiTest.java new file mode 100644 index 0000000000..21048f18ba --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualDatacentersImplLiveApiTest.java @@ -0,0 +1,93 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; +import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListVirtualDatacentersImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListVirtualDatacentersImplLiveApiTest") +public class ListVirtualDatacentersImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListVirtualDatacentersImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = + env.context.getUtils().getInjector().getInstance(ListVirtualDatacentersImpl.class); + } + + public void testExecute() + { + Iterable vdcs = strategy.execute(); + assertNotNull(vdcs); + assertTrue(size(vdcs) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable vdcs = + strategy.execute(VirtualDatacenterPredicates.name("UNEXISTING")); + assertNotNull(vdcs); + assertEquals(size(vdcs), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable vdcs = + strategy.execute(VirtualDatacenterPredicates.name(env.virtualDatacenter.getName())); + assertNotNull(vdcs); + assertEquals(size(vdcs), 1); + } + + public void testExecutePredicateOptionsWithResults() + { + Iterable vdcs = + strategy.execute(VirtualDatacenterOptions.builder() + .datacenterId(env.datacenter.getId()).enterpriseId(env.defaultEnterprise.getId()) + .build()); + assertNotNull(vdcs); + assertEquals(size(vdcs), 1); + } + + public void testExecutePredicateOptionsWithoutResults() + { + Iterable vdcs = + strategy.execute(VirtualDatacenterOptions.builder() + .enterpriseId(env.enterprise.getId()).build()); + assertNotNull(vdcs); + assertEquals(size(vdcs), 0); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImplLiveApiTest.java new file mode 100644 index 0000000000..c3e1afc936 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/internal/ListVirtualMachinesImplLiveApiTest.java @@ -0,0 +1,109 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.cloud.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.jclouds.abiquo.domain.cloud.VirtualMachine; +import org.jclouds.abiquo.predicates.cloud.VirtualMachinePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListVirtualMachinesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListVirtualMachinesImplLiveApiTest") +public class ListVirtualMachinesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListVirtualMachinesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = + env.context.getUtils().getInjector().getInstance(ListVirtualMachinesImpl.class); + } + + public void testExecute() + { + Iterable vms = strategy.execute(); + assertNotNull(vms); + assertTrue(size(vms) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable vms = + strategy.execute(VirtualMachinePredicates.internalName("UNEXISTING")); + assertNotNull(vms); + assertEquals(size(vms), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable vms = + strategy.execute(VirtualMachinePredicates.internalName(env.virtualMachine + .getInternalName())); + assertNotNull(vms); + assertEquals(size(vms), 1); + } + + public void testExecuteWhenExceedsPagination() + { + List vms = new ArrayList(); + + // Pagination by default is set to 25 items per page, so create a few more to verify that + // all are returned when listing + int numVms = 30; + + for (int i = 0; i < numVms; i++) + { + VirtualMachine vm = + VirtualMachine.Builder.fromVirtualMachine(env.virtualMachine).build(); + vm.save(); + vms.add(vm); + } + + try + { + Iterable all = strategy.execute(); + + assertNotNull(all); + assertTrue(size(all) >= numVms); + } + finally + { + for (VirtualMachine vm : vms) + { + vm.delete(); + } + } + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImplLiveApiTest.java new file mode 100644 index 0000000000..ca68a97c14 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListCategoriesImplLiveApiTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.config.Category; +import org.jclouds.abiquo.predicates.config.CategoryPredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicates; + +/** + * Live tests for the {@link ListPropertiesImpl} strategy. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "ListCategoriesImplLiveApiTest") +public class ListCategoriesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListCategoriesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListCategoriesImpl.class); + } + + public void testExecute() + { + Iterable categories = strategy.execute(); + assertNotNull(categories); + assertTrue(size(categories) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable categories = + strategy.execute(CategoryPredicates.name("Unexisting category")); + assertNotNull(categories); + assertEquals(size(categories), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable categories = + strategy.execute(CategoryPredicates.name("Applications servers")); + assertNotNull(categories); + assertEquals(size(categories), 1); + } + + public void testExecuteNotPredicateWithResults() + { + Iterable categories = + strategy.execute(Predicates.not(CategoryPredicates.name("Applications servers"))); + + Iterable allProperties = strategy.execute(); + + assertNotNull(categories); + assertNotNull(allProperties); + assertEquals(size(categories), size(allProperties) - 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImplLiveApiTest.java new file mode 100644 index 0000000000..d1e0676a3a --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListLicensesImplLiveApiTest.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.config.License; +import org.jclouds.abiquo.domain.config.options.LicenseOptions; +import org.jclouds.abiquo.predicates.config.LicensePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListLicenseImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListLicensesImplLiveApiTest") +public class ListLicensesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListLicensesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListLicensesImpl.class); + } + + public void testExecute() + { + Iterable licenses = strategy.execute(); + assertNotNull(licenses); + assertTrue(size(licenses) > 0); + } + + public void testExecuteInactive() + { + LicenseOptions options = LicenseOptions.builder().inactive(true).build(); + + Iterable licenses = strategy.execute(options); + assertNotNull(licenses); + assertTrue(size(licenses) == 1); + } + + public void testExecuteActive() + { + LicenseOptions options = LicenseOptions.builder().active(true).build(); + + Iterable licenses = strategy.execute(options); + assertNotNull(licenses); + assertTrue(size(licenses) >= 1); + } + + public void testExecutePredicateWithoutResults() + { + Iterable licenses = strategy.execute(LicensePredicates.customer("FAIL")); + assertNotNull(licenses); + assertEquals(size(licenses), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable licenses = + strategy.execute(LicensePredicates.code(env.license.getCode())); + assertNotNull(licenses); + assertEquals(size(licenses), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImplLiveApiTest.java new file mode 100644 index 0000000000..f379f6c6cf --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPrivilegesImplLiveApiTest.java @@ -0,0 +1,86 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.config.Privilege; +import org.jclouds.abiquo.predicates.config.PrivilegePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicates; + +/** + * Live tests for the {@link ListPrivilegesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListPrivilegesImplLiveApiTest") +public class ListPrivilegesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListPrivilegesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListPrivilegesImpl.class); + } + + public void testExecute() + { + Iterable privileges = strategy.execute(); + assertNotNull(privileges); + assertTrue(size(privileges) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable privileges = + strategy.execute(PrivilegePredicates.name("Destroy the universe")); + assertNotNull(privileges); + assertEquals(size(privileges), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable privileges = + strategy.execute(PrivilegePredicates.name("USERS_MANAGE_USERS")); + assertNotNull(privileges); + assertEquals(size(privileges), 1); + } + + public void testExecuteNotPredicateWithResults() + { + Iterable privileges = + strategy.execute(Predicates.not(PrivilegePredicates.name("USERS_MANAGE_USERS"))); + + Iterable allPrivileges = strategy.execute(); + + assertNotNull(privileges); + assertNotNull(allPrivileges); + assertEquals(size(privileges), size(allPrivileges) - 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImplLiveApiTest.java new file mode 100644 index 0000000000..26eb511490 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/config/internal/ListPropertiesImplLiveApiTest.java @@ -0,0 +1,99 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.config.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.config.SystemProperty; +import org.jclouds.abiquo.domain.config.options.PropertyOptions; +import org.jclouds.abiquo.predicates.config.SystemPropertyPredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicates; + +/** + * Live tests for the {@link ListPropertiesImpl} strategy. + * + * @author Ignasi Barrera + * @author Francesc Montserrat + */ +@Test(groups = "api", testName = "ListPropertiesImplLiveApiTest") +public class ListPropertiesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListPropertiesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListPropertiesImpl.class); + } + + public void testExecute() + { + Iterable properties = strategy.execute(); + assertNotNull(properties); + assertTrue(size(properties) > 0); + } + + public void testExecuteWithOptions() + { + PropertyOptions options = PropertyOptions.builder().component("client").build(); + + Iterable properties = strategy.execute(options); + assertNotNull(properties); + assertTrue(size(properties) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable properties = + strategy.execute(SystemPropertyPredicates.name("Cloud color")); + assertNotNull(properties); + assertEquals(size(properties), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable properties = + strategy.execute(SystemPropertyPredicates + .name("client.applibrary.ovfpackagesDownloadingProgressUpdateInterval")); + assertNotNull(properties); + assertEquals(size(properties), 1); + } + + public void testExecuteNotPredicateWithResults() + { + Iterable properties = + strategy.execute(Predicates.not(SystemPropertyPredicates + .name("client.applibrary.ovfpackagesDownloadingProgressUpdateInterval"))); + + Iterable allProperties = strategy.execute(); + + assertNotNull(properties); + assertNotNull(allProperties); + assertEquals(size(properties), size(allProperties) - 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImplLiveApiTest.java new file mode 100644 index 0000000000..6175710cbc --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListEnterprisesImplLiveApiTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.enterprise.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.enterprise.Enterprise; +import org.jclouds.abiquo.predicates.enterprise.EnterprisePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListEnterprisesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListEnterprisesImplLiveApiTest") +public class ListEnterprisesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListEnterprisesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListEnterprisesImpl.class); + } + + public void testExecute() + { + Iterable enterprises = strategy.execute(); + assertNotNull(enterprises); + assertTrue(size(enterprises) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable enterprises = + strategy.execute(EnterprisePredicates.name("UNEXISTING")); + assertNotNull(enterprises); + assertEquals(size(enterprises), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable enterprises = + strategy.execute(EnterprisePredicates.name(env.enterprise.getName())); + assertNotNull(enterprises); + assertEquals(size(enterprises), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImplLiveApiTest.java new file mode 100644 index 0000000000..3a8170977e --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/internal/ListVirtualMachineTemplatesImplLiveApiTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.enterprise.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +import org.jclouds.abiquo.predicates.cloud.VirtualMachineTemplatePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualAppliancesImpl; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListVirtualAppliancesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListVirtualMachineTemplatesImplLiveApiTest") +public class ListVirtualMachineTemplatesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListVirtualMachineTemplatesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = + env.context.getUtils().getInjector().getInstance(ListVirtualMachineTemplatesImpl.class); + } + + public void testExecute() + { + Iterable templates = strategy.execute(env.defaultEnterprise); + assertNotNull(templates); + assertTrue(size(templates) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable templates = + strategy.execute(env.defaultEnterprise, + VirtualMachineTemplatePredicates.name("UNEXISTING")); + assertNotNull(templates); + assertEquals(size(templates), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable templates = + strategy.execute(env.defaultEnterprise, + VirtualMachineTemplatePredicates.name(env.template.getName())); + assertNotNull(templates); + // Repository can have multiple templates with the same name + assertTrue(size(templates) > 0); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImplLiveApiTest.java new file mode 100644 index 0000000000..33aca3a096 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListDatacentersImplLiveApiTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.infrastructure.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.infrastructure.Datacenter; +import org.jclouds.abiquo.predicates.infrastructure.DatacenterPredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListDatacentersImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListDatacentersImplLiveApiTest") +public class ListDatacentersImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListDatacentersImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListDatacentersImpl.class); + } + + public void testExecute() + { + Iterable datacenters = strategy.execute(); + assertNotNull(datacenters); + assertTrue(size(datacenters) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable datacenters = + strategy.execute(DatacenterPredicates.name("UNEXISTING")); + assertNotNull(datacenters); + assertEquals(size(datacenters), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable datacenters = + strategy.execute(DatacenterPredicates.name(env.datacenter.getName())); + assertNotNull(datacenters); + assertEquals(size(datacenters), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImplLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImplLiveApiTest.java new file mode 100644 index 0000000000..206a15d29d --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/internal/ListMachinesImplLiveApiTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.strategy.infrastructure.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.abiquo.domain.infrastructure.Machine; +import org.jclouds.abiquo.predicates.infrastructure.MachinePredicates; +import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Live tests for the {@link ListMachinesImpl} strategy. + * + * @author Ignasi Barrera + */ +@Test(groups = "api", testName = "ListMachinesImplLiveApiTest") +public class ListMachinesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest +{ + private ListMachinesImpl strategy; + + @Override + @BeforeClass(groups = "api") + protected void setupStrategy() + { + this.strategy = env.context.getUtils().getInjector().getInstance(ListMachinesImpl.class); + } + + public void testExecute() + { + Iterable machines = strategy.execute(); + assertNotNull(machines); + assertTrue(size(machines) > 0); + } + + public void testExecutePredicateWithoutResults() + { + Iterable machines = strategy.execute(MachinePredicates.name("UNEXISTING")); + assertNotNull(machines); + assertEquals(size(machines), 0); + } + + public void testExecutePredicateWithResults() + { + Iterable machines = + strategy.execute(MachinePredicates.name(env.machine.getName())); + assertNotNull(machines); + assertEquals(size(machines), 1); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/util/Assert.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/util/Assert.java new file mode 100644 index 0000000000..e2914fb986 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/util/Assert.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.util; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.io.IOException; + +import javax.ws.rs.core.Response.Status; + +import org.jclouds.abiquo.domain.exception.AbiquoException; +import org.jclouds.io.Payload; +import org.jclouds.xml.XMLParser; +import org.jclouds.xml.internal.JAXBParser; + +import com.abiquo.model.transport.SingleResourceTransportDto; +import com.abiquo.model.transport.error.ErrorDto; + +/** + * Assertion utilities. + * + * @author Ignasi Barrera + */ +public class Assert +{ + /** + * Assert that the exception contains the given error. + * + * @param exception The exception. + * @param expectedHttpStatus The expected HTTP status code. + * @param expectedErrorCode The expected error code. + */ + public static void assertHasError(final AbiquoException exception, + final Status expectedHttpStatus, final String expectedErrorCode) + { + assertEquals(exception.getHttpStatus(), expectedHttpStatus); + ErrorDto error = exception.findError(expectedErrorCode); + assertNotNull(error); + } + + /** + * Assert that the given payload matches the given string. + * + * @param payload The payload to check. + * @param expected The expected string. + * @param entityClass The entity class for the payload. + * @throws IOException If there is an error during serialization. + */ + public static void assertPayloadEquals(final Payload payload, final String expected, + final Class< ? extends SingleResourceTransportDto> entityClass) throws IOException + { + // Serialize and deserialize to avoid formatting issues + XMLParser xml = new JAXBParser("false"); + SingleResourceTransportDto entity = xml.fromXML(expected, entityClass); + String toMatch = xml.toXML(entity, entityClass); + + assertEquals(payload.getRawContent(), toMatch); + } +} diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/util/Config.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/util/Config.java new file mode 100644 index 0000000000..4b438aa464 --- /dev/null +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/util/Config.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.abiquo.util; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.IOException; +import java.util.Properties; + +/** + * Test configuration. + * + * @author Ignasi Barrera + */ +public class Config +{ + /** The main configuration file. */ + private static final String CONFIG_FILE = "api-live.properties"; + + /** The configuration properties */ + private Properties config; + + /** The singleton configuration instance. */ + private static Config instance; + + public Config(final String config) + { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + this.config = new Properties(); + + try + { + this.config.load(cl.getResourceAsStream(config)); + } + catch (IOException ex) + { + throw new RuntimeException("Could not load test configuration file", ex); + } + } + + public Config(final Properties config) + { + this.config = config; + } + + public static String get(final String property) + { + return get(property, null); + } + + public static String get(final String property, final String defaultValue) + { + if (instance == null) + { + String configFile = System.getProperty("abiquo.live.config", CONFIG_FILE); + instance = new Config(configFile); + } + + return checkNotNull(instance.config.getProperty(property, defaultValue)); + } + +} diff --git a/labs/abiquo/src/test/resources/api-live.properties b/labs/abiquo/src/test/resources/api-live.properties new file mode 100644 index 0000000000..a452389f85 --- /dev/null +++ b/labs/abiquo/src/test/resources/api-live.properties @@ -0,0 +1,20 @@ +# Hypervisor configuration +abiquo.hypervisor.type = ${abiquo.hypervisor.type} +abiquo.hypervisor.address = ${abiquo.hypervisor.address} +abiquo.hypervisor.user = ${abiquo.hypervisor.user} +abiquo.hypervisor.pass = ${abiquo.hypervisor.pass} +abiquo.hypervisor.vswitch = ${abiquo.hypervisor.vswitch} +abiquo.hypervisor.datastore = ${abiquo.hypervisor.datastore} + +# Storage configuration +abiquo.storage.type = ${abiquo.storage.type} +abiquo.storage.address = ${abiquo.storage.address} +abiquo.storage.pass = ${abiquo.storage.pass} +abiquo.storage.user = ${abiquo.storage.user} +abiquo.storage.pool = ${abiquo.storage.pool} + +# UCS Rack configuration +abiquo.ucs.address = ${abiquo.ucs.address} +abiquo.ucs.port = ${abiquo.ucs.port} +abiquo.ucs.pass = ${abiquo.ucs.pass} +abiquo.ucs.user = ${abiquo.ucs.user} diff --git a/labs/abiquo/src/test/resources/filters/filters.properties b/labs/abiquo/src/test/resources/filters/filters.properties new file mode 100644 index 0000000000..8f434a8b80 --- /dev/null +++ b/labs/abiquo/src/test/resources/filters/filters.properties @@ -0,0 +1,26 @@ +# Hypervisor configuration +# This is the Tarantino IT hypervisor. +# Should be replaced with a dedicated ESX asap! + +#abiquo.hypervisor.pass=tarantino +#abiquo.hypervisor.address=10.60.1.132 +#abiquo.hypervisor.datastore=nfs-ds +abiquo.hypervisor.type=VMX_04 +abiquo.hypervisor.address=10.60.20.62 +abiquo.hypervisor.pass=temporal +abiquo.hypervisor.user=root +abiquo.hypervisor.vswitch=vSwitch0 +abiquo.hypervisor.datastore=datastore1 + +# Storage configuration +abiquo.storage.type=LVM +abiquo.storage.address=10.60.12.177 +#abiquo.storage.user= +#abiquo.storage.pass= +abiquo.storage.pool=abiquo + +# UCS Rack configuration +abiquo.ucs.address=10.60.1.45 +abiquo.ucs.port=80 +abiquo.ucs.pass=config +abiquo.ucs.user=config \ No newline at end of file diff --git a/labs/abiquo/src/test/resources/filters/filters_jenkins.properties b/labs/abiquo/src/test/resources/filters/filters_jenkins.properties new file mode 100644 index 0000000000..071d53b99a --- /dev/null +++ b/labs/abiquo/src/test/resources/filters/filters_jenkins.properties @@ -0,0 +1,26 @@ +# Hypervisor configuration +# This is the Tarantino IT hypervisor. +# Should be replaced with a dedicated ESX asap! +#abiquo.hypervisor.pass=tarantino +#abiquo.hypervisor.address=10.60.1.132 +#abiquo.hypervisor.datastore=nfs-ds +abiquo.hypervisor.type=VMX_04 +abiquo.hypervisor.address=10.60.20.62 +abiquo.hypervisor.pass=temporal +abiquo.hypervisor.user=root +abiquo.hypervisor.vswitch=vSwitch0 +abiquo.hypervisor.datastore=datastore1 + + +# Storage configuration +abiquo.storage.type=NEXENTA +abiquo.storage.address=10.60.20.23 +abiquo.storage.user=admin +abiquo.storage.pass=nexenta +abiquo.storage.pool=abiquo + +# UCS Rack configuration +abiquo.ucs.address=10.60.1.45 +abiquo.ucs.port=80 +abiquo.ucs.pass=config +abiquo.ucs.user=config \ No newline at end of file diff --git a/labs/abiquo/src/test/resources/license/expired b/labs/abiquo/src/test/resources/license/expired new file mode 100644 index 0000000000..1db9f513ae --- /dev/null +++ b/labs/abiquo/src/test/resources/license/expired @@ -0,0 +1 @@ +B9cG06GaLHhUlpD9AWxKVkZPd4qPB0OAbm2Blr4374Y6rtPhcukg4MMLNK0uWn5fnsoBSqVX8o0hwQ1I6D3zUbFBSibMaK5xIZQfZmReHf04HPPBg0ZyaPRTBoKy6dCLnWpQIKe8vLemAudZ0w4spdzYMH2jw2TImN+2vd4QDU1qmUItYMsV5Sz+e8YVEGbUVkjRjQCmIUJskVxC+sW47dokgl5Qo8hN+4I6vKgEnXFdOSRFW2cyGgpHVH4Js4hwLG+PS2LXPS4UwvISJXRF6tO7Rgg9iaObcBD/byH5jGmggtSECUtXqI70nesIbMXRHQ1aGHARqbHH3+0Znjcu5g== \ No newline at end of file diff --git a/labs/abiquo/src/test/resources/logback-test.xml b/labs/abiquo/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..70a88e8ba3 --- /dev/null +++ b/labs/abiquo/src/test/resources/logback-test.xml @@ -0,0 +1,94 @@ + + + + target/test-data/jclouds-headers.log + true + + TRACE + + + %date %level [%logger] \(%thread\) %msg%n + + + + target/test-data/jclouds-headers.log.%d + 5 + + + + target/test-data/jclouds-payloads.log + true + + TRACE + + + %date %level [%logger] \(%thread\) %msg%n + + + + target/test-data/jclouds-payloads.log.%d + 5 + + + + target/test-data/jclouds-compute.log + true + + TRACE + + + %date %level [%logger] \(%thread\) %msg%n + + + + target/test-data/jclouds-compute.log.%d + 5 + + + + target/test-data/jclouds.log + true + + TRACE + + + %date %level [%logger] \(%thread\) %msg%n + + + + target/test-data/jclouds.log.%d + 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/labs/pom.xml b/labs/pom.xml index 0ddb6ed9e2..cbc392b9f6 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -61,5 +61,6 @@ fgcp fgcp-au fgcp-de + abiquo From e43f16ff5d7b5c1dd6da4a988cf9a81d7dd53341 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Fri, 7 Sep 2012 12:56:46 +0200 Subject: [PATCH 02/60] Pom fixes and cleanup, properties convention and other fixes commented in the pull-request --- labs/abiquo/NOTICE | 6 ++++- labs/abiquo/pom.xml | 27 +++---------------- .../org/jclouds/abiquo/AbiquoApiMetadata.java | 4 +-- .../AbiquoComputeServiceContextModule.java | 1 - .../{reference => config}/AbiquoEdition.java | 2 +- .../AbiquoProperties.java} | 6 ++--- .../domain/infrastructure/Datacenter.java | 2 +- .../http/filters/AbiquoAuthentication.java | 2 +- .../internal/BaseMonitoringService.java | 4 +-- .../internal/BaseAsyncTaskMonitor.java | 4 +-- .../internal/BaseConversionMonitor.java | 4 +-- .../internal/BaseVirtualApplianceMonitor.java | 4 +-- .../internal/BaseVirtualMachineMonitor.java | 4 +-- .../compute/AbiquoComputeServiceLiveTest.java | 4 +-- .../VirtualMachineTemplateLiveApiTest.java | 6 ----- .../InfrastructureTestEnvironment.java | 2 +- .../AbiquoAuthenticationLiveApiTest.java | 6 ++--- .../internal/BaseMonitoringServiceTest.java | 2 +- 18 files changed, 34 insertions(+), 56 deletions(-) rename labs/abiquo/src/main/java/org/jclouds/abiquo/{reference => config}/AbiquoEdition.java (96%) rename labs/abiquo/src/main/java/org/jclouds/abiquo/{reference/AbiquoConstants.java => config/AbiquoProperties.java} (90%) diff --git a/labs/abiquo/NOTICE b/labs/abiquo/NOTICE index 7e867501e1..bf10c4168b 100644 --- a/labs/abiquo/NOTICE +++ b/labs/abiquo/NOTICE @@ -22,4 +22,8 @@ Copyright 2009-2011 jclouds, Inc. This product includes software developed at Abiquo Holdings S.L. (http://www.abiquo.com/). -distributed under the GNU Lesser General Public License version 3 + +The following Abiquo dependencies are distributed under +the GNU Lesser General Public License version 3: + com.abiquo:api-model-transport + com.abiquo:am-model diff --git a/labs/abiquo/pom.xml b/labs/abiquo/pom.xml index 453f52fa22..9eab759b7b 100644 --- a/labs/abiquo/pom.xml +++ b/labs/abiquo/pom.xml @@ -16,8 +16,9 @@ 2.1-SNAPSHOT - - + http://localhost/api + FIXME + FIXME org.jclouds.abiquo*;version="${project.version}" @@ -112,7 +113,7 @@ org.jclouds.driver - jclouds-jsch + jclouds-sshj ${project.version} test @@ -122,12 +123,6 @@ ${project.version} test - - org.slf4j - slf4j-api - 1.6.1 - test - ch.qos.logback logback-core @@ -140,20 +135,6 @@ 1.0.0 test - diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java index ef1c5d5087..78fd985237 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApiMetadata.java @@ -20,8 +20,8 @@ package org.jclouds.abiquo; import static org.jclouds.Constants.PROPERTY_MAX_REDIRECTS; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; -import static org.jclouds.abiquo.reference.AbiquoConstants.CREDENTIAL_IS_TOKEN; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.CREDENTIAL_IS_TOKEN; import java.net.URI; import java.util.Properties; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java index fc86f99409..4007b0afd6 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java @@ -30,7 +30,6 @@ import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.config.ComputeServiceAdapterContextModule; -import org.jclouds.compute.config.ComputeServiceAdapterContextModule.LocationsFromComputeServiceAdapterModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoEdition.java similarity index 96% rename from labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java rename to labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoEdition.java index a3d685dbea..c7c88f1630 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoEdition.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoEdition.java @@ -17,7 +17,7 @@ * under the License. */ -package org.jclouds.abiquo.reference; +package org.jclouds.abiquo.config; /** * The Abiquo Edition (Community or Enterprise). diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java similarity index 90% rename from labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java rename to labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java index ac560edb9c..bf98bc50ec 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/reference/AbiquoConstants.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java @@ -17,16 +17,16 @@ * under the License. */ -package org.jclouds.abiquo.reference; +package org.jclouds.abiquo.config; import org.jclouds.abiquo.features.services.MonitoringService; /** - * Global constants used in the Abiquo provider. + * Configuration properties and constants used in Abiquo connections. * * @author Ignasi Barrera */ -public interface AbiquoConstants +public interface AbiquoProperties { /** * Boolean property indicating if the provided credential is an api token. diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java index 0894ba2840..80ef2e8af8 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java @@ -25,6 +25,7 @@ import java.util.List; import org.jclouds.abiquo.AbiquoApi; import org.jclouds.abiquo.AbiquoAsyncApi; +import org.jclouds.abiquo.config.AbiquoEdition; import org.jclouds.abiquo.domain.DomainWrapper; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.enterprise.Enterprise; @@ -34,7 +35,6 @@ import org.jclouds.abiquo.domain.infrastructure.options.IpmiOptions; import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; import org.jclouds.abiquo.domain.network.Network; import org.jclouds.abiquo.domain.network.options.NetworkOptions; -import org.jclouds.abiquo.reference.AbiquoEdition; import org.jclouds.abiquo.reference.annotations.EnterpriseEdition; import org.jclouds.rest.RestContext; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java index 4be0049037..f3a462ec1d 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/http/filters/AbiquoAuthentication.java @@ -20,7 +20,7 @@ package org.jclouds.abiquo.http.filters; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.abiquo.reference.AbiquoConstants.CREDENTIAL_IS_TOKEN; +import static org.jclouds.abiquo.config.AbiquoProperties.CREDENTIAL_IS_TOKEN; import java.io.UnsupportedEncodingException; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java index cd38b8e64f..8d850efb7e 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java @@ -21,7 +21,7 @@ package org.jclouds.abiquo.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; @@ -31,8 +31,8 @@ import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.events.handlers.AbstractEventHandler; import org.jclouds.abiquo.events.handlers.BlockingEventHandler; import org.jclouds.abiquo.events.monitor.CompletedEvent; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java index 00cb30a264..f6e88c00e9 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java @@ -21,7 +21,7 @@ package org.jclouds.abiquo.monitor.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -30,8 +30,8 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.domain.task.AsyncTask; import org.jclouds.abiquo.internal.BaseMonitoringService; import org.jclouds.abiquo.monitor.AsyncTaskMonitor; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java index a31ed41db5..b30be3a666 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java @@ -21,7 +21,7 @@ package org.jclouds.abiquo.monitor.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -30,8 +30,8 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.domain.cloud.Conversion; import org.jclouds.abiquo.internal.BaseMonitoringService; import org.jclouds.abiquo.monitor.ConversionMonitor; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java index a561352aaa..a1948dc7dc 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java @@ -21,7 +21,7 @@ package org.jclouds.abiquo.monitor.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -30,8 +30,8 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.domain.cloud.VirtualAppliance; import org.jclouds.abiquo.internal.BaseMonitoringService; import org.jclouds.abiquo.monitor.VirtualApplianceMonitor; diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java index 1cc6e0cb35..aa7df1820f 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java @@ -21,7 +21,7 @@ package org.jclouds.abiquo.monitor.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -30,8 +30,8 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.domain.cloud.VirtualMachine; import org.jclouds.abiquo.internal.BaseMonitoringService; import org.jclouds.abiquo.monitor.VirtualMachineMonitor; diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java index 2f016a123c..48d1f31797 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java @@ -32,7 +32,7 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.logging.config.LoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -89,7 +89,7 @@ public class AbiquoComputeServiceLiveTest extends BaseComputeServiceLiveTest @Override protected Module getSshModule() { - return new JschSshClientModule(); + return new SshjSshClientModule(); } @Override diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java index b9be919742..7391cf5421 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplateLiveApiTest.java @@ -54,12 +54,6 @@ public class VirtualMachineTemplateLiveApiTest extends BaseAbiquoApiLiveApiTest assertNotNull(category); } - public void testGetIcon() - { - String iconUrl = env.virtualMachine.getTemplate().getIconUrl(); - assertNotNull(iconUrl); - } - public void testRequestConversionToSameFormat() { try diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java index ead8ac5ead..17d9db6efa 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.UUID; import org.jclouds.abiquo.AbiquoContext; +import org.jclouds.abiquo.config.AbiquoEdition; import org.jclouds.abiquo.domain.config.License; import org.jclouds.abiquo.domain.enterprise.Enterprise; import org.jclouds.abiquo.domain.enterprise.Limits; @@ -62,7 +63,6 @@ import org.jclouds.abiquo.predicates.infrastructure.RemoteServicePredicates; import org.jclouds.abiquo.predicates.infrastructure.StorageDeviceMetadataPredicates; import org.jclouds.abiquo.predicates.infrastructure.StoragePoolPredicates; import org.jclouds.abiquo.predicates.infrastructure.TierPredicates; -import org.jclouds.abiquo.reference.AbiquoEdition; import org.jclouds.abiquo.util.Config; import com.abiquo.model.enumerator.HypervisorType; diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java index baf418593c..e63697c64a 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/http/filters/AbiquoAuthenticationLiveApiTest.java @@ -38,7 +38,7 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.ContextBuilder; import org.jclouds.abiquo.AbiquoApiMetadata; import org.jclouds.abiquo.AbiquoContext; -import org.jclouds.abiquo.reference.AbiquoConstants; +import org.jclouds.abiquo.config.AbiquoProperties; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; @@ -79,7 +79,7 @@ public class AbiquoAuthenticationLiveApiTest String token = getAuthtenticationToken(); Properties props = new Properties(); - props.setProperty(AbiquoConstants.CREDENTIAL_IS_TOKEN, "true"); + props.setProperty(AbiquoProperties.CREDENTIAL_IS_TOKEN, "true"); // Create a new context that uses the generated token to perform the API calls AbiquoContext tokenContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // @@ -111,7 +111,7 @@ public class AbiquoAuthenticationLiveApiTest String token = getAuthtenticationToken() + "INVALID"; Properties props = new Properties(); - props.setProperty(AbiquoConstants.CREDENTIAL_IS_TOKEN, "true"); + props.setProperty(AbiquoProperties.CREDENTIAL_IS_TOKEN, "true"); // Create a new context that uses the generated token to perform the API calls AbiquoContext tokenContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java index 9d7ca5520b..6d58677094 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseMonitoringServiceTest.java @@ -19,7 +19,7 @@ package org.jclouds.abiquo.internal; -import static org.jclouds.abiquo.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY; +import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; From b5580155159321a726234e9f478d6fdfd962af66 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 9 Sep 2012 15:37:36 -0700 Subject: [PATCH 03/60] increased container count for cloudfiles-us tests --- providers/cloudfiles-us/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/providers/cloudfiles-us/pom.xml b/providers/cloudfiles-us/pom.xml index 3bf2dfaba6..42712424ca 100644 --- a/providers/cloudfiles-us/pom.xml +++ b/providers/cloudfiles-us/pom.xml @@ -35,6 +35,7 @@ org.jclouds.rackspace.cloudfiles.blobstore.integration.CloudFilesUSTestInitializer + 15 https://auth.api.rackspacecloud.com 1.0 @@ -112,6 +113,7 @@ 1 + ${test.blobstore.container-count} ${test.cloudfiles-us.endpoint} ${test.cloudfiles-us.api-version} ${test.cloudfiles-us.build-version} From 49bde19fa05bee1486871cb0d909066806095dd0 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Mon, 10 Sep 2012 02:12:42 +0300 Subject: [PATCH 04/60] Add support for Swift TempURL Middleware --- .../blobstore/AtmosBlobRequestSigner.java | 10 ++ apis/cloudfiles/pom.xml | 5 + .../cloudfiles/CloudFilesAsyncClient.java | 18 ++- .../jclouds/cloudfiles/CloudFilesClient.java | 24 +++- .../jclouds/cloudfiles/TemporaryUrlKey.java | 37 ++++++ .../CloudFilesBlobRequestSigner.java | 124 ++++++++++++++++++ .../CloudFilesBlobStoreContextModule.java | 25 +++- .../ParseTemporaryUrlKeyFromHeaders.java | 36 +++++ .../reference/CloudFilesHeaders.java | 2 + .../cloudfiles/CloudFilesClientTest.java | 72 ++++++++++ .../blobstore/CloudFilesBlobSignerTest.java | 83 ++++++++++++ .../integration/CloudFilesBlobLiveTest.java | 27 +++- .../CloudFilesBlobSignerLiveTest.java | 68 +++++++++- .../s3/blobstore/S3BlobRequestSigner.java | 10 ++ .../blobstore/SwiftBlobRequestSigner.java | 17 ++- .../config/SwiftBlobStoreContextModule.java | 8 +- .../swift/CommonSwiftClientTest.java | 1 + .../blobstore/SwiftBlobRequestSignerTest.java | 1 + .../integration/SwiftBlobSignerLiveTest.java | 5 +- .../jclouds/blobstore/BlobRequestSigner.java | 21 +++ .../blobstore/TransientBlobRequestSigner.java | 10 ++ .../internal/RequestSigningUnsupported.java | 14 +- .../blobstore/AzureBlobRequestSigner.java | 10 ++ ...HPCloudObjectStorageBlobRequestSigner.java | 12 +- 24 files changed, 619 insertions(+), 21 deletions(-) create mode 100644 apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java create mode 100644 apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java create mode 100644 apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java create mode 100644 apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java create mode 100644 apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java index 0fe231f79b..1d211bc4da 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java @@ -67,11 +67,21 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(getMethod, getPath(container, name))); } + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signPutBlob(String container, Blob blob) { return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); } + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signRemoveBlob(String container, String name) { return cleanRequest(processor.createRequest(deleteMethod, getPath(container, name))); diff --git a/apis/cloudfiles/pom.xml b/apis/cloudfiles/pom.xml index 708148679c..a067095c2e 100644 --- a/apis/cloudfiles/pom.xml +++ b/apis/cloudfiles/pom.xml @@ -53,6 +53,11 @@ swift ${project.version} + + org.jclouds.driver + jclouds-joda + ${project.version} + org.jclouds jclouds-core diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java index 14e3b28f5f..9b73ad6971 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java @@ -36,6 +36,7 @@ import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.cloudfiles.functions.ParseCdnUriFromHeaders; import org.jclouds.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders; +import org.jclouds.cloudfiles.functions.ParseTemporaryUrlKeyFromHeaders; import org.jclouds.cloudfiles.options.ListCdnContainerOptions; import org.jclouds.cloudfiles.reference.CloudFilesHeaders; import org.jclouds.openstack.filters.AuthenticateRequest; @@ -57,7 +58,7 @@ import com.google.common.util.concurrent.ListenableFuture; * All commands return a ListenableFuture of the result from Cloud Files. Any exceptions incurred * during processing will be backend in an {@link ExecutionException} as documented in * {@link ListenableFuture#get()}. - * + * * @see CloudFilesClient * @see * @author Adrian Cole @@ -130,4 +131,19 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { @Endpoint(CDNManagement.class) ListenableFuture disableCDN(@PathParam("container") String container); + + /** + * @see CloudFilesClient#getTemporaryUrlKey + */ + @HEAD + @Path("/") + @ResponseParser(ParseTemporaryUrlKeyFromHeaders.class) + ListenableFuture getTemporaryUrlKey(); + + /** + * @see CloudFilesClient#setTemporaryUrlKey + */ + @POST + @Path("/") + ListenableFuture setTemporaryUrlKey(@HeaderParam(CloudFilesHeaders.ACCOUNT_TEMPORARY_URL_KEY) String key); } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java index e74ca1ec54..f52d7b8ad8 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java @@ -34,9 +34,9 @@ import org.jclouds.openstack.swift.CommonSwiftClient; *

* All commands return a Future of the result from Cloud Files. Any exceptions incurred during * processing will be backend in an {@link ExecutionException} as documented in {@link Future#get()}. - * - * @see + * * @author Adrian Cole + * @see */ @Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) public interface CloudFilesClient extends CommonSwiftClient { @@ -52,4 +52,24 @@ public interface CloudFilesClient extends CommonSwiftClient { boolean disableCDN(String container); + /** + * Retrieve the key used to generate Temporary object access URLs + * + * @see + * @return shared secret key + */ + String getTemporaryUrlKey(); + + /** + * To create a Temporary URL you must first set a key as account metadata. + * + * Once the key is set, you should not change it while you still want others to be + * able to access your temporary URL. If you change it, the TempURL becomes invalid + * (within 60 seconds, which is the cache time for a key) and others will not be allowed + * to access it. + * + * @see + * @param temporaryUrlKey + */ + void setTemporaryUrlKey(String temporaryUrlKey); } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java new file mode 100644 index 0000000000..15b7d43e1c --- /dev/null +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudfiles; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Represents the key used for signing URLs that have temporary access to objects + * + * @see + * @author Andrei Savu + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface TemporaryUrlKey { +} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java new file mode 100644 index 0000000000..b6b9d7136a --- /dev/null +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java @@ -0,0 +1,124 @@ +package org.jclouds.cloudfiles.blobstore; + +import com.google.common.base.Throwables; +import com.google.inject.Provider; +import org.jclouds.blobstore.BlobRequestSigner; +import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.cloudfiles.CloudFilesAsyncClient; +import org.jclouds.cloudfiles.TemporaryUrlKey; +import org.jclouds.crypto.Crypto; +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.date.TimeStamp; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.options.GetOptions; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; +import org.jclouds.openstack.swift.domain.SwiftObject; +import org.jclouds.rest.internal.RestAnnotationProcessor; + +import javax.inject.Inject; +import java.lang.reflect.Method; +import java.security.InvalidKeyException; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.instanceOf; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.blobstore.util.BlobStoreUtils.cleanRequest; + +public class CloudFilesBlobRequestSigner implements BlobRequestSigner { + + private final RestAnnotationProcessor processor; + private final Crypto crypto; + + private final Provider unixEpochTimestampProvider; + private final Provider temporaryUrlKeyProvider; + + private final BlobToObject blobToObject; + private final BlobToHttpGetOptions blob2HttpGetOptions; + + private final Method getMethod; + private final Method deleteMethod; + private final Method createMethod; + + @Inject + public CloudFilesBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, + BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, + @TimeStamp Provider unixEpochTimestampProvider, + @TemporaryUrlKey Provider temporaryUrlKeyProvider) throws SecurityException, NoSuchMethodException { + this.processor = checkNotNull(processor, "processor"); + this.crypto = checkNotNull(crypto, "crypto"); + + this.unixEpochTimestampProvider = checkNotNull(unixEpochTimestampProvider, "unixEpochTimestampProvider"); + this.temporaryUrlKeyProvider = checkNotNull(temporaryUrlKeyProvider, "temporaryUrlKeyProvider"); + + this.blobToObject = checkNotNull(blobToObject, "blobToObject"); + this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); + + this.getMethod = CloudFilesAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); + this.deleteMethod = CloudFilesAsyncClient.class.getMethod("removeObject", String.class, String.class); + this.createMethod = CloudFilesAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); + } + + @Override + public HttpRequest signGetBlob(String container, String name) { + return cleanRequest(processor.createRequest(getMethod, container, name)); + } + + @Override + public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { + return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); + } + + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + HttpRequest request = processor.createRequest(getMethod, container, name); + return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); + } + + @Override + public HttpRequest signPutBlob(String container, Blob blob) { + return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); + } + + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + HttpRequest request = processor.createRequest(createMethod, container, blobToObject.apply(blob)); + return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); + } + + @Override + public HttpRequest signRemoveBlob(String container, String name) { + return cleanRequest(processor.createRequest(deleteMethod, container, name)); + } + + private HttpRequest signForTemporaryAccess(HttpRequest request, long timeInSeconds) { + HttpRequest.Builder builder = request.toBuilder(); + builder.filters(filter(request.getFilters(), instanceOf(AuthenticateRequest.class))); + + String key = temporaryUrlKeyProvider.get(); + long expiresInSeconds = unixEpochTimestampProvider.get() + timeInSeconds; + + builder.addQueryParam("temp_url_sig", createSignature(key, createStringToSign( + request.getMethod().toUpperCase(), request, expiresInSeconds))); + builder.addQueryParam("temp_url_expires", "" + expiresInSeconds); + + return builder.build(); + } + + private String createStringToSign(String method, HttpRequest request, long expiresInSeconds) { + checkArgument(method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("PUT")); + return String.format("%s\n%d\n%s", method.toUpperCase(), expiresInSeconds, + request.getEndpoint().getPath()); + } + + private String createSignature(String key, String stringToSign) { + try { + return CryptoStreams.hex(crypto.hmacSHA1(key.getBytes()).doFinal(stringToSign.getBytes())); + + } catch (InvalidKeyException e) { + throw Throwables.propagate(e); + } + } +} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java index c9b64d196a..2c4b8f1544 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java @@ -23,11 +23,15 @@ import java.util.concurrent.TimeUnit; import javax.inject.Singleton; +import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.cloudfiles.CloudFilesClient; +import org.jclouds.cloudfiles.TemporaryUrlKey; import org.jclouds.cloudfiles.blobstore.CloudFilesAsyncBlobStore; +import org.jclouds.cloudfiles.blobstore.CloudFilesBlobRequestSigner; import org.jclouds.cloudfiles.blobstore.CloudFilesBlobStore; import org.jclouds.cloudfiles.blobstore.functions.CloudFilesObjectToBlobMetadata; import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; +import org.jclouds.date.TimeStamp; import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; @@ -37,9 +41,11 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.inject.Provides; +import org.jclouds.rest.HttpClient; +import org.jclouds.rest.RequestSigner; +import org.joda.time.Instant; /** - * * @author Adrian Cole */ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModule { @@ -61,6 +67,18 @@ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModul }); } + @Provides + @TimeStamp + protected Long unixEpochTimestampProvider() { + return Instant.now().getMillis() / 1000; /* in seconds */ + } + + @Provides + @TemporaryUrlKey + protected String temporaryUrlKeyProvider(CloudFilesClient client) { + return client.getTemporaryUrlKey(); + } + @Override protected void configure() { super.configure(); @@ -68,4 +86,9 @@ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModul bind(SwiftAsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class); bind(ObjectToBlobMetadata.class).to(CloudFilesObjectToBlobMetadata.class); } + + @Override + protected void configureRequestSigner() { + bind(BlobRequestSigner.class).to(CloudFilesBlobRequestSigner.class); + } } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java new file mode 100644 index 0000000000..fc360aaccf --- /dev/null +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudfiles.functions; + +import com.google.common.base.Function; +import org.jclouds.http.HttpResponse; + +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.ACCOUNT_TEMPORARY_URL_KEY; + +/** + * @author Andrei Savu + */ +public class ParseTemporaryUrlKeyFromHeaders implements Function { + + @Override + public String apply(HttpResponse httpResponse) { + return getOnlyElement(httpResponse.getHeaders().get(ACCOUNT_TEMPORARY_URL_KEY)); + } +} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java index 696398f395..377a79f4ea 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java @@ -30,6 +30,8 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders; */ public interface CloudFilesHeaders extends SwiftHeaders { + public static final String ACCOUNT_TEMPORARY_URL_KEY = "X-Account-Meta-Temp-Url-Key"; + public static final String CDN_ENABLED = "X-CDN-Enabled"; public static final String CDN_REFERRER_ACL = "X-Referrer-ACL "; public static final String CDN_TTL = "X-TTL"; diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java new file mode 100644 index 0000000000..f09b74dc51 --- /dev/null +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudfiles; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule; +import org.jclouds.cloudfiles.config.CloudFilesRestClientModule; +import org.jclouds.openstack.internal.TestOpenStackAuthenticationModule; +import org.jclouds.openstack.swift.CommonSwiftClientTest; +import org.jclouds.openstack.swift.SwiftApiMetadata; +import org.jclouds.openstack.swift.SwiftAsyncClient; +import org.jclouds.openstack.swift.config.SwiftRestClientModule; +import org.jclouds.rest.HttpClient; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import java.util.Properties; + +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + +/** + * @author Andrei Savu + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "CloudFilesClientTest") +public class CloudFilesClientTest extends CommonSwiftClientTest { + + public static final long UNIX_EPOCH_TIMESTAMP = 123456789L; + public static final String TEMPORARY_URL_KEY = "get-or-set-X-Account-Meta-Temp-Url-Key"; + + protected String provider = "cloudfiles"; + + public static class FixedCloudFilesBlobStoreContextModule extends CloudFilesBlobStoreContextModule { + @Override + protected Long unixEpochTimestampProvider() { + return UNIX_EPOCH_TIMESTAMP; + } + + @Override + protected String temporaryUrlKeyProvider(CloudFilesClient _) { + return TEMPORARY_URL_KEY; + } + } + + @Override + protected ApiMetadata createApiMetadata() { + return new CloudFilesApiMetadata().toBuilder().defaultModules( + ImmutableSet.>of(StorageEndpointModule.class, + CloudFilesRestClientModule.class, FixedCloudFilesBlobStoreContextModule.class)).build(); + } +} diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java new file mode 100644 index 0000000000..7bdcdaefc4 --- /dev/null +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java @@ -0,0 +1,83 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.cloudfiles.blobstore; + +import org.jclouds.blobstore.BlobRequestSigner; +import org.jclouds.blobstore.domain.Blob; +import org.jclouds.cloudfiles.CloudFilesClientTest; +import org.jclouds.http.HttpRequest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.Date; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +/** + * @author Andrei Savu + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "CloudFilesBlobSignerTest") +public class CloudFilesBlobSignerTest extends CloudFilesClientTest { + + private BlobRequestSigner signer; + private Blob.Factory blobFactory; + + public void testSignGetBlobWithTime() { + HttpRequest request = signer.signGetBlob("container", "name", 120); + + assertRequestLineEquals(request, "GET http://storage/container/name?" + + "temp_url_sig=4759d99d13c826bba0af2c9f0c526ca53c95abaf&temp_url_expires=123456909 HTTP/1.1"); + assertFalse(request.getHeaders().containsKey("X-Auth-Token")); + assertPayloadEquals(request, null, null, false); + + assertEquals(request.getFilters().size(), 0); + } + + public void testSignPutBlobWithTime() throws Exception { + Blob blob = blobFactory.create(null); + + blob.getMetadata().setName("name"); + blob.setPayload(""); + blob.getPayload().getContentMetadata().setContentLength(2l); + blob.getPayload().getContentMetadata().setContentMD5(new byte[]{0, 2, 4, 8}); + blob.getPayload().getContentMetadata().setContentType("text/plain"); + blob.getPayload().getContentMetadata().setExpires(new Date(1000)); + + HttpRequest request = signer.signPutBlob("container", blob, 120 /* seconds */); + + assertRequestLineEquals(request, "PUT http://storage/container/name?" + + "temp_url_sig=490690286130adac9e7144d85b320a00b1bf9e2b&temp_url_expires=123456909 HTTP/1.1"); + + assertFalse(request.getHeaders().containsKey("X-Auth-Token")); + assertContentHeadersEqual(request, "text/plain", null, null, null, (long) 2l, new byte[]{0, 2, 4, 8}, new Date(1000)); + + assertEquals(request.getFilters().size(), 0); + } + + @BeforeClass + protected void setupFactory() throws IOException { + super.setupFactory(); + this.blobFactory = injector.getInstance(Blob.Factory.class); + this.signer = injector.getInstance(BlobRequestSigner.class); + } +} diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java index edae3c1abf..14de7f6200 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java @@ -18,16 +18,37 @@ */ package org.jclouds.cloudfiles.blobstore.integration; +import org.jclouds.cloudfiles.CloudFilesApiMetadata; +import org.jclouds.cloudfiles.CloudFilesClient; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobLiveTest; import org.testng.annotations.Test; +import java.util.UUID; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + /** - * * @author Adrian Cole */ -@Test(groups = { "live" }) +@Test(groups = {"live"}) public class CloudFilesBlobLiveTest extends SwiftBlobLiveTest { - public CloudFilesBlobLiveTest(){ + public CloudFilesBlobLiveTest() { provider = "cloudfiles"; } + + public void testGetAndSetTemporaryUrlKey() { + CloudFilesClient client = view.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi(); + + String currentSecretKey = client.getTemporaryUrlKey(); + assertNotNull(currentSecretKey); + try { + String testKey = UUID.randomUUID().toString(); + client.setTemporaryUrlKey(testKey); + assertEquals(client.getTemporaryUrlKey(), testKey); + + } finally { + client.setTemporaryUrlKey(currentSecretKey); + } + } } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java index 7add9a211d..980505c59e 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java @@ -18,16 +18,78 @@ */ package org.jclouds.cloudfiles.blobstore.integration; +import org.jclouds.blobstore.domain.Blob; +import org.jclouds.http.HttpRequest; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobSignerLiveTest; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.util.Strings2; import org.testng.annotations.Test; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + /** - * * @author Adrian Cole */ -@Test(groups = { "live" }) +@Test(groups = {"live"}) public class CloudFilesBlobSignerLiveTest extends SwiftBlobSignerLiveTest { - public CloudFilesBlobSignerLiveTest(){ + public CloudFilesBlobSignerLiveTest() { provider = "cloudfiles"; } + + public void testSignGetUrlWithTime() throws InterruptedException, IOException { + String name = "hello"; + String text = "fooooooooooooooooooooooo"; + + Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); + String container = getContainerName(); + try { + view.getBlobStore().putBlob(container, blob); + assertConsistencyAwareContainerSize(container, 1); + HttpRequest request = view.getSigner().signGetBlob(container, name, 3 /* seconds */); + + assertEquals(request.getFilters().size(), 0); + assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); + + TimeUnit.SECONDS.sleep(4); + try { + Strings2.toString(view.utils().http().invoke(request).getPayload()); + fail("Temporary URL did not expire as expected"); + } catch (AuthorizationException expected) { + } + } finally { + returnContainer(container); + } + } + + @Test + public void testSignPutUrlWithTime() throws Exception { + String name = "hello"; + String text = "fooooooooooooooooooooooo"; + + Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); + String container = getContainerName(); + try { + HttpRequest request = view.getSigner().signPutBlob(container, blob, 3 /* seconds */); + assertEquals(request.getFilters().size(), 0); + + Strings2.toString(view.utils().http().invoke(request).getPayload()); + assertConsistencyAwareContainerSize(container, 1); + + view.getBlobStore().removeBlob(container, name); + assertConsistencyAwareContainerSize(container, 0); + + TimeUnit.SECONDS.sleep(4); + try { + Strings2.toString(view.utils().http().invoke(request).getPayload()); + fail("Temporary URL did not expire as expected"); + } catch (AuthorizationException expected) { + } + } finally { + returnContainer(container); + } + } } diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java index 45aa6ba3c0..71718ede7e 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java @@ -69,11 +69,21 @@ public class S3BlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(getMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signPutBlob(String container, Blob blob) { return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); } + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signRemoveBlob(String container, String name) { return cleanRequest(processor.createRequest(deleteMethod, container, name)); diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java index 7ba1fc8a10..d3986f8e7e 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java @@ -37,12 +37,14 @@ import org.jclouds.openstack.swift.domain.SwiftObject; import org.jclouds.rest.internal.RestAnnotationProcessor; /** - * + * * @author Adrian Cole */ @Singleton public class SwiftBlobRequestSigner implements BlobRequestSigner { + private final RestAnnotationProcessor processor; + private final BlobToObject blobToObject; private final BlobToHttpGetOptions blob2HttpGetOptions; @@ -54,13 +56,14 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { public SwiftBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); + this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); + this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); this.deleteMethod = CommonSwiftAsyncClient.class.getMethod("removeObject", String.class, String.class); this.createMethod = CommonSwiftAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); - } @Override @@ -68,11 +71,21 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(getMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signPutBlob(String container, Blob blob) { return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); } + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signRemoveBlob(String container, String name) { return cleanRequest(processor.createRequest(deleteMethod, container, name)); diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java index 01d39c7d2d..6b60d81071 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java @@ -33,7 +33,7 @@ import com.google.inject.Scopes; /** * Configures the {@link CloudFilesBlobStoreContext}; requires {@link SwiftAsyncBlobStore} * bound. - * + * * @author Adrian Cole */ public class SwiftBlobStoreContextModule extends AbstractModule { @@ -44,8 +44,10 @@ public class SwiftBlobStoreContextModule extends AbstractModule { bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT); bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON); - bind(BlobRequestSigner.class).to(SwiftBlobRequestSigner.class); + configureRequestSigner(); } - + protected void configureRequestSigner() { + bind(BlobRequestSigner.class).to(SwiftBlobRequestSigner.class); + } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java index d677fcb151..a8d3815445 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java @@ -74,6 +74,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest> of(StorageEndpointModule.class, SwiftRestClientModule.class, diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java index 7c3c82ce4a..fd6882b718 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java @@ -19,6 +19,7 @@ package org.jclouds.openstack.swift.blobstore; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import java.io.IOException; import java.util.Date; diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java index 019e66bcfc..392a38024e 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java @@ -25,18 +25,19 @@ import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.testng.annotations.Test; /** - * + * * @author Adrian Cole */ @Test(groups = { "live" }) public class SwiftBlobSignerLiveTest extends BaseBlobSignerLiveTest { + @Override protected Properties setupProperties() { Properties props = super.setupProperties(); setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE); return props; } - + public SwiftBlobSignerLiveTest() { provider = System.getProperty("test.swift.provider", "swift"); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java index 7720910f4e..6510ec0248 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java @@ -47,6 +47,16 @@ public interface BlobRequestSigner { */ HttpRequest signGetBlob(String container, String name); + /** + * gets a signed request, including headers as necessary, to allow access to a blob + * from an external client for a limited period of time + * + * @param timeInSeconds + * validity time in seconds for the generated request + * @see #signGetBlob(String, String) + */ + HttpRequest signGetBlob(String container, String name, long timeInSeconds); + /** * @param options * @see #signGetBlob(String, String) @@ -84,4 +94,15 @@ public interface BlobRequestSigner { * @see BlobBuilder#forSigning */ HttpRequest signPutBlob(String container, Blob blob); + + /** + * gets a signed request, including headers as necessary, to upload a blob from an + * external client for a limited period of time + * + * @param timeInSeconds + * validity time in seconds for the generated request + * @see BlobBuilder#forSigning + * @see BlobRequestSigner#signPutBlob + */ + HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java index e005ca3df3..9cd59a79be 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java @@ -62,6 +62,11 @@ public class TransientBlobRequestSigner implements BlobRequestSigner { return basicAuth.filter(request); } + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signPutBlob(String container, Blob blob) { HttpRequest request = HttpRequest.builder().method("PUT").endpoint( @@ -71,6 +76,11 @@ public class TransientBlobRequestSigner implements BlobRequestSigner { return basicAuth.filter(request); } + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signRemoveBlob(String container, String name) { HttpRequest request = HttpRequest.builder().method("DELETE").endpoint(String.format("%s/%s/%s", endpoint.get(), container, diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java index f86ed67310..cd17ebee9b 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java @@ -38,7 +38,12 @@ public class RequestSigningUnsupported implements BlobRequestSigner { } @Override - public HttpRequest signPutBlob(String container, Blob blob) { + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + + @Override + public HttpRequest signGetBlob(String container, String name, GetOptions options) { throw new UnsupportedOperationException(); } @@ -48,7 +53,12 @@ public class RequestSigningUnsupported implements BlobRequestSigner { } @Override - public HttpRequest signGetBlob(String container, String name, GetOptions options) { + public HttpRequest signPutBlob(String container, Blob blob) { + throw new UnsupportedOperationException(); + } + + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { throw new UnsupportedOperationException(); } diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java index 535d7201aa..72e881a484 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java @@ -66,11 +66,21 @@ public class AzureBlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(getMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signPutBlob(String container, Blob blob) { return cleanRequest(processor.createRequest(createMethod, container, blobToBlob.apply(blob))); } + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signRemoveBlob(String container, String name) { return cleanRequest(processor.createRequest(deleteMethod, container, name)); diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java index 90829b5418..556ff74416 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java @@ -19,7 +19,6 @@ import org.jclouds.openstack.swift.domain.SwiftObject; import org.jclouds.rest.internal.RestAnnotationProcessor; /** - * * @author Adrian Cole */ @Singleton @@ -42,7 +41,6 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner GetOptions[].class); this.deleteMethod = HPCloudObjectStorageAsyncClient.class.getMethod("removeObject", String.class, String.class); this.createMethod = HPCloudObjectStorageAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); - } @Override @@ -50,11 +48,21 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner return cleanRequest(processor.createRequest(getMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signPutBlob(String container, Blob blob) { return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); } + @Override + public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { + throw new UnsupportedOperationException(); + } + @Override public HttpRequest signRemoveBlob(String container, String name) { return cleanRequest(processor.createRequest(deleteMethod, container, name)); From 499e47c5b47d3e8025ec25427eac32d935b3e70e Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 10 Sep 2012 08:04:42 -0700 Subject: [PATCH 05/60] fixes to some softlayer tests --- .../softlayer/compute/SoftLayerExperimentLiveTest.java | 2 +- .../compute/SoftLayerTemplateBuilderLiveTest.java | 7 ++++--- .../softlayer/features/BaseSoftLayerClientLiveTest.java | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java index c98091b8a4..f7501654d0 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java @@ -36,7 +36,7 @@ import com.google.common.io.Closeables; public class SoftLayerExperimentLiveTest extends BaseComputeServiceContextLiveTest { public SoftLayerExperimentLiveTest() { - provider = "glesys"; + provider = "softlayer"; } @Test diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java index 181e380ea7..4d7b9aa477 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java @@ -63,7 +63,7 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes // For each os-type both 32- and 64-bit are supported. switch (input.family) { case UBUNTU: - return input.version.equals("") || input.version.equals("10.04") || input.version.equals("8"); + return input.version.equals("") || input.version.equals("10.04") || input.version.equals("12.04") || input.version.equals("8"); case DEBIAN: return input.version.equals("") || input.version.matches("[56].0"); case FEDORA: @@ -85,7 +85,7 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Test public void testDefaultTemplateBuilder() throws IOException { Template defaultTemplate = view.getComputeService().templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "12.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); @@ -212,6 +212,7 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes @Override protected Set getIso3166Codes() { - return ImmutableSet. of("SG", "NL", "US-CA", "US-TX", "US-VA", "US-WA", "US-TX"); + return ImmutableSet. of("SG", "US-CA", "US-TX", "US-VA", "US-WA"); } + } \ No newline at end of file diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java index f8c6eab88b..8732b7a540 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java @@ -33,6 +33,10 @@ import org.testng.annotations.Test; @Test(groups = "live") public class BaseSoftLayerClientLiveTest extends BaseComputeServiceContextLiveTest { + public BaseSoftLayerClientLiveTest() { + this.provider = "softlayer"; + } + protected RestContext socontext; @BeforeGroups(groups = { "integration", "live" }) From 0e8e07ce38316c1c353228cbd28aa5f38dd110e2 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Mon, 10 Sep 2012 22:44:26 +0300 Subject: [PATCH 06/60] Removed unused import and added @Test annotation --- .../blobstore/integration/CloudFilesBlobSignerLiveTest.java | 1 + .../openstack/swift/blobstore/SwiftBlobRequestSignerTest.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java index 980505c59e..9ced14fa93 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java @@ -40,6 +40,7 @@ public class CloudFilesBlobSignerLiveTest extends SwiftBlobSignerLiveTest { provider = "cloudfiles"; } + @Test public void testSignGetUrlWithTime() throws InterruptedException, IOException { String name = "hello"; String text = "fooooooooooooooooooooooo"; diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java index fd6882b718..7c3c82ce4a 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java @@ -19,7 +19,6 @@ package org.jclouds.openstack.swift.blobstore; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import java.io.IOException; import java.util.Date; From 2efd9a76caf5f698c1837197f54dc7dc882d8893 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 10 Sep 2012 18:02:07 -0700 Subject: [PATCH 07/60] pulled SQS out of sandbox and into labs --- labs/pom.xml | 1 + {sandbox-apis => labs}/sqs/pom.xml | 2 +- .../src/main/java/org/jclouds/sqs/SQSApi.java | 17 +- .../java/org/jclouds/sqs/SQSApiMetadata.java | 97 ++++++++++ .../java/org/jclouds/sqs/SQSAsyncApi.java | 36 ++-- .../sqs/config/SQSRestClientModule.java | 12 +- .../sqs/options/CreateQueueOptions.java | 2 +- .../sqs/options/ListQueuesOptions.java | 2 +- .../java/org/jclouds/sqs/package-info.java | 2 +- .../jclouds/sqs/reference/SQSParameters.java | 0 .../jclouds/sqs/reference/package-info.java | 0 .../java/org/jclouds/sqs/xml/MD5Handler.java | 0 .../xml/RegexListQueuesResponseHandler.java | 17 +- .../org/jclouds/sqs/xml/RegexMD5Handler.java | 0 .../jclouds/sqs/xml/RegexQueueHandler.java | 16 +- .../xml/internal/BaseRegexQueueHandler.java | 34 ++-- .../services/org.jclouds.apis.ApiMetadata | 1 + .../java/org/jclouds/sqs/SQSApiLiveTest.java | 93 +++------- .../org/jclouds/sqs/SQSApiMetadataTest.java | 23 ++- .../java/org/jclouds/sqs/SQSAsyncApiTest.java | 65 +++---- .../sqs/internal/BaseSQSApiLiveTest.java | 46 +++++ .../sqs/options/CreateQueueOptionsTest.java | 0 .../sqs/options/ListQueuesOptionsTest.java | 0 .../sqs/src/test/resources/list_queues.xml | 0 .../sqs/src/test/resources/log4j.xml | 0 .../org/jclouds/sqs/SQSContextBuilder.java | 55 ------ .../org/jclouds/sqs/SQSPropertiesBuilder.java | 54 ------ .../java/org/jclouds/sqs/domain/Queue.java | 102 ----------- .../sqs/xml/ListQueuesResponseHandler.java | 61 ------- .../org/jclouds/sqs/xml/QueueHandler.java | 75 -------- .../xml/ListQueuesResponseHandlerTest.java | 169 ------------------ 31 files changed, 259 insertions(+), 723 deletions(-) rename {sandbox-apis => labs}/sqs/pom.xml (99%) rename sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSClient.java => labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java (93%) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java rename sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSAsyncClient.java => labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java (68%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java (84%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java (98%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java (98%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/package-info.java (88%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java (100%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java (100%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java (100%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java (75%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java (100%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java (77%) rename {sandbox-apis => labs}/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java (52%) create mode 100644 labs/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata rename sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java => labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java (54%) rename sandbox-apis/sqs/src/main/java/org/jclouds/sqs/functions/QueueLocation.java => labs/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java (62%) rename sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java => labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java (72%) create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java rename {sandbox-apis => labs}/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java (100%) rename {sandbox-apis => labs}/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java (100%) rename {sandbox-apis => labs}/sqs/src/test/resources/list_queues.xml (100%) rename {sandbox-apis => labs}/sqs/src/test/resources/log4j.xml (100%) delete mode 100644 sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSContextBuilder.java delete mode 100644 sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java delete mode 100644 sandbox-apis/sqs/src/main/java/org/jclouds/sqs/domain/Queue.java delete mode 100644 sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/ListQueuesResponseHandler.java delete mode 100644 sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/QueueHandler.java delete mode 100644 sandbox-apis/sqs/src/test/java/org/jclouds/sqs/xml/ListQueuesResponseHandlerTest.java diff --git a/labs/pom.xml b/labs/pom.xml index 0ddb6ed9e2..5a445e29e9 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -61,5 +61,6 @@ fgcp fgcp-au fgcp-de + sqs diff --git a/sandbox-apis/sqs/pom.xml b/labs/sqs/pom.xml similarity index 99% rename from sandbox-apis/sqs/pom.xml rename to labs/sqs/pom.xml index da72c61635..9b94080ef8 100644 --- a/sandbox-apis/sqs/pom.xml +++ b/labs/sqs/pom.xml @@ -27,7 +27,7 @@ 1.5.0-SNAPSHOT ../../project/pom.xml - org.jclouds.api + org.jclouds.labs sqs jcloud sqs api jclouds components to access an implementation of Simple Queue Service diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSClient.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java similarity index 93% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSClient.java rename to labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index 93dd31b1be..1a059e8709 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSClient.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -18,15 +18,14 @@ */ package org.jclouds.sqs; +import java.net.URI; import java.util.Set; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; - -import org.jclouds.sqs.domain.Queue; +import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; -import org.jclouds.concurrent.Timeout; /** * Provides access to SQS via their REST API. @@ -35,7 +34,7 @@ import org.jclouds.concurrent.Timeout; * @author Adrian Cole */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) -public interface SQSClient { +public interface SQSApi { /** * The ListQueues action returns a list of your queues. The maximum number of queues that can be @@ -50,7 +49,7 @@ public interface SQSClient { * @see */ - Set listQueuesInRegion(@Nullable String region, ListQueuesOptions... options); + Set listQueuesInRegion(@Nullable String region, ListQueuesOptions... options); /** * @@ -80,7 +79,7 @@ public interface SQSClient { * @param options * like the visibility timeout (in seconds) to use for this queue. */ - Queue createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions... options); + URI createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions... options); /** * The DeleteQueue action deletes the queue specified by the queue URL, regardless of whether the @@ -102,7 +101,7 @@ public interface SQSClient { * @param queue * queue you want to delete */ - void deleteQueue(Queue queue); + void deleteQueue(URI queue); /** * The SendMessage action delivers a message to the specified queue. The maximum allowed message @@ -124,5 +123,5 @@ public interface SQSClient { * characters, see the preceding important note * @return md5 of the content sent */ - byte[] sendMessage(Queue queue, String message); + byte[] sendMessage(URI queue, String message); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java new file mode 100644 index 0000000000..7c73d9ff76 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java @@ -0,0 +1,97 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; +import org.jclouds.sqs.config.SQSRestClientModule; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for Amazon's Simple Queue Service api. + * + * @author Adrian Cole + */ +public class SQSApiMetadata extends BaseRestApiMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = -7077953935392202824L; + + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + private static final long serialVersionUID = -5070937833892503232L; + }; + + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); + } + + public SQSApiMetadata() { + this(new Builder(SQSApi.class, SQSAsyncApi.class)); + } + + protected SQSApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, "amz"); + return properties; + } + + public static class Builder extends BaseRestApiMetadata.Builder { + + protected Builder(Class api, Class asyncApi) { + super(api, asyncApi); + id("sqs") + .name("Amazon Simple Queue Service API") + .identityName("Access Key ID") + .credentialName("Secret Access Key") + .version("2009-02-01") + .defaultProperties(SQSApiMetadata.defaultProperties()) + .defaultEndpoint("https://sqs.us-east-1.amazonaws.com") + .documentation(URI.create("http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference")) + .defaultModules(ImmutableSet.>of(SQSRestClientModule.class)); + } + + @Override + public SQSApiMetadata build() { + return new SQSApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } + +} diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSAsyncClient.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java similarity index 68% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSAsyncClient.java rename to labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index c28f03f960..6572129e24 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSAsyncClient.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -21,22 +21,22 @@ package org.jclouds.sqs; import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.jclouds.sqs.reference.SQSParameters.VERSION; +import java.net.URI; import java.util.Set; -import javax.annotation.Nullable; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; +import org.jclouds.Constants; import org.jclouds.aws.filters.FormSigner; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.VirtualHost; -import org.jclouds.sqs.domain.Queue; -import org.jclouds.sqs.functions.QueueLocation; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; @@ -52,49 +52,47 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @RequestFilters(FormSigner.class) -@FormParams(keys = VERSION, values = SQSAsyncClient.VERSION) +@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") @VirtualHost -public interface SQSAsyncClient { - public static final String VERSION = "2009-02-01"; +public interface SQSAsyncApi { /** - * @see SQSClient#listQueuesInRegion + * @see SQSApi#listQueuesInRegion */ @POST @Path("/") @FormParams(keys = ACTION, values = "ListQueues") @ResponseParser(RegexListQueuesResponseHandler.class) - ListenableFuture> listQueuesInRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - ListQueuesOptions... options); + ListenableFuture> listQueuesInRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, + ListQueuesOptions... options); /** - * @see SQSClient#createQueueInRegion + * @see SQSApi#createQueueInRegion */ @POST @Path("/") @FormParams(keys = ACTION, values = "CreateQueue") @ResponseParser(RegexQueueHandler.class) - ListenableFuture createQueueInRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - @FormParam("QueueName") String queueName, CreateQueueOptions... options); + ListenableFuture createQueueInRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, + @FormParam("QueueName") String queueName, CreateQueueOptions... options); /** - * @see SQSClient#deleteQueue + * @see SQSApi#deleteQueue */ @POST @Path("/") @FormParams(keys = ACTION, values = "DeleteQueue") - ListenableFuture deleteQueue(@EndpointParam(parser = QueueLocation.class) Queue queue); + ListenableFuture deleteQueue(@EndpointParam URI queue); /** - * @see SQSClient#sendMessage + * @see SQSApi#sendMessage */ @POST @Path("/") @FormParams(keys = ACTION, values = "SendMessage") @ResponseParser(RegexMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam(parser = QueueLocation.class) Queue queue, - @FormParam("MessageBody") String message); + ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message); } diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java similarity index 84% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java rename to labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java index 7d34986c6f..bcf8de4c65 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java @@ -19,22 +19,22 @@ package org.jclouds.sqs.config; import org.jclouds.aws.config.FormSigningRestClientModule; -import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.sqs.SQSAsyncClient; -import org.jclouds.sqs.SQSClient; +import org.jclouds.sqs.SQSApi; +import org.jclouds.sqs.SQSAsyncApi; + +import com.google.common.reflect.TypeToken; /** * Configures the SQS connection. * * @author Adrian Cole */ -@RequiresHttp @ConfiguresRestClient -public class SQSRestClientModule extends FormSigningRestClientModule { +public class SQSRestClientModule extends FormSigningRestClientModule { public SQSRestClientModule() { - super(SQSClient.class, SQSAsyncClient.class); + super(TypeToken.of(SQSApi.class), TypeToken.of(SQSAsyncApi.class)); } } diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java b/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java similarity index 98% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java rename to labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java index b881e5bd53..45418883d8 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java @@ -29,7 +29,7 @@ import org.jclouds.http.options.BaseHttpRequestOptions; * * import static org.jclouds.sqs.options.CreateQueueOptions.Builder.* *

- * SQSClient connection = // get connection + * SQSApi connection = // get connection * Queue queue = connection.createQueueInRegion(defaultVisibilityTimeout("foo")); * * diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java b/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java similarity index 98% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java rename to labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java index e3004199ec..99cb158d0e 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java @@ -29,7 +29,7 @@ import org.jclouds.http.options.BaseHttpRequestOptions; * * import static org.jclouds.sqs.options.ListQueuesOptions.Builder.* *

- * SQSClient connection = // get connection + * SQSApi connection = // get connection * Set queues = connection.listQueuesInRegion(queuePrefix("foo")); * * diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/package-info.java b/labs/sqs/src/main/java/org/jclouds/sqs/package-info.java similarity index 88% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/package-info.java rename to labs/sqs/src/main/java/org/jclouds/sqs/package-info.java index 630b1edbac..07b6f72f83 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/package-info.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/package-info.java @@ -17,7 +17,7 @@ * under the License. */ /** - * This package contains an Amazon SQS client implemented by {@link org.jclouds.http.HttpCommandExecutorService} commands. + * This package contains an Amazon SQS api implemented by {@link org.jclouds.http.HttpCommandExecutorService} commands. * * @see * @author Adrian Cole diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java b/labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java similarity index 100% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java rename to labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java b/labs/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java similarity index 100% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java rename to labs/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java similarity index 100% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java rename to labs/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java similarity index 75% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java rename to labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java index dee858caf8..58b580f9d1 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java @@ -19,40 +19,35 @@ package org.jclouds.sqs.xml; import java.net.URI; -import java.util.Map; import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.sqs.domain.Queue; -import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; -import org.jclouds.location.Region; +import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler; import com.google.common.base.Function; /** * - * @see * @author Adrian Cole */ @Singleton -public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements - Function> { +public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements Function> { private final ReturnStringIf2xx returnStringIf200; @Inject - RegexListQueuesResponseHandler(@Region Map regionMap, - ReturnStringIf2xx returnStringIf200) { - super(regionMap); + RegexListQueuesResponseHandler(ReturnStringIf2xx returnStringIf200) { this.returnStringIf200 = returnStringIf200; } @Override - public Set apply(HttpResponse response) { + public Set apply(HttpResponse response) { return parse(returnStringIf200.apply(response)); } diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java similarity index 100% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java rename to labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java similarity index 77% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java rename to labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java index 086a053d2d..e79a763b74 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java @@ -19,39 +19,35 @@ package org.jclouds.sqs.xml; import java.net.URI; -import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.sqs.domain.Queue; -import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; -import org.jclouds.location.Region; +import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler; import com.google.common.base.Function; import com.google.common.collect.Iterables; /** * - * @see * @author Adrian Cole */ @Singleton -public class RegexQueueHandler extends BaseRegexQueueHandler implements - Function { +public class RegexQueueHandler extends BaseRegexQueueHandler implements Function { private final ReturnStringIf2xx returnStringIf200; @Inject - RegexQueueHandler(@Region Map regionMap, ReturnStringIf2xx returnStringIf200) { - super(regionMap); + RegexQueueHandler(ReturnStringIf2xx returnStringIf200) { this.returnStringIf200 = returnStringIf200; } @Override - public Queue apply(HttpResponse response) { + public URI apply(HttpResponse response) { return Iterables.getOnlyElement(parse(returnStringIf200.apply(response))); } } diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java similarity index 52% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java rename to labs/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java index 8f7122871a..a2c7a5f464 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java @@ -19,48 +19,36 @@ package org.jclouds.sqs.xml.internal; import java.net.URI; -import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.sqs.domain.Queue; - -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.Sets; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; /** * - * @see * @author Adrian Cole */ @Singleton public class BaseRegexQueueHandler { - private final ImmutableBiMap uriToRegion; - Pattern pattern = Pattern.compile("(https://[\\S&&[^<]]+)"); + protected final Pattern pattern = Pattern.compile("(https://[\\S&&[^<]]+)"); - @Inject - protected BaseRegexQueueHandler(Map regionMap) { - this.uriToRegion = ImmutableBiMap. builder().putAll(regionMap).build().inverse(); - } - - public Set parse(String in) { - Set queues = Sets.newLinkedHashSet(); + public Set parse(String in) { + Builder queues = ImmutableSet. builder(); Matcher matcher = pattern.matcher(in); while (matcher.find()) { String uriText = matcher.group(1); - String queueName = uriText.substring(uriText.lastIndexOf('/') + 1); - URI location = URI.create(uriText); - String regionString = uriText.substring(0, uriText.indexOf(".com/") + 4); - URI regionURI = URI.create(regionString); - String region = uriToRegion.get(regionURI); - queues.add(new Queue(region, queueName, location)); + if (!Strings.isNullOrEmpty(uriText)) + queues.add(URI.create(uriText)); } - return queues; + return queues.build(); } } diff --git a/labs/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..8831fe1bab --- /dev/null +++ b/labs/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.sqs.SQSApiMetadata \ No newline at end of file diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java similarity index 54% rename from sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java rename to labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index 2ebff952f6..f20325b4a5 100644 --- a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSClientLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -18,80 +18,33 @@ */ package org.jclouds.sqs; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.io.IOException; -import java.util.Properties; +import java.net.URI; import java.util.Set; import java.util.SortedSet; -import org.jclouds.Constants; import org.jclouds.aws.AWSResponseException; import org.jclouds.crypto.CryptoStreams; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.sqs.domain.Queue; +import org.jclouds.sqs.internal.BaseSQSApiLiveTest; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import com.google.inject.Module; /** - * Tests behavior of {@code SQSClient} + * Tests behavior of {@code SQSApi} * * @author Adrian Cole */ -@Test(groups = "live", sequential = true) -public class SQSClientLiveTest { +@Test(groups = "live", singleThreaded = true, testName = "SQSApiLiveTest") +public class SQSApiLiveTest extends BaseSQSApiLiveTest { - private SQSClient client; - - private RestContext context; - - private Set queues = Sets.newHashSet(); - protected String provider = "sqs"; - 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 = System.getProperty("test." + provider + ".endpoint"); - apiVersion = System.getProperty("test." + provider + ".api-version"); - } - - protected Properties setupProperties() { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); - overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - overrides.setProperty(provider + ".identity", identity); - if (credential != null) - overrides.setProperty(provider + ".credential", credential); - if (endpoint != null) - overrides.setProperty(provider + ".endpoint", endpoint); - if (apiVersion != null) - overrides.setProperty(provider + ".api-version", apiVersion); - return overrides; - } - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); - this.client = context.getApi(); - } + private Set queues = Sets.newHashSet(); @Test protected void testListQueues() throws InterruptedException { @@ -99,10 +52,10 @@ public class SQSClientLiveTest { } protected void listQueuesInRegion(String region) throws InterruptedException { - SortedSet allResults = Sets.newTreeSet(client.listQueuesInRegion(region)); + SortedSet allResults = Sets.newTreeSet(context.getApi().listQueuesInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { - Queue queue = allResults.last(); + URI queue = allResults.last(); assertQueueInList(region, queue); } } @@ -116,20 +69,20 @@ public class SQSClientLiveTest { public String createQueueInRegion(final String region, String queueName) throws InterruptedException { try { - SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, queuePrefix(queueName))); + SortedSet result = Sets.newTreeSet(context.getApi().listQueuesInRegion(region, queuePrefix(queueName))); if (result.size() >= 1) { - client.deleteQueue(result.last()); + context.getApi().deleteQueue(result.last()); queueName += 1;// cannot recreate a queue within 60 seconds } } catch (Exception e) { } - Queue queue = null; + URI queue = null; int tries = 0; while (queue == null && tries < 5) { try { tries++; - queue = client.createQueueInRegion(region, queueName); + queue = context.getApi().createQueueInRegion(region, queueName); } catch (AWSResponseException e) { queueName += "1"; if (e.getError().getCode().equals("AWS.SimpleQueueService.QueueDeletedRecently"))// TODO @@ -139,9 +92,6 @@ public class SQSClientLiveTest { throw e; } } - if (region != null) - assertEquals(queue.getRegion(), region); - assertEquals(queue.getName(), queueName); assertQueueInList(region, queue); queues.add(queue); return queueName; @@ -151,19 +101,19 @@ public class SQSClientLiveTest { protected void testSendMessage() throws InterruptedException, IOException { String message = "hardyharhar"; byte[] md5 = CryptoStreams.md5(message.getBytes()); - for (Queue queue : queues) { - assertEquals(client.sendMessage(queue, message), md5); + for (URI queue : queues) { + assertEquals(context.getApi().sendMessage(queue, message), md5); } } - private void assertQueueInList(final String region, Queue queue) throws InterruptedException { - final Queue finalQ = queue; + private void assertQueueInList(final String region, URI queue) throws InterruptedException { + final URI finalQ = queue; assertEventually(new Runnable() { public void run() { - SortedSet result = Sets.newTreeSet(client.listQueuesInRegion(region, queuePrefix(finalQ.getName()))); + Set result = context.getApi().listQueuesInRegion(region); assertNotNull(result); assert result.size() >= 1 : result; - assertEquals(result.first(), finalQ); + assertTrue(result.contains(finalQ), finalQ + " not in " + result); } }); } @@ -171,8 +121,9 @@ public class SQSClientLiveTest { private static final int INCONSISTENCY_WINDOW = 10000; /** - * Due to eventual consistency, container commands may not return correctly immediately. Hence, - * we will try up to the inconsistency window to see if the assertion completes. + * Due to eventual consistency, container commands may not return correctly + * immediately. Hence, we will try up to the inconsistency window to see if + * the assertion completes. */ protected static void assertEventually(Runnable assertion) throws InterruptedException { long start = System.currentTimeMillis(); diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/functions/QueueLocation.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java similarity index 62% rename from sandbox-apis/sqs/src/main/java/org/jclouds/sqs/functions/QueueLocation.java rename to labs/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java index 9e2846bdba..4f5eedaeec 100644 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/functions/QueueLocation.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java @@ -16,25 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs.functions; +package org.jclouds.sqs; -import java.net.URI; +import org.jclouds.View; +import org.jclouds.rest.internal.BaseRestApiMetadataTest; +import org.testng.annotations.Test; -import javax.inject.Singleton; - -import org.jclouds.sqs.domain.Queue; - -import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; /** * * @author Adrian Cole */ -@Singleton -public class QueueLocation implements Function { +@Test(groups = "unit", testName = "SQSApiMetadataTest") +public class SQSApiMetadataTest extends BaseRestApiMetadataTest { - public URI apply(Object from) { - return ((Queue) from).getLocation(); + // no queue abstraction, yet + public SQSApiMetadataTest() { + super(new SQSApiMetadata(), ImmutableSet.> of()); } - } diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java similarity index 72% rename from sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java rename to labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java index 9659b63167..4bdc810538 100644 --- a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/SQSAsyncClientTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java @@ -23,19 +23,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Method; -import java.util.Properties; -import javax.inject.Named; - -import org.jclouds.Constants; +import org.jclouds.apis.ApiMetadata; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; 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.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.sqs.config.SQSRestClientModule; import org.jclouds.sqs.options.CreateQueueOptions; @@ -48,27 +42,31 @@ import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code SQSAsyncClient} + * Tests behavior of {@code SQSAsyncApi} * * @author Adrian Cole */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "SQSAsyncClientTest") -public class SQSAsyncClientTest extends RestClientTest { +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "SQSAsyncApiTest") +public class SQSAsyncApiTest extends BaseAsyncClientTest { + + @Override + protected ApiMetadata createApiMetadata() { + return new SQSApiMetadata(); + } - @RequiresHttp @ConfiguresRestClient - private static final class TestSQSRestClientModule extends SQSRestClientModule { + private static final class TestSQSRestApiModule extends SQSRestClientModule { @Override - protected String provideTimeStamp(final DateService dateService, - @Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) { + protected String provideTimeStamp(final DateService dateService) { return "2009-11-08T15:54:08.897Z"; } } public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, + Method method = SQSAsyncApi.class.getMethod("listQueuesInRegion", String.class, Array.newInstance(ListQueuesOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method, (String) null); @@ -84,7 +82,7 @@ public class SQSAsyncClientTest extends RestClientTest { } public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncClient.class.getMethod("listQueuesInRegion", String.class, + Method method = SQSAsyncApi.class.getMethod("listQueuesInRegion", String.class, Array.newInstance(ListQueuesOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method, null, ListQueuesOptions.Builder.queuePrefix("prefix")); @@ -101,8 +99,8 @@ public class SQSAsyncClientTest extends RestClientTest { } public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array - .newInstance(CreateQueueOptions.class, 0).getClass()); + Method method = SQSAsyncApi.class.getMethod("createQueueInRegion", String.class, String.class, + Array.newInstance(CreateQueueOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method, null, "queueName"); assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); @@ -118,8 +116,8 @@ public class SQSAsyncClientTest extends RestClientTest { } public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncClient.class.getMethod("createQueueInRegion", String.class, String.class, Array - .newInstance(CreateQueueOptions.class, 0).getClass()); + Method method = SQSAsyncApi.class.getMethod("createQueueInRegion", String.class, String.class, + Array.newInstance(CreateQueueOptions.class, 0).getClass()); HttpRequest request = processor.createRequest(method, null, "queueName", CreateQueueOptions.Builder.defaultVisibilityTimeout(45)); @@ -143,31 +141,14 @@ public class SQSAsyncClientTest extends RestClientTest { } @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { }; } @Override protected Module createModule() { - return new TestSQSRestClientModule(); - } - - protected String provider = "sqs"; - - @Override - protected Properties getProperties() { - Properties overrides = new Properties(); - overrides.setProperty(provider + ".endpoint", "https://sqs.us-east-1.amazonaws.com"); - overrides.setProperty(provider + ".propertiesbuilder", SQSPropertiesBuilder.class.getName()); - overrides.setProperty(provider + ".contextbuilder", SQSContextBuilder.class.getName()); - return overrides; - } - - @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", - new Properties()); + return new TestSQSRestApiModule(); } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java new file mode 100644 index 0000000000..e77d9f7ab6 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.internal; + +import org.jclouds.apis.BaseContextLiveTest; +import org.jclouds.rest.RestContext; +import org.jclouds.sqs.SQSApi; +import org.jclouds.sqs.SQSApiMetadata; +import org.jclouds.sqs.SQSAsyncApi; +import org.testng.annotations.Test; + +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseSQSApiLiveTest extends BaseContextLiveTest> { + + public BaseSQSApiLiveTest() { + provider = "sqs"; + } + + @Override + protected TypeToken> contextType() { + return SQSApiMetadata.CONTEXT_TOKEN; + } + +} diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java similarity index 100% rename from sandbox-apis/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java rename to labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java similarity index 100% rename from sandbox-apis/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java rename to labs/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java diff --git a/sandbox-apis/sqs/src/test/resources/list_queues.xml b/labs/sqs/src/test/resources/list_queues.xml similarity index 100% rename from sandbox-apis/sqs/src/test/resources/list_queues.xml rename to labs/sqs/src/test/resources/list_queues.xml diff --git a/sandbox-apis/sqs/src/test/resources/log4j.xml b/labs/sqs/src/test/resources/log4j.xml similarity index 100% rename from sandbox-apis/sqs/src/test/resources/log4j.xml rename to labs/sqs/src/test/resources/log4j.xml diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSContextBuilder.java b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSContextBuilder.java deleted file mode 100644 index 99be8753b5..0000000000 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSContextBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs; - -import java.util.List; -import java.util.Properties; - -import org.jclouds.sqs.config.SQSRestClientModule; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.rest.RestContextBuilder; - -import com.google.inject.Injector; -import com.google.inject.Module; - -/** - * Creates {@link SQSContext} or {@link Injector} instances based on the most commonly requested - * arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. - *

- *

- * If no Modules are specified, the default {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. - * - * @author Adrian Cole - * @see SQSContext - */ -public class SQSContextBuilder extends RestContextBuilder { - - public SQSContextBuilder(Properties props) { - super(SQSClient.class, SQSAsyncClient.class, props); - } - - @Override - protected void addClientModule(List modules) { - modules.add(new SQSRestClientModule()); - } -} diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java deleted file mode 100644 index ef2b7ebd69..0000000000 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/SQSPropertiesBuilder.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; -import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; - -import java.util.Properties; - -import org.jclouds.PropertiesBuilder; - -/** - * Builds properties used in SQS Clients - * - * @author Adrian Cole - */ -public class SQSPropertiesBuilder extends PropertiesBuilder { - @Override - protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); - properties.setProperty(PROPERTY_HEADER_TAG, "amz"); - properties.setProperty(PROPERTY_API_VERSION, SQSAsyncClient.VERSION); - properties.setProperty(PROPERTY_ENDPOINT, "https://sqs.us-east-1.amazonaws.com"); - return properties; - } - - public SQSPropertiesBuilder() { - super(); - } - - public SQSPropertiesBuilder(Properties properties) { - super(properties); - } - -} diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/domain/Queue.java b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/domain/Queue.java deleted file mode 100644 index a6e0fbe98f..0000000000 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/domain/Queue.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; - -/** - * - * @see - * @author Adrian Cole - */ -public class Queue implements Comparable { - private final String region; - private final String name; - private final URI location; - - public Queue(String region, String name, URI location) { - this.region = checkNotNull(region,"region"); - this.location = checkNotNull(location, "location"); - this.name = checkNotNull(name, "name"); - } - - @Override - public int compareTo(Queue o) { - return location.toASCIIString().compareTo(o.location.toASCIIString()); - } - - public String getRegion() { - return region; - } - - public URI getLocation() { - return location; - } - - public String getName() { - return name; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((location == null) ? 0 : location.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((region == null) ? 0 : region.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; - Queue other = (Queue) obj; - if (location == null) { - if (other.location != null) - return false; - } else if (!location.equals(other.location)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (region == null) { - if (other.region != null) - return false; - } else if (!region.equals(other.region)) - return false; - return true; - } - - @Override - public String toString() { - return "Queue [location=" + location + ", name=" + name + ", region=" + region + "]"; - } - - -} diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/ListQueuesResponseHandler.java b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/ListQueuesResponseHandler.java deleted file mode 100644 index 746d8fa7b6..0000000000 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/ListQueuesResponseHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs.xml; - -import java.util.Set; - -import javax.inject.Inject; - -import org.jclouds.sqs.domain.Queue; -import org.jclouds.http.functions.ParseSax; - -import com.google.common.collect.Sets; - -/** - * - * @see - * @author Adrian Cole - */ -public class ListQueuesResponseHandler extends ParseSax.HandlerWithResult> { - - Set queues = Sets.newLinkedHashSet(); - - private final QueueHandler qHandler; - - @Inject - ListQueuesResponseHandler(QueueHandler qHandler) { - this.qHandler = qHandler; - } - - public Set getResult() { - return queues; - } - - public void endElement(String uri, String name, String qName) { - qHandler.endElement(uri, name, qName); - if (qName.equals("QueueUrl")) { - queues.add(qHandler.getResult()); - } - } - - public void characters(char ch[], int start, int length) { - qHandler.characters(ch, start, length); - } -} diff --git a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/QueueHandler.java b/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/QueueHandler.java deleted file mode 100644 index ae581c131f..0000000000 --- a/sandbox-apis/sqs/src/main/java/org/jclouds/sqs/xml/QueueHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs.xml; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Provider; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.sqs.domain.Queue; -import org.jclouds.http.functions.ParseSax; -import org.jclouds.location.Region; - -import com.google.common.collect.ImmutableBiMap; - -/** - * - * @see - * @author Adrian Cole - */ -public class QueueHandler extends ParseSax.HandlerWithResult { - - private StringBuilder currentText = new StringBuilder(); - Queue queue; - - private final ImmutableBiMap regionBiMap; - private final Provider uriBuilderProvider; - - @Inject - QueueHandler(Provider uriBuilderProvider, @Region Map regionMap) { - this.uriBuilderProvider = uriBuilderProvider; - this.regionBiMap = ImmutableBiMap. copyOf(regionMap).inverse(); - } - - public Queue getResult() { - return queue; - } - - public void endElement(String uri, String name, String qName) { - - if (qName.equals("QueueUrl")) { - String uriText = currentText.toString().trim(); - String queueName = uriText.substring(uriText.lastIndexOf('/') + 1); - URI location = URI.create(uriText); - URI regionURI = uriBuilderProvider.get().uri(location).replacePath("").build(); - String region = regionBiMap.get(regionURI); - this.queue = new Queue(region, queueName, location); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } -} diff --git a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/xml/ListQueuesResponseHandlerTest.java b/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/xml/ListQueuesResponseHandlerTest.java deleted file mode 100644 index 729333fa89..0000000000 --- a/sandbox-apis/sqs/src/test/java/org/jclouds/sqs/xml/ListQueuesResponseHandlerTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.inject.Singleton; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.PerformanceTest; -import org.jclouds.aws.domain.Region; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.ParseSax.Factory; -import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.io.Payloads; -import org.jclouds.sqs.domain.Queue; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.io.ByteStreams; -import com.google.common.io.InputSupplier; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Provides; -import com.sun.jersey.api.uri.UriBuilderImpl; - -/** - * Tests behavior of {@code ListQueuesResponseHandlerr} - * - * @author Adrian Cole - */ -// NOTE:without testName, this will fail w/NPE during surefire -@Test(groups = "performance", sequential = true, timeOut = 2 * 60 * 1000, testName = "ListQueuesResponseHandlerTest") -public class ListQueuesResponseHandlerTest extends PerformanceTest { - - private Injector injector; - private Factory factory; - private RegexListQueuesResponseHandler handler; - private InputSupplier supplier; - - @BeforeTest - protected void setUpInjector() throws IOException { - - LOOP_COUNT = 100000; - THREAD_COUNT = 100; - - System.out.printf("queue response handle speed test %d threads %d count%n", THREAD_COUNT, - LOOP_COUNT); - injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() { - - @Override - protected void configure() { - bind(UriBuilder.class).to(UriBuilderImpl.class); - } - - @SuppressWarnings("unused") - @Provides - @Singleton - @org.jclouds.location.Region - Map provideRegions() { - return ImmutableMap. of(Region.EU_WEST_1, URI - .create("https://eu-west-1.queue.amazonaws.com")); - } - - }); - handler = injector.getInstance(RegexListQueuesResponseHandler.class); - - factory = injector.getInstance(ParseSax.Factory.class); - InputStream inputStream = getClass().getResourceAsStream("/list_queues.xml"); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ByteStreams.copy(inputStream, out); - supplier = ByteStreams.newInputStreamSupplier(out.toByteArray()); - assert factory != null; - } - - Set expected = ImmutableSet.of(new Queue(Region.EU_WEST_1, "adriancole-sqs1", URI - .create("https://eu-west-1.queue.amazonaws.com/993194456877/adriancole-sqs1")), - - new Queue(Region.EU_WEST_1, "adriancole-sqs111", URI - .create("https://eu-west-1.queue.amazonaws.com/993194456877/adriancole-sqs111"))); - - public void testSax() { - ListQueuesResponseHandler handler = injector.getInstance(ListQueuesResponseHandler.class); - Set result; - try { - result = factory.create(handler).parse(supplier.getInput()); - assertEquals(result, expected); - } catch (Exception e) { - Throwables.propagate(e); - } - } - - public void testRegex() { - try { - assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(supplier - .getInput()))), expected); - } catch (IOException e) { - Throwables.propagate(e); - } - } - - @Test(enabled = false) - void testRegexSerialResponseTime() throws IOException { - long now = System.currentTimeMillis(); - for (int i = 0; i < LOOP_COUNT; i++) - testRegex(); - System.out.println("testRegex serial: " + (System.currentTimeMillis() - now) + ""); - } - - @Test(enabled = false) - void testRegexParallelResponseTime() throws Throwable { - List tasks = ImmutableList. of(new Runnable() { - public void run() { - testRegex(); - } - }); - executeMultiThreadedPerformanceTest("testRegexParallelResponseTime", tasks); - } - - @Test(enabled = false) - void testSaxSerialResponseTime() throws IOException { - long now = System.currentTimeMillis(); - for (int i = 0; i < LOOP_COUNT; i++) - testSax(); - System.out.println("testSax serial: " + (System.currentTimeMillis() - now) + ""); - } - - @Test(enabled = false) - void testSaxParallelResponseTime() throws Throwable { - List tasks = ImmutableList. of(new Runnable() { - public void run() { - testSax(); - } - }); - executeMultiThreadedPerformanceTest("testSaxParallelResponseTime", tasks); - } - -} From c5fe0a77a4b3aad1b4cd63a25429adbadf1a234c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 11 Sep 2012 10:42:26 -0700 Subject: [PATCH 08/60] switch sqs to use HashCode for md5 --- labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java | 4 +++- .../sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java | 3 ++- .../main/java/org/jclouds/sqs/xml/RegexMD5Handler.java | 10 ++++++---- .../src/test/java/org/jclouds/sqs/SQSApiLiveTest.java | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index 1a059e8709..a9209f67ad 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -27,6 +27,8 @@ import org.jclouds.javax.annotation.Nullable; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; +import com.google.common.hash.HashCode; + /** * Provides access to SQS via their REST API. *

@@ -123,5 +125,5 @@ public interface SQSApi { * characters, see the preceding important note * @return md5 of the content sent */ - byte[] sendMessage(URI queue, String message); + HashCode sendMessage(URI queue, String message); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index 6572129e24..20f27d3614 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -43,6 +43,7 @@ import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.sqs.xml.RegexMD5Handler; import org.jclouds.sqs.xml.RegexQueueHandler; +import com.google.common.hash.HashCode; import com.google.common.util.concurrent.ListenableFuture; /** @@ -93,6 +94,6 @@ public interface SQSAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "SendMessage") @ResponseParser(RegexMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message); + ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java index a4317c292b..4eaa3d9bef 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java @@ -28,6 +28,8 @@ import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; import com.google.common.base.Function; +import com.google.common.hash.HashCode; +import com.google.common.hash.HashCodes; import com.google.inject.Singleton; /** @@ -37,7 +39,7 @@ import com.google.inject.Singleton; * @author Adrian Cole */ @Singleton -public class RegexMD5Handler implements Function { +public class RegexMD5Handler implements Function { Pattern pattern = Pattern.compile("([\\S&&[^<]]+)"); private final ReturnStringIf2xx returnStringIf200; @@ -47,13 +49,13 @@ public class RegexMD5Handler implements Function { } @Override - public byte[] apply(HttpResponse response) { - byte[] value = null; + public HashCode apply(HttpResponse response) { + HashCode value = null; String content = returnStringIf200.apply(response); if (content != null) { Matcher matcher = pattern.matcher(content); if (matcher.find()) { - value = CryptoStreams.hex(matcher.group(1)); + value = HashCodes.fromBytes(CryptoStreams.hex(matcher.group(1))); } } return value; diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index f20325b4a5..73116e15d8 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -29,12 +29,14 @@ import java.util.Set; import java.util.SortedSet; import org.jclouds.aws.AWSResponseException; -import org.jclouds.crypto.CryptoStreams; import org.jclouds.sqs.internal.BaseSQSApiLiveTest; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; +import com.google.common.base.Charsets; import com.google.common.collect.Sets; +import com.google.common.hash.HashCode; +import com.google.common.hash.Hashing; /** * Tests behavior of {@code SQSApi} @@ -100,7 +102,7 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { @Test(dependsOnMethods = "testCreateQueue") protected void testSendMessage() throws InterruptedException, IOException { String message = "hardyharhar"; - byte[] md5 = CryptoStreams.md5(message.getBytes()); + HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); for (URI queue : queues) { assertEquals(context.getApi().sendMessage(queue, message), md5); } From f0e95ced3450e84ad44798a0dbc91398a850d1d2 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Tue, 11 Sep 2012 23:16:08 +0300 Subject: [PATCH 09/60] Replaced Instant.now() with System.currentTimeMillis() and removed some unused imports --- apis/cloudfiles/pom.xml | 5 ----- .../blobstore/config/CloudFilesBlobStoreContextModule.java | 5 +---- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/apis/cloudfiles/pom.xml b/apis/cloudfiles/pom.xml index a067095c2e..708148679c 100644 --- a/apis/cloudfiles/pom.xml +++ b/apis/cloudfiles/pom.xml @@ -53,11 +53,6 @@ swift ${project.version} - - org.jclouds.driver - jclouds-joda - ${project.version} - org.jclouds jclouds-core diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java index 2c4b8f1544..011a3054cf 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java @@ -41,9 +41,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.inject.Provides; -import org.jclouds.rest.HttpClient; -import org.jclouds.rest.RequestSigner; -import org.joda.time.Instant; /** * @author Adrian Cole @@ -70,7 +67,7 @@ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModul @Provides @TimeStamp protected Long unixEpochTimestampProvider() { - return Instant.now().getMillis() / 1000; /* in seconds */ + return System.currentTimeMillis() / 1000; /* convert to seconds */ } @Provides From 327066acd7b78f7f03f369c7dd29b058d7243dc3 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Tue, 11 Sep 2012 23:55:21 +0300 Subject: [PATCH 10/60] Added @Beta annotations on the new methods in BlobRequestSigner --- .../src/main/java/org/jclouds/blobstore/BlobRequestSigner.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java index 6510ec0248..5cd65d1fb4 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java @@ -18,6 +18,7 @@ */ package org.jclouds.blobstore; +import com.google.common.annotations.Beta; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobBuilder; import org.jclouds.blobstore.internal.RequestSigningUnsupported; @@ -55,6 +56,7 @@ public interface BlobRequestSigner { * validity time in seconds for the generated request * @see #signGetBlob(String, String) */ + @Beta HttpRequest signGetBlob(String container, String name, long timeInSeconds); /** @@ -104,5 +106,6 @@ public interface BlobRequestSigner { * @see BlobBuilder#forSigning * @see BlobRequestSigner#signPutBlob */ + @Beta HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds); } From e19d27f97c58ae8186d9d9faad0779a5b135dee7 Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Mon, 10 Sep 2012 14:56:53 -0500 Subject: [PATCH 11/60] Updates to Rackspace CDN Container Metadata handling. Added feature to Purge CDN Object. Added feature to set default index and error pages for CDN based static website. --- .../cloudfiles/CloudFilesAsyncClient.java | 83 +++++++- .../jclouds/cloudfiles/CloudFilesClient.java | 56 ++++- ...rableToHeadersWithPurgeCDNObjectEmail.java | 53 +++++ .../domain/ContainerCDNMetadata.java | 55 +++-- .../ParseContainerCDNMetadataFromHeaders.java | 26 ++- .../reference/CloudFilesHeaders.java | 9 +- .../CloudFilesClientExpectTest.java | 201 +++++++++++++++++- .../cloudfiles/CloudFilesClientLiveTest.java | 36 +++- ...eToHeadersWithPurgeCDNObjectEmailTest.java | 76 +++++++ ...erCDNMetadataListFromJsonResponseTest.java | 32 ++- .../src/test/resources/test_list_cdn.json | 36 +++- .../swift/CommonSwiftClientLiveTest.java | 2 +- 12 files changed, 608 insertions(+), 57 deletions(-) create mode 100644 apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/binders/BindIterableToHeadersWithPurgeCDNObjectEmail.java create mode 100644 apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/binders/BindIterableToHeadersWithPurgeCDNObjectEmailTest.java diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java index 9b73ad6971..aa3c9aaf8d 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java @@ -19,10 +19,12 @@ package org.jclouds.cloudfiles; import java.net.URI; +import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HEAD; import javax.ws.rs.HeaderParam; @@ -33,6 +35,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; +import org.jclouds.cloudfiles.binders.BindIterableToHeadersWithPurgeCDNObjectEmail; import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.cloudfiles.functions.ParseCdnUriFromHeaders; import org.jclouds.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders; @@ -42,6 +45,7 @@ import org.jclouds.cloudfiles.reference.CloudFilesHeaders; import org.jclouds.openstack.filters.AuthenticateRequest; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.Storage; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.Headers; @@ -78,9 +82,6 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { @Endpoint(CDNManagement.class) ListenableFuture> listCDNContainers(ListCdnContainerOptions... options); - // TODO: Container name is not included in CDN HEAD response headers, so we - // cannot populate it - // here. /** * @see CloudFilesClient#getCDNMetadata */ @@ -91,6 +92,18 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { @Endpoint(CDNManagement.class) ListenableFuture getCDNMetadata(@PathParam("container") String container); + /** + * @see CloudFilesClient#enableCDN(String, long, boolean); + */ + @PUT + @Path("/{container}") + @Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "True") + @ResponseParser(ParseCdnUriFromHeaders.class) + @Endpoint(CDNManagement.class) + ListenableFuture enableCDN(@PathParam("container") String container, + @HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl, + @HeaderParam(CloudFilesHeaders.CDN_LOG_RETENTION) boolean logRetention); + /** * @see CloudFilesClient#enableCDN(String, long); */ @@ -100,7 +113,7 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { @ResponseParser(ParseCdnUriFromHeaders.class) @Endpoint(CDNManagement.class) ListenableFuture enableCDN(@PathParam("container") String container, - @HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl); + @HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl); /** * @see CloudFilesClient#enableCDN(String) @@ -113,14 +126,35 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { ListenableFuture enableCDN(@PathParam("container") String container); /** - * @see CloudFilesClient#updateCDN + * @see CloudFilesClient#updateCDN(long, boolean) */ @POST @Path("/{container}") @ResponseParser(ParseCdnUriFromHeaders.class) @Endpoint(CDNManagement.class) ListenableFuture updateCDN(@PathParam("container") String container, - @HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl); + @HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl, + @HeaderParam(CloudFilesHeaders.CDN_LOG_RETENTION) boolean logRetention); + + /** + * @see CloudFilesClient#updateCDN(boolean) + */ + @POST + @Path("/{container}") + @ResponseParser(ParseCdnUriFromHeaders.class) + @Endpoint(CDNManagement.class) + ListenableFuture updateCDN(@PathParam("container") String container, + @HeaderParam(CloudFilesHeaders.CDN_LOG_RETENTION) boolean logRetention); + + /** + * @see CloudFilesClient#updateCDN(long) + */ + @POST + @Path("/{container}") + @ResponseParser(ParseCdnUriFromHeaders.class) + @Endpoint(CDNManagement.class) + ListenableFuture updateCDN(@PathParam("container") String container, + @HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl); /** * @see CloudFilesClient#disableCDN @@ -131,6 +165,43 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { @Endpoint(CDNManagement.class) ListenableFuture disableCDN(@PathParam("container") String container); + /** + * @see CloudFilesClient#purgeCDNObject(String, String, List) + */ + @DELETE + @Path("/{container}/{object}") + @Headers(keys = CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL, values = "{email}") + @Endpoint(CDNManagement.class) + ListenableFuture purgeCDNObject(@PathParam("container") String container, + @PathParam("object") String object, + @BinderParam(BindIterableToHeadersWithPurgeCDNObjectEmail.class) Iterable emails); + + /** + * @see CloudFilesClient#purgeCDNObject(String, String) + */ + @DELETE + @Path("/{container}/{object}") + @Endpoint(CDNManagement.class) + ListenableFuture purgeCDNObject(@PathParam("container") String container, + @PathParam("object") String object); + + /** + * @see CloudFilesClient#setCDNStaticWebsiteIndex + */ + @POST + @Path("/{container}") + @Headers(keys = CloudFilesHeaders.CDN_WEBSITE_INDEX, values = "{index}") + ListenableFuture setCDNStaticWebsiteIndex(@PathParam("container") String container, + @PathParam("index") String index); + + /** + * @see CloudFilesClient#setCDNStaticWebsiteError + */ + @POST + @Path("/{container}") + @Headers(keys = CloudFilesHeaders.CDN_WEBSITE_ERROR, values = "{error}") + ListenableFuture setCDNStaticWebsiteError(@PathParam("container") String container, + @PathParam("error") String error); /** * @see CloudFilesClient#getTemporaryUrlKey diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java index f52d7b8ad8..23e3dd3abb 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java @@ -40,17 +40,71 @@ import org.jclouds.openstack.swift.CommonSwiftClient; */ @Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) public interface CloudFilesClient extends CommonSwiftClient { + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/List_CDN-Enabled_Containers-d1e2414.html + */ Set listCDNContainers(ListCdnContainerOptions... options); + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/List_CDN-Enabled_Container_Metadata-d1e2711.html + */ ContainerCDNMetadata getCDNMetadata(String container); + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/CDN-Enabled_Container-d1e2665.html + */ + URI enableCDN(String container, long ttl, boolean logRetention); + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/CDN-Enabled_Container-d1e2665.html + */ URI enableCDN(String container, long ttl); - + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/CDN-Enabled_Container-d1e2665.html + */ URI enableCDN(String container); + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/Update_CDN-Enabled_Container_Metadata-d1e2787.html + */ + URI updateCDN(String container, long ttl, boolean logRetention); + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/Update_CDN-Enabled_Container_Metadata-d1e2787.html + */ + URI updateCDN(String container, boolean logRetention); + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/Update_CDN-Enabled_Container_Metadata-d1e2787.html + */ URI updateCDN(String container, long ttl); + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/CDN-Enabled_Container-d1e2665.html + */ boolean disableCDN(String container); + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/Purge_CDN-Enabled_Objects-d1e3858.html + */ + boolean purgeCDNObject(String container, String object, Iterable emails); + + /** + * See http://docs.rackspace.com/files/api/v1/cf-devguide/content/Purge_CDN-Enabled_Objects-d1e3858.html + */ + boolean purgeCDNObject(String container, String object); + + /** + * http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_Static_Website-dle4000.html + */ + boolean setCDNStaticWebsiteIndex(String container, String index); + + /* + * http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Error_Pages_for_Static_Website-dle4005.html + */ + boolean setCDNStaticWebsiteError(String container, String error); /** * Retrieve the key used to generate Temporary object access URLs diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/binders/BindIterableToHeadersWithPurgeCDNObjectEmail.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/binders/BindIterableToHeadersWithPurgeCDNObjectEmail.java new file mode 100644 index 0000000000..77c36a9214 --- /dev/null +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/binders/BindIterableToHeadersWithPurgeCDNObjectEmail.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudfiles.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; + +import javax.inject.Singleton; + +import org.jclouds.cloudfiles.reference.CloudFilesHeaders; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMultimap; + +/** + * @author Everett Toews + */ +@Singleton +public class BindIterableToHeadersWithPurgeCDNObjectEmail implements Binder { + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + checkArgument(checkNotNull(input, "input") instanceof Iterable, "this binder is only valid for Iterable!"); + checkNotNull(request, "request"); + + Iterable emails = (Iterable) input; + String emailCSV = Joiner.on(", ").join((List) emails); + ImmutableMultimap headers = + ImmutableMultimap. of(CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL, emailCSV); + + return (R) request.toBuilder().replaceHeaders(headers).build(); + } +} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/domain/ContainerCDNMetadata.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/domain/ContainerCDNMetadata.java index 727cf238a4..a885ecb3f6 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/domain/ContainerCDNMetadata.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/domain/ContainerCDNMetadata.java @@ -29,17 +29,22 @@ public class ContainerCDNMetadata implements Comparable { private String name; private boolean cdn_enabled; + private boolean log_retention; private long ttl; private URI cdn_uri; + private URI cdn_ssl_uri; + private URI cdn_streaming_uri; private String referrer_acl; private String useragent_acl; - private boolean log_retention; - public ContainerCDNMetadata(String name, boolean cdnEnabled, long ttl, URI cdnUri) { + public ContainerCDNMetadata(String name, boolean cdnEnabled, boolean logRetention, long ttl, URI cdnUri, URI cdnSslUri, URI cdnStreamingUri) { this.name = name; this.cdn_enabled = cdnEnabled; + this.log_retention = logRetention; this.ttl = ttl; this.cdn_uri = cdnUri; + this.cdn_ssl_uri = cdnSslUri; + this.cdn_streaming_uri = cdnStreamingUri; } public ContainerCDNMetadata() { @@ -53,16 +58,36 @@ public class ContainerCDNMetadata implements Comparable { return name; } - public URI getCDNUri() { - return cdn_uri; + public boolean isCDNEnabled() { + return cdn_enabled; + } + + public boolean isLogRetention() { + return log_retention; } public long getTTL() { return ttl; } - public boolean isCDNEnabled() { - return cdn_enabled; + public URI getCDNUri() { + return cdn_uri; + } + + public URI getCDNSslUri() { + return cdn_ssl_uri; + } + + public URI getCDNStreamingUri() { + return cdn_streaming_uri; + } + + public String getReferrerACL() { + return referrer_acl; + } + + public String getUseragentACL() { + return useragent_acl; } public int compareTo(ContainerCDNMetadata o) { @@ -87,31 +112,21 @@ public class ContainerCDNMetadata implements Comparable { return false; if (getClass() != obj.getClass()) return false; + ContainerCDNMetadata other = (ContainerCDNMetadata) obj; if (cdn_uri == null) { if (other.cdn_uri != null) return false; } else if (!cdn_uri.equals(other.cdn_uri)) return false; + return true; } - public String getReferrerACL() { - return referrer_acl; - } - - public String getUseragentACL() { - return useragent_acl; - } - - public boolean isLogRetention() { - return log_retention; - } - @Override public String toString() { return String.format( - "[name=%s, cdn_uri=%s, cdn_enabled=%s, log_retention=%s, referrer_acl=%s, ttl=%s, useragent_acl=%s]", - name, cdn_uri, cdn_enabled, log_retention, referrer_acl, ttl, useragent_acl); + "[name=%s, cdn_enabled=%s, log_retention=%s, ttl=%s, cdn_uri=%s, cdn_ssl_uri=%s, cdn_streaming_uri=%s, referrer_acl=%s, useragent_acl=%s]", + name, cdn_enabled, log_retention, ttl, cdn_uri, cdn_ssl_uri, cdn_streaming_uri, referrer_acl, useragent_acl); } } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java index b53a4144e6..42b9f8909c 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataFromHeaders.java @@ -45,18 +45,26 @@ public class ParseContainerCDNMetadataFromHeaders implements * parses the http response headers to create a new {@link ContainerCDNMetadata} object. */ public ContainerCDNMetadata apply(final HttpResponse from) { - String cdnUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_URI), - CloudFilesHeaders.CDN_URI); - String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_TTL), - CloudFilesHeaders.CDN_TTL); - String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_ENABLED), - CloudFilesHeaders.CDN_ENABLED); + String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_ENABLED), CloudFilesHeaders.CDN_ENABLED); + String cdnLogRetention = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_LOG_RETENTION), CloudFilesHeaders.CDN_LOG_RETENTION); + String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_TTL), CloudFilesHeaders.CDN_TTL); + String cdnUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_URI), CloudFilesHeaders.CDN_URI); + String cdnSslUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_SSL_URI), CloudFilesHeaders.CDN_SSL_URI); + String cdnStreamingUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_STREAMING_URI), CloudFilesHeaders.CDN_STREAMING_URI); + if (cdnUri == null) { // CDN is not, and has never, been enabled for this container. return null; - } else { - return new ContainerCDNMetadata(request.getEndpoint().getPath(), Boolean - .parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri)); + } + else { + return new ContainerCDNMetadata( + request.getEndpoint().getPath(), + Boolean.parseBoolean(cdnEnabled), + Boolean.parseBoolean(cdnLogRetention), + Long.parseLong(cdnTTL), + URI.create(cdnUri), + URI.create(cdnSslUri), + URI.create(cdnStreamingUri)); } } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java index 377a79f4ea..10547a5f06 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java @@ -33,8 +33,15 @@ public interface CloudFilesHeaders extends SwiftHeaders { public static final String ACCOUNT_TEMPORARY_URL_KEY = "X-Account-Meta-Temp-Url-Key"; public static final String CDN_ENABLED = "X-CDN-Enabled"; - public static final String CDN_REFERRER_ACL = "X-Referrer-ACL "; + public static final String CDN_LOG_RETENTION = "X-Log-Retention"; public static final String CDN_TTL = "X-TTL"; public static final String CDN_URI = "X-CDN-URI"; + public static final String CDN_SSL_URI = "X-Cdn-Ssl-Uri"; + public static final String CDN_STREAMING_URI = "X-Cdn-Streaming-Uri"; + public static final String CDN_REFERRER_ACL = "X-Referrer-ACL "; public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL"; + + public static final String CDN_CONTAINER_PURGE_OBJECT_EMAIL = "X-Purge-Email"; + public static final String CDN_WEBSITE_INDEX = "X-Container-Meta-Web-Index"; + public static final String CDN_WEBSITE_ERROR = "X-Container-Meta-Web-Error"; } diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientExpectTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientExpectTest.java index f69f2c2ccc..cd9b699e68 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientExpectTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientExpectTest.java @@ -18,7 +18,16 @@ */ package org.jclouds.cloudfiles; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; + +import org.jclouds.blobstore.ContainerNotFoundException; +import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.cloudfiles.internal.BaseCloudFilesRestClientExpectTest; +import org.jclouds.cloudfiles.reference.CloudFilesHeaders; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -30,7 +39,8 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "CloudFilesClientExpectTest") public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTest { - public void deleteContainerReturnsTrueOn200And404() { + @Test + public void testDeleteContainerReturnsTrueOn200And404() { HttpRequest deleteContainer = HttpRequest .builder() @@ -50,7 +60,194 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe CloudFilesClient clientWhenContainerDoesntExist = requestsSendResponses(initialAuth, responseWithAuth, deleteContainer, containerNotFound); assert clientWhenContainerDoesntExist.deleteContainerIfEmpty("container"); - } + @Test + public void testGetCDNMetadataWhenResponseIs2xxReturnsContainerCDNMetadata() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("HEAD") + .endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .addHeader(CloudFilesHeaders.CDN_ENABLED, "True") + .addHeader(CloudFilesHeaders.CDN_LOG_RETENTION, "True") + .addHeader(CloudFilesHeaders.CDN_TTL, "259200") + .addHeader(CloudFilesHeaders.CDN_URI, "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com") + .addHeader(CloudFilesHeaders.CDN_SSL_URI, "https://e9f6fe92d217dc013369-36c33e76d676c80251b3c13ecb603b67.ssl.cf1.rackcdn.com") + .addHeader(CloudFilesHeaders.CDN_STREAMING_URI, "http://0e79346bc0a2564dcc5e-36c33e76d676c80251b3c13ecb603b67.r19.stream.cf1.rackcdn.com") + .statusCode(204) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + ContainerCDNMetadata containerCDNMetadata = cdnContainerClient.getCDNMetadata("container"); + assertTrue(containerCDNMetadata.isCDNEnabled()); + assertTrue(containerCDNMetadata.isLogRetention()); + assertEquals(containerCDNMetadata.getTTL(), 259200); + assertEquals(containerCDNMetadata.getCDNUri().toString(), "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com"); + assertEquals(containerCDNMetadata.getCDNSslUri().toString(), "https://e9f6fe92d217dc013369-36c33e76d676c80251b3c13ecb603b67.ssl.cf1.rackcdn.com"); + assertEquals(containerCDNMetadata.getCDNStreamingUri().toString(), "http://0e79346bc0a2564dcc5e-36c33e76d676c80251b3c13ecb603b67.r19.stream.cf1.rackcdn.com"); + } + + @Test + public void testGetCDNMetadataWhenResponseIs404ReturnsNull() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("HEAD") + .endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(404) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + assertNull(cdnContainerClient.getCDNMetadata("container")); + } + + @Test + public void testUpdateCDNMetadataWhenResponseIs2xxReturnsURI() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("POST") + .endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader(CloudFilesHeaders.CDN_LOG_RETENTION, "true") + .addHeader(CloudFilesHeaders.CDN_TTL, "259200") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .addHeader(CloudFilesHeaders.CDN_ENABLED, "True") + .addHeader(CloudFilesHeaders.CDN_LOG_RETENTION, "True") + .addHeader(CloudFilesHeaders.CDN_TTL, "259200") + .addHeader(CloudFilesHeaders.CDN_URI, "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com") + .addHeader(CloudFilesHeaders.CDN_SSL_URI, "https://e9f6fe92d217dc013369-36c33e76d676c80251b3c13ecb603b67.ssl.cf1.rackcdn.com") + .addHeader(CloudFilesHeaders.CDN_STREAMING_URI, "http://0e79346bc0a2564dcc5e-36c33e76d676c80251b3c13ecb603b67.r19.stream.cf1.rackcdn.com") + .statusCode(204) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + URI cdnURI = cdnContainerClient.updateCDN("container", 259200, true); + assertEquals(cdnURI.toString(), "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com"); + } + + @Test(expectedExceptions = ContainerNotFoundException.class) + public void testUpdateCDNMetadataWhenResponseIs404ThrowsException() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("POST") + .endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader(CloudFilesHeaders.CDN_LOG_RETENTION, "true") + .addHeader(CloudFilesHeaders.CDN_TTL, "259200") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(404) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + cdnContainerClient.updateCDN("container", 259200, true); + } + + @Test + public void testPurgeCDNObjectWhenResponseIs2xxReturnsTrue() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("DELETE") + .endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container/foo.txt") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(204) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + assertTrue(cdnContainerClient.purgeCDNObject("container", "foo.txt")); + } + + @Test + public void testSetCDNStaticWebsiteIndexWhenResponseIs2xxReturnsTrue() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("POST") + .endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader(CloudFilesHeaders.CDN_WEBSITE_INDEX, "index.html") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(204) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + assertTrue(cdnContainerClient.setCDNStaticWebsiteIndex("container", "index.html")); + } + + @Test(expectedExceptions = ContainerNotFoundException.class) + public void testSetCDNStaticWebsiteIndexWhenResponseIs404ThrowsException() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("POST") + .endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader(CloudFilesHeaders.CDN_WEBSITE_INDEX, "index.html") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(404) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + cdnContainerClient.setCDNStaticWebsiteIndex("container", "index.html"); + } + + @Test + public void testSetCDNStaticWebsiteErrorWhenResponseIs2xxReturnsTrue() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("POST") + .endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader(CloudFilesHeaders.CDN_WEBSITE_ERROR, "error.html") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(204) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + assertTrue(cdnContainerClient.setCDNStaticWebsiteError("container", "error.html")); + } + + @Test(expectedExceptions = ContainerNotFoundException.class) + public void testSetCDNStaticWebsiteErrorWhenResponseIs404ThrowsException() { + HttpRequest cdnContainerRequest = HttpRequest.builder() + .method("POST") + .endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container") + .addHeader(CloudFilesHeaders.CDN_WEBSITE_ERROR, "error.html") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse cdnContainerResponse = HttpResponse.builder() + .statusCode(404) + .build(); + + CloudFilesClient cdnContainerClient = requestsSendResponses( + initialAuth, responseWithAuth, cdnContainerRequest, cdnContainerResponse); + + cdnContainerClient.setCDNStaticWebsiteError("container", "error.html"); + } } \ No newline at end of file diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java index b39533b149..b7a22c9eae 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientLiveTest.java @@ -27,6 +27,7 @@ import java.util.Set; import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.cloudfiles.options.ListCdnContainerOptions; import org.jclouds.openstack.swift.CommonSwiftClientLiveTest; +import org.jclouds.openstack.swift.domain.ContainerMetadata; import org.jclouds.openstack.swift.domain.SwiftObject; import org.testng.annotations.Test; @@ -80,16 +81,23 @@ public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest= 1); cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); + final boolean cdnEnabled = cdnMetadata.isCDNEnabled(); + final boolean logRetention = cdnMetadata.isLogRetention(); final long initialTTL = cdnMetadata.getTTL(); - assertTrue(cdnMetadataList.contains(new ContainerCDNMetadata(containerNameWithCDN, true, initialTTL, cdnUri))); + final URI cdnSslUri = cdnMetadata.getCDNSslUri(); + final URI cdnStreamingUri = cdnMetadata.getCDNStreamingUri(); + assertTrue(cdnMetadataList.contains(new ContainerCDNMetadata( + containerNameWithCDN, cdnEnabled, logRetention, initialTTL, cdnUri, cdnSslUri, cdnStreamingUri))); + + // Test listing with options cdnMetadataList = getApi().listCDNContainers(ListCdnContainerOptions.Builder.enabledOnly()); assertTrue(Iterables.all(cdnMetadataList, new Predicate() { @@ -113,10 +128,9 @@ public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest emails = ImmutableList.of("foo@bar.com", "bar@foo.com"); + + HttpRequest request = HttpRequest.builder().method("DELETE").endpoint("http://localhost").build(); + BindIterableToHeadersWithPurgeCDNObjectEmail binder = + injector.getInstance(BindIterableToHeadersWithPurgeCDNObjectEmail.class); + + HttpRequest actualRequest = binder.bindToRequest(request, emails); + HttpRequest expectedRequest = HttpRequest.builder() + .method("DELETE") + .endpoint("http://localhost") + .addHeader(CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL, "foo@bar.com, bar@foo.com") + .build(); + + assertEquals(actualRequest, expectedRequest); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullListIsBad() { + HttpRequest request = HttpRequest.builder().method("DELETE").endpoint("http://localhost").build(); + BindIterableToHeadersWithPurgeCDNObjectEmail binder = + injector.getInstance(BindIterableToHeadersWithPurgeCDNObjectEmail.class); + + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullRequestIsBad() { + List emails = ImmutableList.of("foo@bar.com", "bar@foo.com"); + BindIterableToHeadersWithPurgeCDNObjectEmail binder = + injector.getInstance(BindIterableToHeadersWithPurgeCDNObjectEmail.class); + + binder.bindToRequest(null, emails); + } +} diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java index 42837baebf..235fb278d4 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java @@ -51,12 +51,32 @@ public class ParseContainerCDNMetadataListFromJsonResponseTest { InputStream is = getClass().getResourceAsStream("/test_list_cdn.json"); Set expects = ImmutableSortedSet.of( - - new ContainerCDNMetadata("adriancole-blobstore.testCDNOperationsContainerWithCDN", false, 3600, URI - .create("http://c0354712.cdn.cloudfiles.rackspacecloud.com")), new ContainerCDNMetadata( - "adriancole-blobstore5", true, 28800, URI.create("http://c0404671.cdn.cloudfiles.rackspacecloud.com")), - new ContainerCDNMetadata("adriancole-cfcdnint.testCDNOperationsContainerWithCDN", false, 3600, URI - .create("http://c0320431.cdn.cloudfiles.rackspacecloud.com"))); + new ContainerCDNMetadata( + "adriancole-blobstore.testCDNOperationsContainerWithCDN", + false, + false, + 3600, + URI.create("http://c0354712.cdn.cloudfiles.rackspacecloud.com"), + URI.create("https://c0354712.cdn.ssl.cloudfiles.rackspacecloud.com"), + URI.create("http://c0354712.cdn.stream.cloudfiles.rackspacecloud.com")), + new ContainerCDNMetadata( + "adriancole-blobstore5", + true, + false, + 28800, + URI.create("http://c0404671.cdn.cloudfiles.rackspacecloud.com"), + URI.create("https://c0404671.cdn.ssl.cloudfiles.rackspacecloud.com"), + URI.create("http://c0404671.cdn.stream.cloudfiles.rackspacecloud.com")), + new ContainerCDNMetadata( + "adriancole-cfcdnint.testCDNOperationsContainerWithCDN", + false, + false, + 3600, + URI.create("http://c0320431.cdn.cloudfiles.rackspacecloud.com"), + URI.create("https://c0320431.cdn.ssl.cloudfiles.rackspacecloud.com"), + URI.create("http://c0320431.cdn.stream.cloudfiles.rackspacecloud.com")) + ); + ParseJson> parser = i.getInstance(Key .get(new TypeLiteral>>() { })); diff --git a/apis/cloudfiles/src/test/resources/test_list_cdn.json b/apis/cloudfiles/src/test/resources/test_list_cdn.json index bea7be869e..9562816160 100644 --- a/apis/cloudfiles/src/test/resources/test_list_cdn.json +++ b/apis/cloudfiles/src/test/resources/test_list_cdn.json @@ -1,5 +1,35 @@ [ -{"name":"adriancole-blobstore.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"http://c0354712.cdn.cloudfiles.rackspacecloud.com","referrer_acl":"","useragent_acl":"", "log_retention":"false"}, -{"name":"adriancole-blobstore5","cdn_enabled":"true","ttl":28800,"cdn_uri":"http://c0404671.cdn.cloudfiles.rackspacecloud.com","referrer_acl":"","useragent_acl":"", "log_retention":"false"}, -{"name":"adriancole-cfcdnint.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"http://c0320431.cdn.cloudfiles.rackspacecloud.com","referrer_acl":"","useragent_acl":"", "log_retention":"false"} + { + "name":"adriancole-blobstore.testCDNOperationsContainerWithCDN", + "cdn_enabled":"false", + "log_retention":"false", + "ttl":3600, + "cdn_uri":"http://c0354712.cdn.cloudfiles.rackspacecloud.com", + "cdn_ssl_uri":"https://c0354712.cdn.ssl.cloudfiles.rackspacecloud.com", + "cdn_streaming_uri":"http://c0354712.cdn.stream.cloudfiles.rackspacecloud.com", + "referrer_acl":"", + "useragent_acl":"" + }, + { + "name":"adriancole-blobstore5", + "cdn_enabled":"true", + "log_retention":"false", + "ttl":28800, + "cdn_uri":"http://c0404671.cdn.cloudfiles.rackspacecloud.com", + "cdn_ssl_uri":"https://c0404671.cdn.ssl.cloudfiles.rackspacecloud.com", + "cdn_streaming_uri":"http://c0404671.cdn.stream.cloudfiles.rackspacecloud.com", + "referrer_acl":"", + "useragent_acl":"" + }, + { + "name":"adriancole-cfcdnint.testCDNOperationsContainerWithCDN", + "cdn_enabled":"false", + "log_retention":"false", + "ttl":3600, + "cdn_uri":"http://c0320431.cdn.cloudfiles.rackspacecloud.com", + "cdn_ssl_uri":"https://c0320431.cdn.ssl.cloudfiles.rackspacecloud.com", + "cdn_streaming_uri":"http://c0320431.cdn.stream.cloudfiles.rackspacecloud.com", + "referrer_acl":"", + "useragent_acl":"" + } ] \ No newline at end of file diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java index d1a214ea2a..23fbe2d8ec 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientLiveTest.java @@ -339,7 +339,7 @@ public abstract class CommonSwiftClientLiveTest ext assert contentType.startsWith("text/plain") || "application/x-www-form-urlencoded".equals(contentType): contentType; } - private SwiftObject newSwiftObject(String data, String key) throws IOException { + protected SwiftObject newSwiftObject(String data, String key) throws IOException { SwiftObject object = getApi().newSwiftObject(); object.getInfo().setName(key); object.setPayload(data); From 26f4ccdbb660a95ca4be7d64c86c225ce335013e Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 11 Sep 2012 23:30:03 -0700 Subject: [PATCH 12/60] more progress on sqs --- labs/sqs/pom.xml | 2 +- .../src/main/java/org/jclouds/sqs/SQSApi.java | 112 +++++++---- .../java/org/jclouds/sqs/SQSApiMetadata.java | 2 +- .../java/org/jclouds/sqs/SQSAsyncApi.java | 86 +++++++- .../java/org/jclouds/sqs/domain/Message.java | 186 ++++++++++++++++++ .../jclouds/sqs/domain/MessageIdAndMD5.java | 119 +++++++++++ .../sqs/options/CreateQueueOptions.java | 135 ++++++++++--- .../sqs/options/ListQueuesOptions.java | 5 - .../sqs/options/ReceiveMessageOptions.java | 164 +++++++++++++++ .../sqs/options/SendMessageOptions.java | 108 ++++++++++ .../jclouds/sqs/reference/SQSParameters.java | 4 +- .../org/jclouds/sqs/xml/MessageHandler.java | 77 ++++++++ .../xml/ReceiveMessageResponseHandler.java | 87 ++++++++ ....java => RegexMessageIdAndMD5Handler.java} | 18 +- .../org/jclouds/sqs/SQSApiExpectTest.java | 113 +++++++++++ .../java/org/jclouds/sqs/SQSApiLiveTest.java | 50 ++--- .../java/org/jclouds/sqs/SQSAsyncApiTest.java | 154 --------------- .../sqs/internal/BaseSQSApiExpectTest.java | 29 +++ .../sqs/internal/BaseSQSApiLiveTest.java | 25 +++ .../sqs/internal/BaseSQSExpectTest.java} | 37 ++-- .../sqs/options/CreateQueueOptionsTest.java | 67 +++---- .../options/ReceiveMessageOptionsTest.java | 39 ++++ .../sqs/options/SendMessageOptionsTest.java | 51 +++++ .../sqs/parse/ReceiveMessageResponseTest.java | 70 +++++++ .../sqs/parse/SendMessageResponseTest.java | 60 ++++++ labs/sqs/src/test/resources/create_queue.xml | 9 + labs/sqs/src/test/resources/list_queues.xml | 2 +- labs/sqs/src/test/resources/messages.xml | 39 ++++ labs/sqs/src/test/resources/send_message.xml | 10 + 29 files changed, 1514 insertions(+), 346 deletions(-) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/Message.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java rename labs/sqs/src/main/java/org/jclouds/sqs/xml/{RegexMD5Handler.java => RegexMessageIdAndMD5Handler.java} (71%) create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java delete mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java rename labs/sqs/src/{main/java/org/jclouds/sqs/xml/MD5Handler.java => test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java} (51%) create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java create mode 100644 labs/sqs/src/test/resources/create_queue.xml create mode 100644 labs/sqs/src/test/resources/messages.xml create mode 100644 labs/sqs/src/test/resources/send_message.xml diff --git a/labs/sqs/pom.xml b/labs/sqs/pom.xml index 9b94080ef8..43f9c737c9 100644 --- a/labs/sqs/pom.xml +++ b/labs/sqs/pom.xml @@ -35,7 +35,7 @@ https://sqs.us-east-1.amazonaws.com - 2009-02-01 + 2011-10-01 ${test.aws.identity} ${test.aws.credential} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index a9209f67ad..b164c8bc7c 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -24,81 +24,97 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.domain.MessageIdAndMD5; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; - -import com.google.common.hash.HashCode; +import org.jclouds.sqs.options.ReceiveMessageOptions; +import org.jclouds.sqs.options.SendMessageOptions; /** * Provides access to SQS via their REST API. *

* + * @see SQSAsyncApi * @author Adrian Cole */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface SQSApi { /** - * The ListQueues action returns a list of your queues. The maximum number of queues that can be - * returned is 1000. If you specify a value for the optional QueueNamePrefix parameter, only - * queues with a name beginning with the specified value are returned + * The ListQueues action returns a list of your queues. The maximum number of + * queues that can be returned is 1000. If you specify a value for the + * optional QueueNamePrefix parameter, only queues with a name beginning with + * the specified value are returned * * @param region * Queues are Region-specific. * @param options * specify prefix or other options * - * @see */ - Set listQueuesInRegion(@Nullable String region, ListQueuesOptions... options); + Set listQueuesInRegion(@Nullable String region); + + Set listQueuesInRegion(@Nullable String region, ListQueuesOptions options); /** * * The CreateQueue action creates a new queue. *

- * When you request CreateQueue, you provide a name for the queue. To successfully create a new - * queue, you must provide a name that is unique within the scope of your own queues. If you - * provide the name of an existing queue, a new queue isn't created and an error isn't returned. - * Instead, the request succeeds and the queue URL for the existing queue is returned (for more - * information about queue URLs, see Queue and Message Identifiers in the Amazon SQS Developer - * Guide). Exception: if you provide a value for DefaultVisibilityTimeout that is different from - * the value for the existing queue, you receive an error. + * When you request CreateQueue, you provide a name for the queue. To + * successfully create a new queue, you must provide a name that is unique + * within the scope of your own queues. If you provide the name of an + * existing queue, a new queue isn't created and an error isn't returned. + * Instead, the request succeeds and the queue URL for the existing queue is + * returned (for more information about queue URLs, see Queue and Message + * Identifiers in the Amazon SQS Developer Guide). Exception: if you provide + * a value for DefaultVisibilityTimeout that is different from the value for + * the existing queue, you receive an error. *

Note

* - * If you delete a queue, you must wait at least 60 seconds before creating a queue with the same - * name. + * If you delete a queue, you must wait at least 60 seconds before creating a + * queue with the same name. *

- * A default value for the queue's visibility timeout (30 seconds) is set when the queue is - * created. You can override this value with the DefaultVisibilityTimeout request parameter. For - * more information, see Visibility Timeout in the Amazon SQS Developer Guide. + * A default value for the queue's visibility timeout (30 seconds) is set + * when the queue is created. You can override this value with the + * DefaultVisibilityTimeout request parameter. For more information, see + * Visibility Timeout in the Amazon SQS Developer Guide. * * @param region * Queues are Region-specific. * @param queueName - * The name to use for the queue created. Constraints: Maximum 80 characters; - * alphanumeric characters, hyphens (-), and underscores (_) are allowed. + * The name to use for the queue created. Constraints: Maximum 80 + * characters; alphanumeric characters, hyphens (-), and + * underscores (_) are allowed. * @param options * like the visibility timeout (in seconds) to use for this queue. */ - URI createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions... options); + URI createQueueInRegion(@Nullable String region, String queueName); + + URI createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions options); /** - * The DeleteQueue action deletes the queue specified by the queue URL, regardless of whether the - * queue is empty. If the specified queue does not exist, SQS returns a successful response.

+ * The DeleteQueue action deletes the queue specified by the queue URL, + * regardless of whether the queue is empty. If the specified queue does not + * exist, SQS returns a successful response.

* Caution

* - * Use DeleteQueue with care; once you delete your queue, any messages in the queue are no longer - * available. + * Use DeleteQueue with care; once you delete your queue, any messages in the + * queue are no longer available. *

- * When you delete a queue, the deletion process takes up to 60 seconds. Requests you send - * involving that queue during the 60 seconds might succeed. For example, a SendMessage request - * might succeed, but after the 60 seconds, the queue and that message you sent no longer exist. - * Also, when you delete a queue, you must wait at least 60 seconds before creating a queue with - * the same name. + * When you delete a queue, the deletion process takes up to 60 seconds. + * Requests you send involving that queue during the 60 seconds might + * succeed. For example, a SendMessage request might succeed, but after the + * 60 seconds, the queue and that message you sent no longer exist. Also, + * when you delete a queue, you must wait at least 60 seconds before creating + * a queue with the same name. *

- * We reserve the right to delete queues that have had no activity for more than 30 days. For - * more information, see About SQS Queues in the Amazon SQS Developer Guide. + * We reserve the right to delete queues that have had no activity for more + * than 30 days. For more information, see About SQS Queues in the Amazon SQS + * Developer Guide. * * @param queue * queue you want to delete @@ -106,24 +122,36 @@ public interface SQSApi { void deleteQueue(URI queue); /** - * The SendMessage action delivers a message to the specified queue. The maximum allowed message - * size is 8 KB. + * The SendMessage action delivers a message to the specified queue. The + * maximum allowed message size is 8 KB. *

* Important *

- * The following list shows the characters (in Unicode) allowed in your message, according to the - * W3C XML specification (for more information, go to http://www.w3.org/TR/REC-xml/#charsets). If - * you send any characters not included in the list, your request will be rejected. + * The following list shows the characters (in Unicode) allowed in your + * message, according to the W3C XML specification (for more information, go + * to http://www.w3.org/TR/REC-xml/#charsets). If you send any characters not + * included in the list, your request will be rejected. *

- * #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] + * #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to + * #x10FFFF] * * @param queue * queue you want to send to * * @param message - * The message to send. Type: String maximum 8 KB in size. For a list of allowed - * characters, see the preceding important note + * The message to send. Type: String maximum 8 KB in size. For a + * list of allowed characters, see the preceding important note * @return md5 of the content sent */ - HashCode sendMessage(URI queue, String message); + MessageIdAndMD5 sendMessage(URI queue, String message); + + MessageIdAndMD5 sendMessage(URI queue, String message, SendMessageOptions options); + + Message receiveMessage(URI queue); + + Message receiveMessage(URI queue, ReceiveMessageOptions options); + + Set receiveMessages(URI queue, int max); + + Set receiveMessages(URI queue, int max, ReceiveMessageOptions options); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java index 7c73d9ff76..6c23ba0dba 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java @@ -75,7 +75,7 @@ public class SQSApiMetadata extends BaseRestApiMetadata { .name("Amazon Simple Queue Service API") .identityName("Access Key ID") .credentialName("Secret Access Key") - .version("2009-02-01") + .version("2011-10-01") .defaultProperties(SQSApiMetadata.defaultProperties()) .defaultEndpoint("https://sqs.us-east-1.amazonaws.com") .documentation(URI.create("http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference")) diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index 20f27d3614..cdb88d9275 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -37,13 +37,19 @@ import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.domain.MessageIdAndMD5; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; +import org.jclouds.sqs.options.ReceiveMessageOptions; +import org.jclouds.sqs.options.SendMessageOptions; +import org.jclouds.sqs.xml.MessageHandler; +import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; -import org.jclouds.sqs.xml.RegexMD5Handler; +import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; import org.jclouds.sqs.xml.RegexQueueHandler; -import com.google.common.hash.HashCode; import com.google.common.util.concurrent.ListenableFuture; /** @@ -57,6 +63,16 @@ import com.google.common.util.concurrent.ListenableFuture; @VirtualHost public interface SQSAsyncApi { + /** + * @see SQSApi#listQueuesInRegion + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ListQueues") + @ResponseParser(RegexListQueuesResponseHandler.class) + ListenableFuture> listQueuesInRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + /** * @see SQSApi#listQueuesInRegion */ @@ -66,7 +82,7 @@ public interface SQSAsyncApi { @ResponseParser(RegexListQueuesResponseHandler.class) ListenableFuture> listQueuesInRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - ListQueuesOptions... options); + ListQueuesOptions options); /** * @see SQSApi#createQueueInRegion @@ -77,7 +93,18 @@ public interface SQSAsyncApi { @ResponseParser(RegexQueueHandler.class) ListenableFuture createQueueInRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - @FormParam("QueueName") String queueName, CreateQueueOptions... options); + @FormParam("QueueName") String queueName); + + /** + * @see SQSApi#createQueueInRegion + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "CreateQueue") + @ResponseParser(RegexQueueHandler.class) + ListenableFuture createQueueInRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, + @FormParam("QueueName") String queueName, CreateQueueOptions options); /** * @see SQSApi#deleteQueue @@ -93,7 +120,54 @@ public interface SQSAsyncApi { @POST @Path("/") @FormParams(keys = ACTION, values = "SendMessage") - @ResponseParser(RegexMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message); + @ResponseParser(RegexMessageIdAndMD5Handler.class) + ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message); + + /** + * @see SQSApi#sendMessage + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessage") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message, + SendMessageOptions options); + + /** + * @see SQSApi#receiveMessage + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(MessageHandler.class) + ListenableFuture receiveMessage(@EndpointParam URI queue); + + /** + * @see SQSApi#receiveMessage + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(MessageHandler.class) + ListenableFuture receiveMessage(@EndpointParam URI queue, ReceiveMessageOptions options); + + /** + * @see SQSApi#receiveMessages + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(ReceiveMessageResponseHandler.class) + ListenableFuture> receiveMessages(@EndpointParam URI queue, @FormParam("MaxNumberOfMessages") int max); + + /** + * @see SQSApi#receiveMessages + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(ReceiveMessageResponseHandler.class) + ListenableFuture> receiveMessages(@EndpointParam URI queue, @FormParam("MaxNumberOfMessages") int max, + ReceiveMessageOptions options); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/Message.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/Message.java new file mode 100644 index 0000000000..37d0c9168b --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/Message.java @@ -0,0 +1,186 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableMap; +import com.google.common.hash.HashCode; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class Message { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromMessage(this); + } + + public static class Builder { + + private String id; + private String body; + private String receiptHandle; + private HashCode md5; + private ImmutableMap.Builder attributes = ImmutableMap. builder(); + + /** + * @see Message#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see Message#getBody() + */ + public Builder body(String body) { + this.body = body; + return this; + } + + /** + * @see Message#getReceiptHandle() + */ + public Builder receiptHandle(String receiptHandle) { + this.receiptHandle = receiptHandle; + return this; + } + + /** + * @see Message#getMD5() + */ + public Builder md5(HashCode md5) { + this.md5 = md5; + return this; + } + + /** + * @see Message#getAttributes() + */ + public Builder attributes(Map attributes) { + this.attributes.putAll(checkNotNull(attributes, "attributes")); + return this; + } + + /** + * @see Message#getAttributes() + */ + public Builder addAttribute(String name, String value) { + this.attributes.put(checkNotNull(name, "name"), checkNotNull(value, "value")); + return this; + } + + public Message build() { + return new Message(id, body, receiptHandle, md5, attributes.build()); + } + + public Builder fromMessage(Message in) { + return id(in.getId()).body(in.getBody()).receiptHandle(in.getReceiptHandle()).md5(in.getMD5()) + .attributes(in.getAttributes()); + } + } + + private final String id; + private final String body; + private final String receiptHandle; + private final HashCode md5; + private final Map attributes; + + private Message(String id, String body, String receiptHandle, HashCode md5, Map attributes) { + this.id = checkNotNull(id, "id"); + this.body = checkNotNull(body, "body of %s", id); + this.receiptHandle = checkNotNull(receiptHandle, "receiptHandle of %s", id); + this.md5 = checkNotNull(md5, "md5 of %s", id); + this.attributes = ImmutableMap.copyOf(checkNotNull(attributes, "attributes of %s", id)); + } + + /** + * The message's SQS-assigned ID. + */ + public String getId() { + return id; + } + + /** + * The message's contents (not URL encoded) + */ + public String getBody() { + return body; + } + + /** + * A string associated with a specific instance of receiving the message. + */ + public String getReceiptHandle() { + return receiptHandle; + } + + /** + * An MD5 digest of the non-URL-encoded message body string + */ + public HashCode getMD5() { + return md5; + } + + /** + * Attributes of the queue + */ + public Map getAttributes() { + return attributes; + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Message that = Message.class.cast(obj); + return Objects.equal(this.id, that.id); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("body", body).add("md5", md5) + .add("receiptHandle", receiptHandle).add("attributes", attributes).toString(); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java new file mode 100644 index 0000000000..897f69d332 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java @@ -0,0 +1,119 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.hash.HashCode; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class MessageIdAndMD5 { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromMessage(this); + } + + public static class Builder { + + private String id; + private HashCode md5; + + /** + * @see MessageIdAndMD5#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see MessageIdAndMD5#getMD5() + */ + public Builder md5(HashCode md5) { + this.md5 = md5; + return this; + } + + public MessageIdAndMD5 build() { + return new MessageIdAndMD5(id, md5); + } + + public Builder fromMessage(MessageIdAndMD5 in) { + return id(in.getId()).md5(in.getMD5()); + } + } + + private final String id; + private final HashCode md5; + + private MessageIdAndMD5(String id, HashCode md5) { + this.id = checkNotNull(id, "id"); + this.md5 = checkNotNull(md5, "md5 of %s", id); + } + + /** + * The message's SQS-assigned ID. + */ + public String getId() { + return id; + } + + /** + * An MD5 digest of the non-URL-encoded message body string + */ + public HashCode getMD5() { + return md5; + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + MessageIdAndMD5 that = MessageIdAndMD5.class.cast(obj); + return Objects.equal(this.id, that.id); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("md5", md5).toString(); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java b/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java index 45418883d8..7cd0694931 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java @@ -18,56 +18,131 @@ */ package org.jclouds.sqs.options; +import java.util.Map; +import java.util.Map.Entry; + import org.jclouds.http.options.BaseHttpRequestOptions; +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Multimap; + /** - * Contains options supported in the Form API for the CreateQueue operation.

- * Usage

The recommended way to instantiate a CreateQueueOptions object is to statically import - * CreateQueueOptions.Builder.* and invoke a static creation method followed by an instance mutator - * (if needed): - *

- * - * import static org.jclouds.sqs.options.CreateQueueOptions.Builder.* - *

- * SQSApi connection = // get connection - * Queue queue = connection.createQueueInRegion(defaultVisibilityTimeout("foo")); - * + * Options used to receive a message from a queue. + * + * @see docs * * @author Adrian Cole - * @see */ -public class CreateQueueOptions extends BaseHttpRequestOptions { +public class CreateQueueOptions extends BaseHttpRequestOptions implements Cloneable { + + private ImmutableMap.Builder attributes = ImmutableMap. builder(); /** - * A default value for the queue's visibility timeout (30 seconds) is set when the queue is - * created. You can override this value with the DefaultVisibilityTimeout request parameter. For - * more information, see Visibility Timeout in the Amazon SQS Developer Guide. + * The duration (in seconds) that the received messages are hidden from + * subsequent retrieve requests after being retrieved by a CreateQueue + * request. * - * @param seconds - * The visibility timeout (in seconds) to use for this queue. 0 to 43200 (maximum 12 - * hours); Default: 30 seconds + * @param visibilityTimeout + * Constraints: 0 to 43200 (maximum 12 hours) + * + * Default: The visibility timeout for the queue */ - public CreateQueueOptions defaultVisibilityTimeout(int seconds) { - //TODO validate - formParameters.put("DefaultVisibilityTimeout", seconds+""); + public CreateQueueOptions visibilityTimeout(int visibilityTimeout) { + return attribute("VisibilityTimeout", visibilityTimeout + ""); + } + + /** + */ + public CreateQueueOptions attributes(Map attributes) { + this.attributes = ImmutableMap. builder().putAll(attributes); return this; } - public String getRestorableBy() { - return getFirstFormOrNull("DefaultVisibilityTimeout"); + /** + * @see #attributes + */ + public CreateQueueOptions attribute(String name, String value) { + this.attributes.put(name, value); + return this; } public static class Builder { /** - * @see CreateQueueOptions#defaultVisibilityTimeout(int ) + * @see CreateQueueOptions#visibilityTimeout */ - public static CreateQueueOptions defaultVisibilityTimeout(int seconds) { - CreateQueueOptions options = new CreateQueueOptions(); - return options.defaultVisibilityTimeout(seconds); + public static CreateQueueOptions visibilityTimeout(Integer visibilityTimeout) { + return new CreateQueueOptions().visibilityTimeout(visibilityTimeout); } + /** + * @see CreateQueueOptions#attribute + */ + public static CreateQueueOptions attribute(String name, String value) { + return new CreateQueueOptions().attribute(name, value); + } + + /** + * @see CreateQueueOptions#attributes + */ + public static CreateQueueOptions attributes(Map attributes) { + return new CreateQueueOptions().attributes(attributes); + } + } + + @Override + public Multimap buildFormParameters() { + Multimap params = super.buildFormParameters(); + ImmutableMap attributes = this.attributes.build(); + if (attributes.size() > 0) { + int nameIndex = 1; + for (Entry attribute : attributes.entrySet()) { + params.put("Attribute." + nameIndex + ".Name", attribute.getKey()); + params.put("Attribute." + nameIndex + ".Value", attribute.getValue()); + nameIndex++; + } + } + return params; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(attributes); + } + + @Override + public CreateQueueOptions clone() { + return new CreateQueueOptions().attributes(attributes.build()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CreateQueueOptions other = CreateQueueOptions.class.cast(obj); + return Objects.equal(this.attributes, other.attributes); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + ImmutableMap attributes = this.attributes.build(); + return Objects.toStringHelper(this).omitNullValues().add("attributes", attributes.size() > 0 ? attributes : null) + .toString(); } } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java b/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java index 99cb158d0e..851c61fa2b 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java @@ -49,15 +49,10 @@ public class ListQueuesOptions extends BaseHttpRequestOptions { * allowed. */ public ListQueuesOptions queuePrefix(String prefix) { - //TODO validate formParameters.put("QueueNamePrefix", prefix); return this; } - public String getRestorableBy() { - return getFirstFormOrNull("QueueNamePrefix"); - } - public static class Builder { /** diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java b/labs/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java new file mode 100644 index 0000000000..dcbd6ba3ba --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java @@ -0,0 +1,164 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; + +/** + * Options used to receive a message from a queue. + * + * @see docs + * + * @author Adrian Cole + */ +public class ReceiveMessageOptions extends BaseHttpRequestOptions implements Cloneable { + + private Integer visibilityTimeout; + private ImmutableSet.Builder attributes = ImmutableSet. builder(); + + /** + * The duration (in seconds) that the received messages are hidden from + * subsequent retrieve requests after being retrieved by a ReceiveMessage + * request. + * + * @param visibilityTimeout + * Constraints: 0 to 43200 (maximum 12 hours) + * + * Default: The visibility timeout for the queue + */ + public ReceiveMessageOptions visibilityTimeout(Integer visibilityTimeout) { + this.visibilityTimeout = visibilityTimeout; + return this; + } + + /** + * The attribute you want to get. + * + * All - returns all values. + * + * SenderId - returns the AWS account number (or the IP address, if anonymous + * access is allowed) of the sender. + * + * SentTimestamp - returns the time when the message was sent (epoch time in + * milliseconds). + * + * ApproximateReceiveCount - returns the number of times a message has been + * received but not deleted. + * + * ApproximateFirstReceiveTimestamp - returns the time when the message was + * first received (epoch time in milliseconds). + */ + public ReceiveMessageOptions attributes(Iterable attributes) { + this.attributes = ImmutableSet. builder().addAll(attributes); + return this; + } + + /** + * @see #attributes + */ + public ReceiveMessageOptions attribute(String attribute) { + this.attributes.add(attribute); + return this; + } + + public static class Builder { + + /** + * @see ReceiveMessageOptions#visibilityTimeout + */ + public static ReceiveMessageOptions visibilityTimeout(Integer visibilityTimeout) { + return new ReceiveMessageOptions().visibilityTimeout(visibilityTimeout); + } + + /** + * @see ReceiveMessageOptions#attribute + */ + public static ReceiveMessageOptions attribute(String attribute) { + return new ReceiveMessageOptions().attribute(attribute); + } + + /** + * @see ReceiveMessageOptions#attributes + */ + public static ReceiveMessageOptions attributes(Iterable attributes) { + return new ReceiveMessageOptions().attributes(attributes); + } + } + + @Override + public Multimap buildFormParameters() { + Multimap params = super.buildFormParameters(); + if (visibilityTimeout != null) + params.put("VisibilityTimeout", visibilityTimeout.toString()); + ImmutableSet attributes = this.attributes.build(); + if (attributes.size() > 0) { + int nameIndex = 1; + for (String attribute : attributes) { + params.put("AttributeName." + nameIndex, attribute); + nameIndex++; + } + } + return params; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(visibilityTimeout, attributes); + } + + @Override + public ReceiveMessageOptions clone() { + return new ReceiveMessageOptions().visibilityTimeout(visibilityTimeout).attributes(attributes.build()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ReceiveMessageOptions other = ReceiveMessageOptions.class.cast(obj); + return Objects.equal(this.visibilityTimeout, other.visibilityTimeout) + && Objects.equal(this.attributes, other.attributes); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + ImmutableSet attributes = this.attributes.build(); + return Objects.toStringHelper(this).omitNullValues().add("visibilityTimeout", visibilityTimeout) + .add("attributes", attributes.size() > 0 ? attributes : null).toString(); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java b/labs/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java new file mode 100644 index 0000000000..ba17cee7de --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java @@ -0,0 +1,108 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.base.Objects; +import com.google.common.collect.Multimap; + +/** + * Options used to send a message. + * + * @see docs + * + * @author Adrian Cole + */ +public class SendMessageOptions extends BaseHttpRequestOptions implements Cloneable { + + private Integer delaySeconds; + + /** + * The number of seconds to delay a specific message. Messages with a + * positive DelaySeconds value become available for processing after the + * delay time is finished. If you don't specify a value, the default value + * for the queue applies. + * + * @param delaySeconds + * from 0 to 900 (15 minutes). If this parameter is not used, the + * default value for the queue applies. + */ + public SendMessageOptions delaySeconds(Integer delaySeconds) { + this.delaySeconds = delaySeconds; + return this; + } + + public static class Builder { + + /** + * @see SendMessageOptions#delaySeconds + */ + public static SendMessageOptions delaySeconds(Integer delaySeconds) { + return new SendMessageOptions().delaySeconds(delaySeconds); + } + + } + + @Override + public Multimap buildFormParameters() { + Multimap params = super.buildFormParameters(); + if (delaySeconds != null) + params.put("DelaySeconds", delaySeconds.toString()); + return params; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(delaySeconds); + } + + @Override + public SendMessageOptions clone() { + return new SendMessageOptions().delaySeconds(delaySeconds); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SendMessageOptions other = SendMessageOptions.class.cast(obj); + return Objects.equal(this.delaySeconds, other.delaySeconds); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("delaySeconds", delaySeconds).toString(); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java b/labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java index 6e2a491095..a50659b8cb 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java @@ -21,7 +21,7 @@ package org.jclouds.sqs.reference; /** * Configuration properties and constants used in SQS connections. * - * @see * @author Adrian Cole */ @@ -33,7 +33,7 @@ public interface SQSParameters { public static final String ACTION = "Action"; /** - * The API version to use, as specified in the WSDL. For example: 2009-02-01. + * The API version to use, as specified in the WSDL. For example: 2011-10-01. */ public static final String VERSION = "Version"; diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java new file mode 100644 index 0000000000..3a972d5ffe --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.sqs.domain.Message; + +import com.google.common.hash.HashCodes; + +/** + * @see + * + * @author Adrian Cole + */ +public class MessageHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private Message.Builder builder = Message.builder(); + private String name; + + @Override + public Message getResult() { + try { + return builder.build(); + } catch (NullPointerException e) { + return null; + } finally { + builder = Message.builder(); + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals("MessageId")) { + builder.id(currentOrNull(currentText)); + } else if (qName.equals("ReceiptHandle")) { + builder.receiptHandle(currentOrNull(currentText)); + } else if (qName.equals("MD5OfBody")) { + builder.md5(HashCodes.fromBytes(CryptoStreams.hex(currentOrNull(currentText)))); + } else if (qName.equals("Body")) { + builder.body(currentOrNull(currentText)); + } else if (qName.equals("Name")) { + this.name = currentOrNull(currentText); + } else if (qName.equals("Value")) { + builder.addAttribute(this.name, currentOrNull(currentText)); + this.name = null; + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java new file mode 100644 index 0000000000..7976476acc --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java @@ -0,0 +1,87 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Set; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.sqs.domain.Message; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.inject.Inject; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { + + private final MessageHandler messageHandler; + + private Builder messages = ImmutableSet. builder(); + + private boolean inMessages; + + @Inject + public ReceiveMessageResponseHandler(MessageHandler messageHandler) { + this.messageHandler = messageHandler; + } + + @Override + public Set getResult() { + return messages.build(); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "ReceiveMessageResult")) { + inMessages = true; + } + if (inMessages) { + messageHandler.startElement(url, name, qName, attributes); + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (equalsOrSuffix(qName, "ReceiveMessageResult")) { + inMessages = false; + } else if (equalsOrSuffix(qName, "Message")) { + messages.add(messageHandler.getResult()); + } else if (inMessages) { + messageHandler.endElement(uri, name, qName); + } + } + + @Override + public void characters(char ch[], int start, int length) { + if (inMessages) { + messageHandler.characters(ch, start, length); + } + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java similarity index 71% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java rename to labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java index 4eaa3d9bef..9baf8a5531 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMD5Handler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java @@ -26,9 +26,9 @@ import javax.inject.Inject; import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.sqs.domain.MessageIdAndMD5; import com.google.common.base.Function; -import com.google.common.hash.HashCode; import com.google.common.hash.HashCodes; import com.google.inject.Singleton; @@ -39,26 +39,28 @@ import com.google.inject.Singleton; * @author Adrian Cole */ @Singleton -public class RegexMD5Handler implements Function { - Pattern pattern = Pattern.compile("([\\S&&[^<]]+)"); +public class RegexMessageIdAndMD5Handler implements Function { + Pattern pattern = Pattern.compile("([\\S&&[^<]]+)\\s*([\\S&&[^<]]+)", Pattern.DOTALL); private final ReturnStringIf2xx returnStringIf200; @Inject - RegexMD5Handler(ReturnStringIf2xx returnStringIf200) { + public RegexMessageIdAndMD5Handler(ReturnStringIf2xx returnStringIf200) { this.returnStringIf200 = returnStringIf200; } @Override - public HashCode apply(HttpResponse response) { - HashCode value = null; + public MessageIdAndMD5 apply(HttpResponse response) { String content = returnStringIf200.apply(response); if (content != null) { Matcher matcher = pattern.matcher(content); if (matcher.find()) { - value = HashCodes.fromBytes(CryptoStreams.hex(matcher.group(1))); + return MessageIdAndMD5.builder() + .id(matcher.group(1)) + .md5(HashCodes.fromBytes(CryptoStreams.hex(matcher.group(2)))) + .build(); } } - return value; + return null; } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java new file mode 100644 index 0000000000..10b636ff14 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java @@ -0,0 +1,113 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.sqs.internal.BaseSQSApiExpectTest; +import org.jclouds.sqs.parse.ReceiveMessageResponseTest; +import org.jclouds.sqs.parse.SendMessageResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "SQSApiExpectTest") +public class SQSApiExpectTest extends BaseSQSApiExpectTest { + + HttpRequest sendMessage = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessage") + .addFormParam("MessageBody", "hardyharhar") + .addFormParam("Signature", "PVzszzgIcT1xt9%2BEzGzWB2Bt8zDadBc48HsgF89AoJE%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessage, sendMessageResponse); + + assertEquals(apiWhenExist.sendMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "hardyharhar").toString(), new SendMessageResponseTest().expected().toString()); + } + + + HttpRequest receiveMessage = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ReceiveMessage") + .addFormParam("Signature", "UURXsAjggoaz5P1h2EFswRd8Ji9euHmXhHvrAmIqM1E%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testReceiveMessageWhenResponseIs2xx() throws Exception { + + HttpResponse receiveMessageResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/messages.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(receiveMessage, receiveMessageResponse); + + assertEquals( + apiWhenExist.receiveMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")) + .toString(), Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString()); + } + + + HttpRequest receiveMessages = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ReceiveMessage") + .addFormParam("MaxNumberOfMessages", "10") + .addFormParam("Signature", "pZ9B4%2BTBvQA4n0joP4t8ue5x0xmKMd9prpVLVoT%2F7qU%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testReceiveMessagesWhenResponseIs2xx() throws Exception { + + HttpResponse receiveMessagesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/messages.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(receiveMessages, receiveMessagesResponse); + + assertEquals( + apiWhenExist.receiveMessages(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), 10) + .toString(), new ReceiveMessageResponseTest().expected().toString()); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index 73116e15d8..eddb8356f8 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -23,17 +23,18 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.io.IOException; import java.net.URI; import java.util.Set; import java.util.SortedSet; import org.jclouds.aws.AWSResponseException; import org.jclouds.sqs.internal.BaseSQSApiLiveTest; +import org.jclouds.sqs.options.ReceiveMessageOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import com.google.common.base.Charsets; +import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; @@ -71,9 +72,9 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { public String createQueueInRegion(final String region, String queueName) throws InterruptedException { try { - SortedSet result = Sets.newTreeSet(context.getApi().listQueuesInRegion(region, queuePrefix(queueName))); + Set result = context.getApi().listQueuesInRegion(region, queuePrefix(queueName)); if (result.size() >= 1) { - context.getApi().deleteQueue(result.last()); + context.getApi().deleteQueue(Iterables.getLast(result)); queueName += 1;// cannot recreate a queue within 60 seconds } } catch (Exception e) { @@ -99,12 +100,21 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { return queueName; } + String message = "hardyharhar"; + HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); + @Test(dependsOnMethods = "testCreateQueue") - protected void testSendMessage() throws InterruptedException, IOException { - String message = "hardyharhar"; - HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); + protected void testSendMessage() { for (URI queue : queues) { - assertEquals(context.getApi().sendMessage(queue, message), md5); + assertEquals(context.getApi().sendMessage(queue, message).getMD5(), md5); + } + } + + @Test(dependsOnMethods = "testSendMessage") + protected void testReceiveMessage() { + for (URI queue : queues) { + assertEquals(context.getApi().receiveMessage(queue, ReceiveMessageOptions.Builder.attribute("All")).getMD5(), + md5); } } @@ -120,32 +130,6 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { }); } - private static final int INCONSISTENCY_WINDOW = 10000; - - /** - * Due to eventual consistency, container commands may not return correctly - * immediately. Hence, we will try up to the inconsistency window to see if - * the assertion completes. - */ - protected static void assertEventually(Runnable assertion) throws InterruptedException { - long start = System.currentTimeMillis(); - AssertionError error = null; - for (int i = 0; i < 30; i++) { - try { - assertion.run(); - if (i > 0) - System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start, - assertion.getClass().getSimpleName()); - return; - } catch (AssertionError e) { - error = e; - } - Thread.sleep(INCONSISTENCY_WINDOW / 30); - } - if (error != null) - throw error; - } - @AfterTest public void shutdown() { context.close(); diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java deleted file mode 100644 index 4bdc810538..0000000000 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSAsyncApiTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.lang.reflect.Array; -import java.lang.reflect.Method; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.aws.filters.FormSigner; -import org.jclouds.date.DateService; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.internal.BaseAsyncClientTest; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.sqs.config.SQSRestClientModule; -import org.jclouds.sqs.options.CreateQueueOptions; -import org.jclouds.sqs.options.ListQueuesOptions; -import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; -import org.jclouds.sqs.xml.RegexQueueHandler; -import org.testng.annotations.Test; - -import com.google.inject.Module; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code SQSAsyncApi} - * - * @author Adrian Cole - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during -// surefire -@Test(groups = "unit", testName = "SQSAsyncApiTest") -public class SQSAsyncApiTest extends BaseAsyncClientTest { - - @Override - protected ApiMetadata createApiMetadata() { - return new SQSApiMetadata(); - } - - @ConfiguresRestClient - private static final class TestSQSRestApiModule extends SQSRestClientModule { - - @Override - protected String provideTimeStamp(final DateService dateService) { - return "2009-11-08T15:54:08.897Z"; - } - } - - public void testListQueuesInRegion() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncApi.class.getMethod("listQueuesInRegion", String.class, - Array.newInstance(ListQueuesOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, (String) null); - - assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues", "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testListQueuesInRegionOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncApi.class.getMethod("listQueuesInRegion", String.class, - Array.newInstance(ListQueuesOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, null, ListQueuesOptions.Builder.queuePrefix("prefix")); - - assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix", - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testCreateQueueInRegion() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncApi.class.getMethod("createQueueInRegion", String.class, String.class, - Array.newInstance(CreateQueueOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, null, "queueName"); - - assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName", - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, RegexQueueHandler.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testCreateQueueInRegionOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SQSAsyncApi.class.getMethod("createQueueInRegion", String.class, String.class, - Array.newInstance(CreateQueueOptions.class, 0).getClass()); - HttpRequest request = processor.createRequest(method, null, "queueName", - CreateQueueOptions.Builder.defaultVisibilityTimeout(45)); - - assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, - "Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45", - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, RegexQueueHandler.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(), FormSigner.class); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } - - @Override - protected Module createModule() { - return new TestSQSRestApiModule(); - } - -} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java new file mode 100644 index 0000000000..dc92282337 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java @@ -0,0 +1,29 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.internal; + +import org.jclouds.sqs.SQSApi; + +/** + * + * @author Adrian Cole + */ +public class BaseSQSApiExpectTest extends BaseSQSExpectTest { + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index e77d9f7ab6..1d0b35e2fa 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -43,4 +43,29 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest 0) + System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start, + assertion.getClass().getSimpleName()); + return; + } catch (AssertionError e) { + error = e; + } + Thread.sleep(INCONSISTENCY_WINDOW / 30); + } + if (error != null) + throw error; + } } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java similarity index 51% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java rename to labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java index f0d1f3e4be..6896a1ad65 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/MD5Handler.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java @@ -16,35 +16,36 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs.xml; +package org.jclouds.sqs.internal; -import org.jclouds.crypto.CryptoStreams; -import org.jclouds.http.functions.ParseSax; +import org.jclouds.date.DateService; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.internal.BaseRestApiExpectTest; +import org.jclouds.sqs.config.SQSRestClientModule; + +import com.google.inject.Module; /** * - * @see * @author Adrian Cole */ -public class MD5Handler extends ParseSax.HandlerWithResult { +public class BaseSQSExpectTest extends BaseRestApiExpectTest { - private StringBuilder currentText = new StringBuilder(); - byte[] md5; - - public byte[] getResult() { - return md5; + public BaseSQSExpectTest() { + provider = "sqs"; } - public void endElement(String uri, String name, String qName) { - if (qName.equals("MD5OfMessageBody")) { - String md5Hex = currentText.toString().trim(); - this.md5 = CryptoStreams.hex(md5Hex); + @ConfiguresRestClient + private static final class TestSQSRestClientModule extends SQSRestClientModule { + + @Override + protected String provideTimeStamp(final DateService dateService) { + return "2009-11-08T15:54:08.897Z"; } - currentText = new StringBuilder(); } - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); + @Override + protected Module createModule() { + return new TestSQSRestClientModule(); } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java index 1445bc2c46..ffae91064a 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java @@ -1,66 +1,43 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ package org.jclouds.sqs.options; -import static org.jclouds.sqs.options.CreateQueueOptions.Builder.defaultVisibilityTimeout; +import static org.jclouds.sqs.options.CreateQueueOptions.Builder.attribute; +import static org.jclouds.sqs.options.CreateQueueOptions.Builder.visibilityTimeout; import static org.testng.Assert.assertEquals; -import java.util.Collections; - -import org.jclouds.http.options.HttpRequestOptions; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + /** - * Tests possible uses of CreateQueueOptions and CreateQueueOptions.Builder.* + * Tests behavior of {@code CreateQueueOptions} * * @author Adrian Cole */ +@Test(groups = "unit", testName = "CreateQueueOptionsTest") public class CreateQueueOptionsTest { - @Test - public void testAssignability() { - assert HttpRequestOptions.class.isAssignableFrom(CreateQueueOptions.class); - assert !String.class.isAssignableFrom(CreateQueueOptions.class); + public void testVisibilityTimeout() { + CreateQueueOptions options = new CreateQueueOptions().visibilityTimeout(2); + assertEquals(ImmutableSet.of("VisibilityTimeout"), options.buildFormParameters().get("Attribute.1.Name")); + assertEquals(ImmutableSet.of("2"), options.buildFormParameters().get("Attribute.1.Value")); } - @Test - public void testTimeout() { - CreateQueueOptions options = new CreateQueueOptions(); - options.defaultVisibilityTimeout(1); - assertEquals(options.buildFormParameters().get("DefaultVisibilityTimeout"), Collections - .singletonList("1")); + public void testVisibilityTimeoutStatic() { + CreateQueueOptions options = visibilityTimeout(2); + assertEquals(ImmutableSet.of("VisibilityTimeout"), options.buildFormParameters().get("Attribute.1.Name")); + assertEquals(ImmutableSet.of("2"), options.buildFormParameters().get("Attribute.1.Value")); } - @Test - public void testNullTimeout() { - CreateQueueOptions options = new CreateQueueOptions(); - assertEquals(options.buildFormParameters().get("DefaultVisibilityTimeout"), Collections.EMPTY_LIST); + public void testAttribute() { + CreateQueueOptions options = new CreateQueueOptions().attribute("DelaySeconds", "1"); + assertEquals(ImmutableSet.of("DelaySeconds"), options.buildFormParameters().get("Attribute.1.Name")); + assertEquals(ImmutableSet.of("1"), options.buildFormParameters().get("Attribute.1.Value")); } - @Test - public void testTimeoutStatic() { - CreateQueueOptions options = defaultVisibilityTimeout(1); - assertEquals(options.buildFormParameters().get("DefaultVisibilityTimeout"), Collections - .singletonList("1")); + public void testAttributeStatic() { + CreateQueueOptions options = attribute("DelaySeconds", "1"); + assertEquals(ImmutableSet.of("DelaySeconds"), options.buildFormParameters().get("Attribute.1.Name")); + assertEquals(ImmutableSet.of("1"), options.buildFormParameters().get("Attribute.1.Value")); } - public void testNoTimeout() { - defaultVisibilityTimeout(0); - } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java new file mode 100644 index 0000000000..815a8a4956 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java @@ -0,0 +1,39 @@ +package org.jclouds.sqs.options; + +import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; +import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.visibilityTimeout; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ReceiveMessageOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ReceiveMessageOptionsTest") +public class ReceiveMessageOptionsTest { + + public void testVisibilityTimeout() { + ReceiveMessageOptions options = new ReceiveMessageOptions().visibilityTimeout(2); + assertEquals(ImmutableSet.of("2"), options.buildFormParameters().get("VisibilityTimeout")); + } + + public void testVisibilityTimeoutStatic() { + ReceiveMessageOptions options = visibilityTimeout(2); + assertEquals(ImmutableSet.of("2"), options.buildFormParameters().get("VisibilityTimeout")); + } + + public void testAttribute() { + ReceiveMessageOptions options = new ReceiveMessageOptions().attribute("All"); + assertEquals(ImmutableSet.of("All"), options.buildFormParameters().get("AttributeName.1")); + } + + public void testAttributeStatic() { + ReceiveMessageOptions options = attribute("All"); + assertEquals(ImmutableSet.of("All"), options.buildFormParameters().get("AttributeName.1")); + } + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java new file mode 100644 index 0000000000..5bbebdb7d9 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.options; + +import static org.jclouds.sqs.options.SendMessageOptions.Builder.delaySeconds; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests possible uses of SendMessageOptions and SendMessageOptions.Builder.* + * + * @author Adrian Cole + */ +public class SendMessageOptionsTest { + + @Test + public void testDelaySeconds() { + SendMessageOptions options = new SendMessageOptions(); + options.delaySeconds(3); + assertEquals(options.buildFormParameters().get("DelaySeconds"), ImmutableSet.of("3")); + } + + @Test + public void testDelaySecondsStatic() { + SendMessageOptions options = delaySeconds(3); + assertEquals(options.buildFormParameters().get("DelaySeconds"), ImmutableSet.of("3")); + } + + public void testNoDelaySeconds() { + delaySeconds(null); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java new file mode 100644 index 0000000000..c06baba868 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Set; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.hash.HashCodes; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "ReceiveMessageResponseTest") +public class ReceiveMessageResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/messages.xml"); + + Set expected = expected(); + + ReceiveMessageResponseHandler handler = injector.getInstance(ReceiveMessageResponseHandler.class); + Set result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public Set expected() { + return ImmutableSet.of(Message + .builder() + .id("5fea7756-0ea4-451a-a703-a558b933e274") + .receiptHandle( + "MbZj6wDWli+JvwwJaBV+3dcjk2YW2vA3+STFFljTM8tJJg6HRG6PYSasuWXPJB+Cw" + "\n" + + " Lj1FjgXUv1uSj1gUPAWV66FU/WeR4mq2OKpEGYWbnLmpRCJVAyeMjeU5ZBdtcQ+QE" + "\n" + + " auMZc8ZRv37sIW2iJKq3M9MFx1YvV11A2x/KSbkJ0=") + .md5(HashCodes.fromBytes(CryptoStreams.hex("fafb00f5732ab283681e124bf8747ed1"))) + .body("This is a test message") + .addAttribute("SenderId", "195004372649") + .addAttribute("SentTimestamp", "1238099229000") + .addAttribute("ApproximateReceiveCount", "5") + .addAttribute("ApproximateFirstReceiveTimestamp", "1250700979248").build()); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java new file mode 100644 index 0000000000..1ede1dc154 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; +import org.testng.annotations.Test; + +import com.google.common.hash.HashCodes; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "SendMessageResponseTest") +public class SendMessageResponseTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/send_message.xml"); + + MessageIdAndMD5 expected = expected(); + + RegexMessageIdAndMD5Handler handler = new RegexMessageIdAndMD5Handler( new ReturnStringIf2xx ()); + MessageIdAndMD5 result = handler.apply(HttpResponse.builder().statusCode(200).payload(is).build()); + + assertEquals(result.toString(), expected.toString()); + + } + + public MessageIdAndMD5 expected() { + return MessageIdAndMD5.builder() + .id("c332b2b0-b61f-42d3-8832-d03ebd89f68d") + .md5(HashCodes.fromBytes(CryptoStreams.hex("e32aedf2b2b25355d04b1507055532e6"))) + .build(); + } +} diff --git a/labs/sqs/src/test/resources/create_queue.xml b/labs/sqs/src/test/resources/create_queue.xml new file mode 100644 index 0000000000..33f78bf0d6 --- /dev/null +++ b/labs/sqs/src/test/resources/create_queue.xml @@ -0,0 +1,9 @@ + + + + https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11 + + + 86f9002d-531a-5868-a452-48e4293ae0a4 + + \ No newline at end of file diff --git a/labs/sqs/src/test/resources/list_queues.xml b/labs/sqs/src/test/resources/list_queues.xml index ae5e35cc19..80ad010379 100644 --- a/labs/sqs/src/test/resources/list_queues.xml +++ b/labs/sqs/src/test/resources/list_queues.xml @@ -1,2 +1,2 @@ -https://eu-west-1.queue.amazonaws.com/993194456877/adriancole-sqs1https://eu-west-1.queue.amazonaws.com/993194456877/adriancole-sqs111313c81c8-e345-4c75-ad57-ce4d9d5ff35a \ No newline at end of file +https://eu-west-1.queue.amazonaws.com/993194456877/adriancole-sqs1https://eu-west-1.queue.amazonaws.com/993194456877/adriancole-sqs111313c81c8-e345-4c75-ad57-ce4d9d5ff35a \ No newline at end of file diff --git a/labs/sqs/src/test/resources/messages.xml b/labs/sqs/src/test/resources/messages.xml new file mode 100644 index 0000000000..496b15980b --- /dev/null +++ b/labs/sqs/src/test/resources/messages.xml @@ -0,0 +1,39 @@ + + + + + 5fea7756-0ea4-451a-a703-a558b933e274 + + + MbZj6wDWli+JvwwJaBV+3dcjk2YW2vA3+STFFljTM8tJJg6HRG6PYSasuWXPJB+Cw + Lj1FjgXUv1uSj1gUPAWV66FU/WeR4mq2OKpEGYWbnLmpRCJVAyeMjeU5ZBdtcQ+QE + auMZc8ZRv37sIW2iJKq3M9MFx1YvV11A2x/KSbkJ0= + + + fafb00f5732ab283681e124bf8747ed1 + + This is a test message + + SenderId + 195004372649 + + + SentTimestamp + 1238099229000 + + + ApproximateReceiveCount + 5 + + + ApproximateFirstReceiveTimestamp + 1250700979248 + + + + + + b6633655-283d-45b4-aee4-4e84e0ae6afa + + + \ No newline at end of file diff --git a/labs/sqs/src/test/resources/send_message.xml b/labs/sqs/src/test/resources/send_message.xml new file mode 100644 index 0000000000..13f9f2f7d3 --- /dev/null +++ b/labs/sqs/src/test/resources/send_message.xml @@ -0,0 +1,10 @@ + + + + c332b2b0-b61f-42d3-8832-d03ebd89f68d + e32aedf2b2b25355d04b1507055532e6 + + + c6c18089-18ad-52f8-9d06-c840628cb2ea + + \ No newline at end of file From dc212cf4602fd67c663abf5f814edf5b58750a85 Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Wed, 12 Sep 2012 08:41:18 +0200 Subject: [PATCH 13/60] issue 384: added support for ubuntu12.04; prepared for supporting remote host --- labs/virtualbox/README.md | 18 +- labs/virtualbox/pom.xml | 7 +- .../virtualbox/VirtualBoxApiMetadata.java | 14 +- ...rdcodeLocalhostAsNodeMetadataSupplier.java | 11 +- ...VirtualBoxComputeServiceContextModule.java | 5 +- .../config/VirtualBoxConstants.java | 3 + .../jclouds/virtualbox/domain/YamlImage.java | 3 +- ...MachineFromIMachineIfNotAlreadyExists.java | 17 +- .../functions/CreateAndInstallVm.java | 22 +- .../HardcodedHostToHostNodeMetadata.java | 83 ++++ .../functions/IMachineToNodeMetadata.java | 50 +-- .../functions/IMachineToSshClient.java | 12 +- .../functions/IpAddressesLoadingCache.java | 95 +++++ .../functions/MastersLoadingCache.java | 386 +++++++++++------- .../virtualbox/functions/NodeCreator.java | 155 ++++--- .../admin/StartVBoxIfNotAlreadyRunning.java | 70 +++- .../statements/EnableNetworkInterface.java | 3 - .../jclouds/virtualbox/util/MachineUtils.java | 93 ++--- .../src/main/resources/default-images.yaml | 89 +++- .../BaseVirtualBoxClientLiveTest.java | 10 +- .../virtualbox/PreseedCfgServerTest.java | 1 - ...rtualBoxComputeServiceAdapterLiveTest.java | 4 +- .../compute/VirtualBoxExperimentLiveTest.java | 5 +- .../VirtualBoxImageExtensionLiveTest.java | 19 + .../functions/CreateAndInstallVmLiveTest.java | 62 +-- .../StartVBoxIfNotAlreadyRunningLiveTest.java | 20 +- .../GuestAdditionsInstallerLiveTest.java | 24 +- .../util/MachineControllerLiveTest.java | 34 +- .../src/test/resources/default-images.yaml | 90 +++- 29 files changed, 911 insertions(+), 494 deletions(-) create mode 100644 labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/HardcodedHostToHostNodeMetadata.java create mode 100644 labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java diff --git a/labs/virtualbox/README.md b/labs/virtualbox/README.md index 9b7e26d86a..b618fa9d92 100644 --- a/labs/virtualbox/README.md +++ b/labs/virtualbox/README.md @@ -1,11 +1,19 @@ #Setup -Have virtualbox 4.1.8 installed. +Have virtualbox 4.1.20r80170 installed. Have an ssh daemon with passwordless login to localhost (i.e. "ssh [me]@localhost" must work without password). +To achieve that, be sure you have your ssh public key (at System.getProperty("user.home") + "/.ssh/id_rsa") in your '.ssh/authorized_keys'. +Please look at [this example]http://www.linuxproblem.org/art_9.html for more details. -That's it! +You can have also specify '-Dvirtualbox.identity' and '-Dvirtualbox.credential' if you want to use a username and password of your local machine. + +In order to make available a preseed file, jclouds-vbox will start a PreseedServer at `http://localhost:23232` that will serve a preseed.cfg file. +Make sure your firewall rules are not blocking this port. +If you need to override this default you can use -Djclouds.virtualbox.preconfigurationurl=http://localhost:PORT/preseed.cfg, with a different PORT. + +That's it! -------------- @@ -17,7 +25,7 @@ Enjoy local cloud goodness by running: > (use 'org.jclouds.compute2) > (import 'org.jclouds.scriptbuilder.statements.login.AdminAccess) -> (def compute (compute-service "virtualbox" "admin" "12345" :sshj :slf4j)) +> (def compute (compute-service "virtualbox" "user" "password" :sshj :slf4j)) > (create-nodes compute "local-cluster" 2 (build-template compute { :run-script (AdminAccess/standard) } )) -------------- @@ -39,8 +47,8 @@ It *should* behave as any other provider, if not please report. - jclouds-vbox is still at alpha stage please report any issues you find. - jclouds-vbox has been mostly tested on Mac OSX, it might work on Linux iff vbox is running and correctly set up, but it won't work on windows for the moment. -- cached isos, vm's and most configs are kept at ~/.jclouds-vbox/ by default. -- jclouds-vbox assumes vbox has the default host-only network vboxnet0, that the network is in 192.168.86.0/255.255.255.0 and that the host has address 1 in this network. +- cached isos, vm's and most configs are kept at ~/.jclouds-vbox/ by default, you can override -Dtest.virtualbox.workingDir=/path/to/your/workingDir. +- jclouds-vbox assumes vbox has the default host-only network vboxnet0, that the network is in 192.168.86.0/255.255.255.0 and that the host has address 1 in this network. -------------- diff --git a/labs/virtualbox/pom.xml b/labs/virtualbox/pom.xml index 820018decf..27c6c93b52 100644 --- a/labs/virtualbox/pom.xml +++ b/labs/virtualbox/pom.xml @@ -37,10 +37,10 @@ http://localhost:18083/ 4.1.4 - 4.1.8r75467 + 4.1.20r80170 administrator - 12345 - imageId=test-ubuntu-11.10-i386,loginUser=toor:password,authenticateSudo=true + CHANGE_ME + osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64,loginUser=toor:password,authenticateSudo=true org.jclouds.virtualbox*;version="${project.version}" org.jclouds*;version="${project.version}",* @@ -136,6 +136,7 @@ 1 + false ${test.virtualbox.endpoint} ${test.virtualbox.api-version} diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java index f7c1b7fef9..6fd60045c8 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java @@ -20,6 +20,8 @@ package org.jclouds.virtualbox; import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_CREDENTIAL; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_IDENTITY; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGES_DESCRIPTOR; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL; @@ -81,7 +83,13 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata { properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor); properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg"); - properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=11.10,os64Bit=true,osArchMatches=x86,loginUser=toor:password,authenticateSudo=true"); + + properties.put(VIRTUALBOX_GUEST_IDENTITY, "toor"); + properties.put(VIRTUALBOX_GUEST_CREDENTIAL, "password"); + properties.setProperty(TEMPLATE, + String.format("osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64,loginUser=%s:%s,authenticateSudo=true", + properties.getProperty(VIRTUALBOX_GUEST_IDENTITY), + properties.getProperty(VIRTUALBOX_GUEST_CREDENTIAL))); return properties; } @@ -93,8 +101,8 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata { .identityName("User") .credentialName("Password") .documentation(URI.create("https://www.virtualbox.org/sdkref/index.html")) - .defaultIdentity("administrator") - .defaultCredential("12345") + .defaultIdentity(System.getProperty("user.name")) + .defaultCredential("CHANGE_ME") .defaultEndpoint("http://localhost:18083/") .documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon")) // later version not in maven, yet diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/HardcodeLocalhostAsNodeMetadataSupplier.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/HardcodeLocalhostAsNodeMetadataSupplier.java index 814a6c9c1f..ce598d4037 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/HardcodeLocalhostAsNodeMetadataSupplier.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/HardcodeLocalhostAsNodeMetadataSupplier.java @@ -35,6 +35,7 @@ import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; import com.google.common.base.Charsets; +import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.base.Throwables; import com.google.common.io.Files; @@ -79,7 +80,7 @@ import com.google.inject.Provides; public class HardcodeLocalhostAsNodeMetadataSupplier extends AbstractModule { public static final String HOST_ID = "host"; - public static final String HOSTNAME = System.getenv("HOSTNAME"); + public static final String HOSTNAME = Strings.nullToEmpty(System.getenv("HOSTNAME")); /** * Lazy so that we don't hang up the injector reading a file @@ -91,9 +92,7 @@ public class HardcodeLocalhostAsNodeMetadataSupplier extends AbstractModule { @Override public NodeMetadata get() { - String privateKey = readRsaIdentity(); - return new NodeMetadataBuilder() .id(HOST_ID) .name("host installing virtualbox") @@ -110,9 +109,9 @@ public class HardcodeLocalhostAsNodeMetadataSupplier extends AbstractModule { .description(HOSTNAME) .build()) .credentials(LoginCredentials.builder() - .user(System.getProperty("user.name")) - .privateKey(privateKey) - .build()) + .user(System.getProperty("user.name")) + .privateKey(privateKey) + .build()) .build(); } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index 7fe2b90c26..d65bd8584b 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -150,7 +150,10 @@ public class VirtualBoxComputeServiceContextModule extends @Override public VirtualBoxManager apply(Supplier nodeSupplier) { - return VirtualBoxManager.createInstance(nodeSupplier.get().getId()); + if(nodeSupplier.get().getId() != null) + return VirtualBoxManager.createInstance(nodeSupplier.get().getId()); + + return VirtualBoxManager.createInstance(""); } @Override diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java index 46a6e67ac5..e0c8442435 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java @@ -61,5 +61,8 @@ public interface VirtualBoxConstants { + ".jclouds-vbox"; public static final String VIRTUALBOX_PROVIDER = "virtualbox"; + + public static final String VIRTUALBOX_GUEST_IDENTITY = "jclouds.virtualbox.guest.identity"; + public static final String VIRTUALBOX_GUEST_CREDENTIAL = "jclouds.virtualbox.guest.credential"; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java index bff48a2632..8a45140ffa 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java @@ -118,6 +118,7 @@ public class YamlImage { public String os_family; public String os_description; public String os_version; + public String iso_md5; public String iso; public String keystroke_sequence; public String preseed_cfg; @@ -154,7 +155,7 @@ public class YamlImage { public String toString() { return "YamlImage [id=" + id + ", name=" + name + ", description=" + description + ", hostname=" + hostname + ", location_id=" + location_id + ", os_arch=" + os_arch + ", os_family=" + os_family - + ", os_description=" + os_description + ", os_version=" + os_version + ", iso=" + iso + + ", os_description=" + os_description + ", os_version=" + os_version + ", iso=" + iso + ", keystroke_sequence=" + keystroke_sequence + ", preseed_cfg=" + preseed_cfg + ", login_port=" + login_port + ", os_64bit=" + os_64bit + ", group=" + group + ", tags=" + tags + ", metadata=" + metadata + ", username=" + username + ", credential=" + credential + ", credential_url=" diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java index 46521df88a..0985deb519 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java @@ -21,6 +21,7 @@ package org.jclouds.virtualbox.functions; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; import javax.annotation.Resource; import javax.inject.Named; @@ -60,6 +61,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu private final Supplier manager; private final String workingDir; private final MachineUtils machineUtils; + + private final ReentrantLock lock = new ReentrantLock(); @Inject public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(Supplier manager, @@ -104,15 +107,13 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu if (isLinkedClone) options.add(CloneOptions.Link); - // TODO snapshot name - ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc", logger) - .apply(master); - - // clone - IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options); - + ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, + "snapshotName", "snapshotDesc", logger).apply(master); + IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, + CloneMode.MachineState, options); progress.waitForCompletion(-1); - logger.debug(String.format("Machine %s is cloned correctly", clonedMachine.getName())); + logger.debug(String.format("Machine %s is cloned correctly", + clonedMachine.getName())); // memory may not be the same as the master vm clonedMachine.setMemorySize(cloneSpec.getVmSpec().getMemory()); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java index b359cd47ff..ff013ede56 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java @@ -42,7 +42,9 @@ import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.statements.InstallGuestAdditions; import org.jclouds.virtualbox.util.MachineController; import org.jclouds.virtualbox.util.MachineUtils; +import org.virtualbox_4_1.DeviceType; import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IMediumAttachment; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -88,19 +90,14 @@ public class CreateAndInstallVm implements Function { @Override public IMachine apply(MasterSpec masterSpec) { - VmSpec vmSpec = masterSpec.getVmSpec(); IsoSpec isoSpec = masterSpec.getIsoSpec(); String vmName = vmSpec.getVmName(); - IMachine vm = createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(masterSpec); - // Launch machine and wait for it to come online machineController.ensureMachineIsLaunched(vmName); - String installationKeySequence = isoSpec.getInstallationKeySequence().replace("PRECONFIGURATION_URL", preconfigurationUrl); - configureOsInstallationWithKeyboardSequence(vmName, installationKeySequence); // the OS installation is a long process: let's delay the check for ssh of 30 sec @@ -111,11 +108,8 @@ public class CreateAndInstallVm implements Function { } SshClient client = sshClientForIMachine.apply(vm); - logger.debug(">> awaiting installation to finish node(%s)", vmName); - checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", vmName); - NodeMetadata nodeMetadata = imachineToNodeMetadata.apply(vm); logger.debug(">> awaiting post-installation actions on vm: %s", vmName); @@ -129,9 +123,17 @@ public class CreateAndInstallVm implements Function { new InstallGuestAdditions(vmSpec, version), RunScriptOptions.NONE); ExecResponse gaInstallationResponse = Futures.getUnchecked(execInstallGA); checkState(gaInstallationResponse.getExitStatus() == 0); - machineController.ensureMachineIsShutdown(vmName); - + Iterable mediumAttachments = Iterables.filter(vm.getMediumAttachmentsOfController("IDE Controller"), + new Predicate() { + public boolean apply(IMediumAttachment in) { + return in.getMedium() != null && in.getMedium().getDeviceType().equals(DeviceType.DVD); + } + }); + for (IMediumAttachment iMediumAttachment : mediumAttachments) { + machineUtils.writeLockMachineAndApply(vm.getName(), new DetachDistroMediumFromMachine( + iMediumAttachment.getController(), iMediumAttachment.getPort(), iMediumAttachment.getDevice())); + } return vm; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/HardcodedHostToHostNodeMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/HardcodedHostToHostNodeMetadata.java new file mode 100644 index 0000000000..8f09c67d22 --- /dev/null +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/HardcodedHostToHostNodeMetadata.java @@ -0,0 +1,83 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.annotation.Resource; +import javax.inject.Named; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.location.Provider; +import org.jclouds.logging.Logger; +import org.jclouds.rest.annotations.Credential; +import org.jclouds.rest.annotations.Identity; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; +import com.google.inject.Singleton; + +@Singleton +public class HardcodedHostToHostNodeMetadata implements + Function { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final Supplier providerSupplier; + private final String username; + private final String password; + + @Inject + public HardcodedHostToHostNodeMetadata( + @Provider Supplier providerSupplier, + @Nullable @Identity String identity, + @Nullable @Credential String credential) { + this.providerSupplier = checkNotNull(providerSupplier, + "endpoint to virtualbox websrvd is needed"); + this.username = identity; + this.password = credential.equals("CHANGE_ME") ? "" : credential; + } + + @Override + public NodeMetadata apply(NodeMetadata host) { + + LoginCredentials.Builder credentialsBuilder = LoginCredentials.builder( + host.getCredentials()).user(username); + if (!password.isEmpty()) + credentialsBuilder.password(password); + + return NodeMetadataBuilder + .fromNodeMetadata(host) + .credentials(credentialsBuilder.build()) + .publicAddresses(ImmutableList.of(providerSupplier.get().getHost())) + .build(); + } + +} diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java index d985d050cd..499fca7da1 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java @@ -46,7 +46,6 @@ import org.virtualbox_4_1.NetworkAttachmentType; import com.google.common.base.Function; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -82,7 +81,6 @@ public class IMachineToNodeMetadata implements Function NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder(); nodeMetadataBuilder.name(name).ids(vm.getName()).group(group); - // TODO Set up location properly LocationBuilder locationBuilder = new LocationBuilder(); locationBuilder.description(""); @@ -96,41 +94,8 @@ public class IMachineToNodeMetadata implements Function if (nodeState == null) nodeState = Status.UNRECOGNIZED; nodeMetadataBuilder.status(nodeState); - - /* - // nat adapter - INetworkAdapter natAdapter = vm.getNetworkAdapter(0l); - checkNotNull(natAdapter, "slot 0 networkadapter"); - checkState(natAdapter.getAttachmentType() == NetworkAttachmentType.NAT, - "expecting slot 0 to be a NAT attachment type (was: " + natAdapter.getAttachmentType() + ")"); - - int ipTermination = 0; - int inPort = 0; - String hostAddress = ""; - - nodeMetadataBuilder.publicAddresses(ImmutableSet.of(natAdapter.getNatDriver().getHostIP())); - for (String nameProtocolnumberAddressInboudportGuestTargetport : natAdapter.getNatDriver().getRedirects()) { - Iterable stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); - String protocolNumber = Iterables.get(stuff, 1); - hostAddress = Iterables.get(stuff, 2); - String inboundPort = Iterables.get(stuff, 3); - String targetPort = Iterables.get(stuff, 5); - if ("1".equals(protocolNumber) && "22".equals(targetPort)) { - inPort = Integer.parseInt(inboundPort); - ipTermination = inPort % NodeCreator.NODE_PORT_INIT + 2; - } - } - - // only masters use 2222 port - if (inPort == MastersLoadingCache.MASTER_PORT) { - nodeMetadataBuilder.publicAddresses(ImmutableSet.of(hostAddress)).loginPort(inPort); - } else { - nodeMetadataBuilder.privateAddresses(ImmutableSet.of((NodeCreator.VMS_NETWORK + ipTermination) + "")); - nodeMetadataBuilder.publicAddresses(ImmutableSet.of((NodeCreator.VMS_NETWORK + ipTermination) + "")); - } - */ - nodeMetadataBuilder = getIpAddresses(vm, nodeMetadataBuilder); + LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true); nodeMetadataBuilder.credentials(loginCredentials); @@ -144,7 +109,9 @@ public class IMachineToNodeMetadata implements Function INetworkAdapter adapter = vm.getNetworkAdapter(slot); if(adapter != null) { if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) { - publicIpAddresses.add(adapter.getNatDriver().getHostIP()); + String hostIP = adapter.getNatDriver().getHostIP(); + if(!hostIP.isEmpty()) + publicIpAddresses.add(hostIP); for (String nameProtocolnumberAddressInboudportGuestTargetport : adapter.getNatDriver().getRedirects()) { Iterable stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); String protocolNumber = Iterables.get(stuff, 1); @@ -153,26 +120,25 @@ public class IMachineToNodeMetadata implements Function String targetPort = Iterables.get(stuff, 5); if ("1".equals(protocolNumber) && "22".equals(targetPort)) { int inPort = Integer.parseInt(inboundPort); - nodeMetadataBuilder.publicAddresses(ImmutableSet.of(hostAddress)).loginPort(inPort); + publicIpAddresses.add(hostAddress); + nodeMetadataBuilder.loginPort(inPort); } //privateIpAddresses.add((NodeCreator.VMS_NETWORK + ipTermination) + ""); } // TODO this could be a public and private address } else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) { - String clientIpAddress = machineUtils.getIpAddressFromBridgedNIC(vm.getName()); + String clientIpAddress = machineUtils.getIpAddressFromFirstNIC(vm.getName()); //privateIpAddresses.add(clientIpAddress); publicIpAddresses.add(clientIpAddress); } else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) { - String clientIpAddress = machineUtils.getIpAddressFromHostOnlyNIC(vm.getName()); + String clientIpAddress = machineUtils.getIpAddressFromFirstNIC(vm.getName()); publicIpAddresses.add(clientIpAddress); - } } } nodeMetadataBuilder.publicAddresses(publicIpAddresses); nodeMetadataBuilder.privateAddresses(publicIpAddresses); - return nodeMetadataBuilder; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java index 3c684152b6..adb15aa207 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java @@ -20,6 +20,8 @@ package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_CREDENTIAL; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_IDENTITY; import java.util.List; @@ -35,6 +37,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.Logger; import org.jclouds.ssh.SshClient; +import org.jclouds.virtualbox.VirtualBoxApiMetadata; import org.jclouds.virtualbox.domain.BridgedIf; import org.jclouds.virtualbox.statements.GetIPAddressFromMAC; import org.jclouds.virtualbox.statements.ScanNetworkWithPing; @@ -82,10 +85,11 @@ public class IMachineToSshClient implements Function { String clientIpAddress = null; String sshPort = "22"; - // TODO: we need a way to align the default login credentials - // from the iso with the vmspec -> IMachineToNodeMetadata using YamlImage ? + String guestIdentity = VirtualBoxApiMetadata.defaultProperties().getProperty(VIRTUALBOX_GUEST_IDENTITY); + String guestCredential = VirtualBoxApiMetadata.defaultProperties().getProperty(VIRTUALBOX_GUEST_CREDENTIAL); LoginCredentials loginCredentials = LoginCredentials.builder() - .user("toor").password("password").authenticateSudo(true) + .user(guestIdentity) + .password(guestCredential).authenticateSudo(true) .build(); if (networkAdapter.getAttachmentType() @@ -109,7 +113,7 @@ public class IMachineToSshClient implements Function { clientIpAddress = getIpAddressFromBridgedNIC(networkAdapter, network); } else if (networkAdapter.getAttachmentType().equals( NetworkAttachmentType.HostOnly)) { - clientIpAddress = machineUtils.getIpAddressFromHostOnlyNIC(vm.getName()); + clientIpAddress = machineUtils.getIpAddressFromFirstNIC(vm.getName()); } checkNotNull(clientIpAddress, "clientIpAddress"); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java new file mode 100644 index 0000000000..c45112a6b7 --- /dev/null +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java @@ -0,0 +1,95 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.virtualbox.util.MachineUtils; +import org.virtualbox_4_1.VirtualBoxManager; + +import com.google.common.base.Supplier; +import com.google.common.cache.AbstractLoadingCache; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.Maps; + +/** + * A {@link LoadingCache} for ip addresses. If the requested ip address has been + * previously extracted this returns it, if not it calls vbox api. + * + * @author andrea turli + * + */ +@Singleton +public class IpAddressesLoadingCache extends + AbstractLoadingCache { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final Map masters = Maps.newHashMap(); + private final Supplier manager; + + @Inject + public IpAddressesLoadingCache(Supplier manager) { + this.manager = checkNotNull(manager, "vboxmanager"); + } + + @Override + public synchronized String get(String idOrName) throws ExecutionException { + if (masters.containsKey(idOrName)) { + return masters.get(idOrName); + } + + String currentIp = "", previousIp = ""; + int count = 0; + while (count < 3) { + currentIp = ""; + while (!MachineUtils.isIpv4(currentIp)) { + currentIp = manager.get().getVBox().findMachine(idOrName) + .getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP"); + } + + if (previousIp.equals(currentIp)) { + count++; + } + previousIp = currentIp; + } + + masters.put(idOrName, currentIp); + return currentIp; + } + + @Override + public String getIfPresent(Object key) { + return masters.get((String) key); + } + +} diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java index 42f95069d0..04f6f4d702 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java @@ -22,6 +22,7 @@ package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; @@ -32,6 +33,8 @@ import static org.jclouds.virtualbox.util.MachineUtils.machineNotFoundException; import java.io.File; import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; @@ -42,10 +45,17 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.compute.callables.RunScriptOnNode.Factory; +import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.location.Provider; import org.jclouds.logging.Logger; import org.jclouds.rest.annotations.BuildVersion; +import org.jclouds.scriptbuilder.domain.Statement; +import org.jclouds.scriptbuilder.domain.StatementList; +import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.Master; @@ -57,6 +67,8 @@ import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.YamlImage; import org.jclouds.virtualbox.functions.admin.PreseedCfgServer; +import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen; +import org.testng.collections.Lists; import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.NetworkAttachmentType; @@ -71,178 +83,236 @@ import com.google.common.cache.AbstractLoadingCache; import com.google.common.cache.LoadingCache; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.net.HostAndPort; /** - * A {@link LoadingCache} for masters. If the requested master has been previously created this - * returns it, if not it coordinates its creation including downloading isos and creating - * cache/config directories. This also implements {@link Supplier} in order to provide jetty with - * the current image (only one master can be created at a time). + * A {@link LoadingCache} for masters. If the requested master has been + * previously created this returns it, if not it coordinates its creation + * including downloading isos and creating cache/config directories. This also + * implements {@link Supplier} in order to provide jetty with the current image + * (only one master can be created at a time). * - * @author dralves + * @author dralves, andrea turli * */ @Singleton public class MastersLoadingCache extends AbstractLoadingCache { - // TODO parameterize - public static final int MASTER_PORT = 2222; - public static final String HOST_ONLY_IFACE_NAME = "vboxnet0"; + // TODO parameterize + public static final int MASTER_PORT = 2222; - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; - private final Map masters = Maps.newHashMap(); - private final Function masterCreatorAndInstaller; - private final Map imageMapping; - private final String workingDir; - private final String installationKeySequence; - private final String isosDir; - private final Supplier manager; - private final Function isoDownloader; - private final String version; - private final String preconfigurationUrl; + private final Map masters = Maps.newHashMap(); + private final Function masterCreatorAndInstaller; + private final Map imageMapping; + private final String workingDir; + private final String installationKeySequence; + private final String isosDir; + private final Supplier manager; + private final String version; + private final String preconfigurationUrl; - @Inject - public MastersLoadingCache(@BuildVersion String version, - @Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence, - @Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl, - @Named(VIRTUALBOX_WORKINGDIR) String workingDir, Function masterLoader, - Supplier> yamlMapper, Supplier manager, - Function isoDownloader) { - checkNotNull(version, "version"); - checkNotNull(installationKeySequence, "installationKeySequence"); - checkNotNull(manager, "vboxmanager"); - this.manager = manager; - this.masterCreatorAndInstaller = masterLoader; - this.installationKeySequence = installationKeySequence; - this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR : workingDir; - this.isosDir = workingDir + File.separator + "isos"; - this.imageMapping = Maps.newLinkedHashMap(); - for (Entry entry : yamlMapper.get().entrySet()) { - this.imageMapping.put(entry.getKey().getId(), entry.getValue()); + private final Factory runScriptOnNodeFactory; + private final RetryIfSocketNotYetOpen socketTester; + private final Supplier host; + private final Supplier providerSupplier; + private final HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata; + + @Inject + public MastersLoadingCache( + @BuildVersion String version, + @Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence, + @Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl, + @Named(VIRTUALBOX_WORKINGDIR) String workingDir, + Function masterLoader, + Supplier> yamlMapper, + Supplier manager, + Factory runScriptOnNodeFactory, + RetryIfSocketNotYetOpen socketTester, Supplier host, + @Provider Supplier providerSupplier, + HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) { + checkNotNull(version, "version"); + checkNotNull(installationKeySequence, "installationKeySequence"); + checkNotNull(manager, "vboxmanager"); + this.manager = manager; + this.masterCreatorAndInstaller = masterLoader; + this.installationKeySequence = installationKeySequence; + this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR + : workingDir; + this.isosDir = workingDir + File.separator + "isos"; + this.imageMapping = Maps.newLinkedHashMap(); + for (Entry entry : yamlMapper.get().entrySet()) { + this.imageMapping.put(entry.getKey().getId(), entry.getValue()); + } + this.version = Iterables.get(Splitter.on('r').split(version), 0); + this.preconfigurationUrl = preconfigurationUrl; + + this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, + "runScriptOnNodeFactory"); + this.socketTester = checkNotNull(socketTester, "socketTester"); + this.socketTester.seconds(3L); + this.host = checkNotNull(host, "host"); + this.providerSupplier = checkNotNull(providerSupplier, + "endpoint to virtualbox websrvd is needed"); + this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata; + } + + @PostConstruct + public void createCacheDirStructure() { + if (!new File(workingDir).exists()) { + new File(workingDir, "isos").mkdirs(); + } + } + + @Override + public synchronized Master get(Image key) throws ExecutionException { + // check if we have loaded this machine before + if (masters.containsKey(key.getId())) { + return masters.get(key.getId()); + } + checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR), + "master image names cannot contain \"" + + VIRTUALBOX_NODE_NAME_SEPARATOR + "\""); + String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId(); + IMachine masterMachine; + Master master; + // ready the preseed file server + PreseedCfgServer server = new PreseedCfgServer(); + try { + // try and find a master machine in vbox + masterMachine = manager.get().getVBox().findMachine(vmName); + master = Master.builder().machine(masterMachine).build(); + } catch (VBoxException e) { + if (machineNotFoundException(e)) { + // machine was not found try to build one from a yaml file + YamlImage currentImage = checkNotNull(imageMapping.get(key.getId()), "currentImage"); + URI preseedServer; + try { + preseedServer = new URI(preconfigurationUrl); + if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(), + preseedServer.getPort()))) { + server.start(preconfigurationUrl, currentImage.preseed_cfg); + } + } catch (URISyntaxException e1) { + throw e; + } + + MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, + vmName); + + // create the master machine if it can't be found + masterMachine = masterCreatorAndInstaller.apply(masterSpec); + // build the master + master = Master.builder().machine(masterMachine) + .spec(masterSpec).build(); + } else { + throw e; + } + } finally { + server.stop(); + } + + masters.put(key.getId(), master); + return master; + } + + private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage, + String vmName) throws ExecutionException { + String guestAdditionsFileName = String.format( + "VBoxGuestAdditions_%s.iso", version); + String guestAdditionsIso = String.format("%s/%s", isosDir, + guestAdditionsFileName); + String guestAdditionsUri = "http://download.virtualbox.org/virtualbox/" + + version + "/" + guestAdditionsFileName; + if (!new File(guestAdditionsIso).exists()) { + getFilePathOrDownload(guestAdditionsUri, null); + } + // check if the iso is here, download if not + String localIsoUrl = checkNotNull(getFilePathOrDownload(currentImage.iso, currentImage.iso_md5), "distro iso"); + String adminDisk = workingDir + File.separator + vmName + ".vdi"; + HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk) + .autoDelete(true).controllerPort(0).deviceSlot(1).build(); + + StorageController ideController = StorageController.builder() + .name("IDE Controller").bus(StorageBus.IDE) + .attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk) + .attachISO(1, 0, guestAdditionsIso).build(); + + VmSpec vmSpecification = VmSpec.builder().id(currentImage.id) + .name(vmName).memoryMB(512).osTypeId("") + .controller(ideController).forceOverwrite(true) + .cleanUpMode(CleanupMode.Full).build(); + + NetworkAdapter networkAdapter = NetworkAdapter + .builder() + .networkAttachmentType(NetworkAttachmentType.NAT) + .tcpRedirectRule(providerSupplier.get().getHost(), MASTER_PORT, + "", 22).build(); + + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard + .builder().addNetworkAdapter(networkAdapter).slot(0L).build(); + + NetworkSpec networkSpec = NetworkSpec.builder() + .addNIC(networkInterfaceCard).build(); + + return MasterSpec + .builder() + .vm(vmSpecification) + .iso(IsoSpec + .builder() + .sourcePath(localIsoUrl) + .installationScript( + installationKeySequence.replace("HOSTNAME", + vmSpecification.getVmName())).build()) + .network(networkSpec).build(); + } + + @Override + public synchronized Master getIfPresent(Object key) { + checkArgument(key instanceof Image, + "this cache is for entries who's keys are Images"); + Image image = Image.class.cast(key); + if (masters.containsKey(image.getId())) { + return masters.get(image.getId()); + } + return null; + } + + private String getFilePathOrDownload(String httpUrl, String md5) + throws ExecutionException { + String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1, + httpUrl.length()); + URI provider = providerSupplier.get(); + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), + provider.getPort()))) { + throw new RuntimeException("could not connect to virtualbox"); } - this.version = Iterables.get(Splitter.on('r').split(version), 0); - this.isoDownloader = isoDownloader; - this.preconfigurationUrl = preconfigurationUrl; - } + File file = new File(isosDir, fileName); + List statements = Lists.newArrayList(); + statements.add(Statements.saveHttpResponseTo(URI.create(httpUrl), + isosDir, fileName)); + StatementList statementList = new StatementList(statements); + NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata + .apply(host.get()); + runScriptOnNodeFactory + .create(hostNodeMetadata, statementList, runAsRoot(false)).init() + .call(); - @PostConstruct - public void createCacheDirStructure() { - if (!new File(workingDir).exists()) { - new File(workingDir, "isos").mkdirs(); + ExecResponse response = runScriptOnNodeFactory + .create( + hostNodeMetadata, + Statements.exec("md5 " + isosDir + File.separator + fileName), + runAsRoot(false)).init().call(); + if (md5 != null) { + if (!Iterables.get( + Splitter.on("=").trimResults().split(response.getOutput()), 1) + .equals(md5)) + return null; } - } - - @Override - public synchronized Master get(Image key) throws ExecutionException { - // check if we have loaded this machine before - if (masters.containsKey(key.getId())) { - return masters.get(key.getId()); - } - - checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR), "master image names cannot contain \"" - + VIRTUALBOX_NODE_NAME_SEPARATOR + "\""); - - String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId(); - - IMachine masterMachine; - - Master master; - - // ready the preseed file server - PreseedCfgServer server = new PreseedCfgServer(); - try { - // try and find a master machine in vbox - masterMachine = manager.get().getVBox().findMachine(vmName); - master = Master.builder().machine(masterMachine).build(); - - } catch (VBoxException e) { - if (machineNotFoundException(e)) { - // machine was not found try to build one from a yaml file - YamlImage currentImage = imageMapping.get(key.getId()); - - checkNotNull(currentImage); - - server.start(preconfigurationUrl, currentImage.preseed_cfg); - - MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, vmName); - - // create the master machine if it can't be found - masterMachine = masterCreatorAndInstaller.apply(masterSpec); - - // build the master - master = Master.builder().machine(masterMachine).spec(masterSpec).build(); - } else { - throw e; - } - } finally { - server.stop(); - } - - masters.put(key.getId(), master); - return master; - } - - private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage, String vmName) throws ExecutionException { - - String guestAdditionsFileName = String.format("VBoxGuestAdditions_%s.iso", version); - String guestAdditionsIso = String.format("%s/%s", isosDir, guestAdditionsFileName); - String guestAdditionsUri = "http://download.virtualbox.org/virtualbox/" + version + "/" + guestAdditionsFileName; - if (!new File(guestAdditionsIso).exists()) { - getFilePathOrDownload(guestAdditionsUri); - } - checkState(new File(guestAdditionsIso).exists(), "guest additions iso does not exist at: " + guestAdditionsIso); - - // check if the iso is here, download if not - String localIsoUrl = getFilePathOrDownload(currentImage.iso); - - String adminDisk = workingDir + File.separator + vmName + ".vdi"; - - HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1) - .build(); - - StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE) - .attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk).attachISO(1, 0, guestAdditionsIso).build(); - - VmSpec vmSpecification = VmSpec.builder().id(currentImage.id).name(vmName).memoryMB(512).osTypeId("") - .controller(ideController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); - - NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule("127.0.0.1", MASTER_PORT, "", 22).build(); - - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) - .slot(0L).build(); - - NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); - - return MasterSpec - .builder() - .vm(vmSpecification) - .iso(IsoSpec.builder().sourcePath(localIsoUrl) - .installationScript(installationKeySequence.replace("HOSTNAME", vmSpecification.getVmName())) - .build()).network(networkSpec).build(); - } - - @Override - public synchronized Master getIfPresent(Object key) { - checkArgument(key instanceof Image, "this cache is for entries who's keys are Images"); - Image image = Image.class.cast(key); - if (masters.containsKey(image.getId())) { - return masters.get(image.getId()); - } - return null; - } - - private String getFilePathOrDownload(String httpUrl) throws ExecutionException { - String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1, httpUrl.length()); - File localFile = new File(isosDir, fileName); - if (!localFile.exists()) { - logger.debug("iso not found in cache, downloading: %s", httpUrl); - localFile = isoDownloader.apply(URI.create(httpUrl)); - } - checkState(localFile.exists(), "iso file has not been downloaded: " + fileName); - return localFile.getAbsolutePath(); + return file.getAbsolutePath(); } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java index d417afbfee..e9f6f289a9 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java @@ -22,10 +22,13 @@ package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_CREDENTIAL; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_IDENTITY; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_NAME_SEPARATOR; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; +import java.net.URI; import java.util.List; import javax.inject.Inject; @@ -39,7 +42,12 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.domain.LoginCredentials; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.location.Provider; +import org.jclouds.rest.annotations.Credential; +import org.jclouds.rest.annotations.Identity; import org.jclouds.scriptbuilder.domain.Statements; +import org.jclouds.virtualbox.VirtualBoxApiMetadata; import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.domain.CloneSpec; import org.jclouds.virtualbox.domain.Master; @@ -63,8 +71,10 @@ import org.virtualbox_4_1.NetworkAttachmentType; import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Function; +import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -84,29 +94,36 @@ public class NodeCreator implements Function host; - - + private final Supplier providerSupplier; + private final String username; + private final String password; + private int ram = 512; + private final String guestIdentity = VirtualBoxApiMetadata.defaultProperties().getProperty(VIRTUALBOX_GUEST_IDENTITY); + private final String guestCredential = VirtualBoxApiMetadata.defaultProperties().getProperty(VIRTUALBOX_GUEST_CREDENTIAL); + @Inject public NodeCreator(Supplier manager, Function cloner, Factory runScriptOnNodeFactory, + MachineUtils machineUtils, RunScriptOnNode.Factory scriptRunnerFactory, MachineController machineController, Supplier host, - MachineUtils machineUtils, RunScriptOnNode.Factory scriptRunnerFactory, MachineController machineController) { + @Provider Supplier providerSupplier, + @Nullable @Identity String identity, + @Nullable @Credential String credential) { this.manager = manager; this.cloner = cloner; this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); - this.host = checkNotNull(host, "host"); - this.machineUtils = machineUtils; this.machineController = machineController; + this.host = checkNotNull(host, "host"); + this.providerSupplier = checkNotNull(providerSupplier, + "endpoint to virtualbox websrvd is needed"); + this.username = identity; + this.password = credential; } @Override public synchronized NodeAndInitialCredentials apply(NodeSpec nodeSpec) { - checkNotNull(nodeSpec, "NodeSpec"); - - Master master = nodeSpec.getMaster(); - checkNotNull(master, "Master"); - + Master master = checkNotNull(nodeSpec.getMaster(), "Master"); if (master.getMachine().getCurrentSnapshot() != null) { ISession session; try { @@ -119,40 +136,32 @@ public class NodeCreator implements Function 0) { ram = nodeSpec.getTemplate().getHardware().getRam(); } - - VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(ram).cleanUpMode(CleanupMode.Full) + VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(ram) + .cleanUpMode(CleanupMode.Full) .forceOverwrite(true).build(); - // CASE NAT + HOST-ONLY - NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .build(); - NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(1L).build(); - - NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly) - .build(); - - // create new hostOnly interface if needed, otherwise use the one already there with dhcp enabled ... - String hostOnlyIfName = getHostOnlyIfOrCreate(); - - NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter) - .addHostInterfaceName(hostOnlyIfName).slot(0L).build(); - - NetworkSpec networkSpec = createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard); + // case 'vbox host is localhost': NAT + HOST-ONLY + NetworkSpec networkSpec = createNetworkSpecWhenVboxIsLocalhost(); + Optional optionalNatIfaceCard = Iterables.tryFind( + networkSpec.getNetworkInterfaceCards(), + new Predicate() { + @Override + public boolean apply(NetworkInterfaceCard nic) { + return nic.getNetworkAdapter().getNetworkAttachmentType() + .equals(NetworkAttachmentType.NAT); + } + }); CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()).network(networkSpec) .vm(cloneVmSpec).build(); IMachine cloned = cloner.apply(cloneSpec); - machineController.ensureMachineIsLaunched(cloneVmSpec.getVmName()); // IMachineToNodeMetadata produces the final ip's but these need to be set before so we build a @@ -160,42 +169,55 @@ public class NodeCreator implements Function nodeAndInitialCredentials = new NodeAndInitialCredentials(cloned, - cloneName, LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build()); - - return nodeAndInitialCredentials; + return new NodeAndInitialCredentials(cloned, + cloneName, LoginCredentials.builder() + .user(guestIdentity) + .password(guestCredential) + .authenticateSudo(true) + .build()); } - + private NodeMetadata buildPartialNodeMetadata(IMachine clone) { NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder(); nodeMetadataBuilder.id(clone.getName()); nodeMetadataBuilder.status(VirtualBoxComputeServiceContextModule.toPortableNodeStatus.get(clone.getState())); - nodeMetadataBuilder.publicAddresses(ImmutableSet.of(machineUtils.getIpAddressFromHostOnlyNIC(clone.getName()))); - - LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true); - nodeMetadataBuilder.credentials(loginCredentials); - + nodeMetadataBuilder.publicAddresses(ImmutableSet.of(machineUtils.getIpAddressFromFirstNIC(clone.getName()))); + LoginCredentials loginCredentials = new LoginCredentials(guestIdentity, guestCredential, null, true); + nodeMetadataBuilder.credentials(loginCredentials); return nodeMetadataBuilder.build(); } - private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard, - NetworkInterfaceCard hostOnlyIfaceCard) { - return NetworkSpec.builder().addNIC(natIfaceCard).addNIC(hostOnlyIfaceCard).build(); + private NetworkSpec createNetworkSpecWhenVboxIsLocalhost() { + NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) + .build(); + NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder() + .addNetworkAdapter(natAdapter) + .slot(1L) + .build(); + NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder() + .networkAttachmentType(NetworkAttachmentType.HostOnly) + .build(); + // create new hostOnly interface if needed, otherwise use the one already there with dhcp enabled ... + String hostOnlyIfName = getHostOnlyIfOrCreate(); + NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter) + .addHostInterfaceName(hostOnlyIfName).slot(0L).build(); + return createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard); } - /** - * @return - */ + private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard, + NetworkInterfaceCard hostOnlyIfaceCard) { + return NetworkSpec.builder() + .addNIC(natIfaceCard) + .addNIC(hostOnlyIfaceCard) + .build(); + } + private String getHostOnlyIfOrCreate() { - IHostNetworkInterface availableHostInterfaceIf = returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(manager .get().getVBox().getHost().getNetworkInterfaces()); if (availableHostInterfaceIf==null) { @@ -205,7 +227,6 @@ public class NodeCreator implements Function availableNetworkInterfaces) { checkNotNull(availableNetworkInterfaces); return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces), null); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java index 4b5eeba584..b9d21b7fc2 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java @@ -24,22 +24,29 @@ import static com.google.common.base.Preconditions.checkState; import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; import java.net.URI; +import java.util.List; +import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.compute.callables.RunScriptOnNode.Factory; +import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.location.Provider; import org.jclouds.logging.Logger; +import org.jclouds.scriptbuilder.domain.Statement; +import org.jclouds.scriptbuilder.domain.StatementList; import org.jclouds.scriptbuilder.domain.Statements; +import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata; import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen; import org.virtualbox_4_1.SessionState; import org.virtualbox_4_1.VirtualBoxManager; +import com.beust.jcommander.internal.Lists; import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.net.HostAndPort; @@ -57,43 +64,74 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier private final Supplier providerSupplier; private final Function, VirtualBoxManager> managerForNode; private transient VirtualBoxManager manager; + private final HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata; // the functions and suppliers here are to ensure we don't do heavy i/o in injection @Inject public StartVBoxIfNotAlreadyRunning(Function, VirtualBoxManager> managerForNode, Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier host, - @Provider Supplier providerSupplier) { + @Provider Supplier providerSupplier, + HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) { this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.socketTester = checkNotNull(socketTester, "socketTester"); this.socketTester.seconds(3L); this.host = checkNotNull(host, "host"); this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed"); this.managerForNode = checkNotNull(managerForNode, "managerForNode"); - start(); + this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata; } + @PostConstruct public synchronized void start() { URI provider = providerSupplier.get(); - if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { - logger.debug("disabling password access"); - runScriptOnNodeFactory.create(host.get(), Statements.exec("VBoxManage setproperty websrvauthlibrary null"), - runAsRoot(false).wrapInInitScript(false)).init().call(); - logger.debug(">> starting vboxwebsrv"); - String vboxwebsrv = "vboxwebsrv -t 10000 -v -b"; - runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), - runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); - - if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))){ - throw new RuntimeException("could not connect to virtualbox"); - } + NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get()); + // kill previously started vboxwebsrv (possibly dirty session) + List statements = Lists.newArrayList(); + statements.add(Statements.findPid("vboxwebsrv")); + statements.add(Statements.kill()); + StatementList statementList = new StatementList(statements); + + if (socketTester.apply(HostAndPort.fromParts(provider.getHost(), + provider.getPort()))) { + logger.debug(String.format("shutting down previously started vboxwewbsrv at %s", provider)); + ExecResponse execResponse = runScriptOnNodeFactory + .create(hostNodeMetadata, statementList, runAsRoot(false)) + .init().call(); + if(execResponse.getExitStatus()!=0) + throw new RuntimeException("Cannot execute jclouds"); } + + logger.debug("disabling password access"); + runScriptOnNodeFactory + .create( + hostNodeMetadata, + Statements + .exec("VBoxManage setproperty websrvauthlibrary null"), + runAsRoot(false).wrapInInitScript(false)).init().call(); + logger.debug(">> starting vboxwebsrv"); + String vboxwebsrv = "vboxwebsrv -t0 -v -b -H " + + providerSupplier.get().getHost(); + runScriptOnNodeFactory + .create( + hostNodeMetadata, + Statements.exec(vboxwebsrv), + runAsRoot(false).wrapInInitScript(false) + .blockOnComplete(false).nameTask("vboxwebsrv")).init() + .call(); + + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), + provider.getPort()))) { + throw new RuntimeException("could not connect to virtualbox"); + } + manager = managerForNode.apply(host); manager.connect(provider.toASCIIString(), "", ""); if (logger.isDebugEnabled()) if (manager.getSessionObject().getState() != SessionState.Unlocked) - logger.warn("manager is not in unlocked state " + manager.getSessionObject().getState()); + logger.warn("manager is not in unlocked state " + + manager.getSessionObject().getState()); } - + @Override public VirtualBoxManager get() { checkState(manager != null, "start not called"); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java index 224fd2f7f8..59be70df96 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java @@ -63,9 +63,6 @@ public class EnableNetworkInterface implements Statement { } private List getStatements(String iface) { - /* - * auto eth0 - */ List statements = Lists.newArrayList(); statements.add(exec(String.format("echo auto %s >> /etc/network/interfaces", iface))); // statements.add(exec(String.format("echo iface %s inet dhcp >> /etc/network/interfaces", iface))); // diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java index 11e627949b..c0d23708c7 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java @@ -21,6 +21,7 @@ package org.jclouds.virtualbox.util; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import java.util.concurrent.ExecutionException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -37,6 +38,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.util.Throwables2; +import org.jclouds.virtualbox.functions.IpAddressesLoadingCache; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.ISession; import org.virtualbox_4_1.LockType; @@ -69,12 +71,14 @@ public class MachineUtils { private final Supplier manager; private final Factory scriptRunner; + private final IpAddressesLoadingCache ipAddressesLoadingCache; @Inject - public MachineUtils(Supplier manager, RunScriptOnNode.Factory scriptRunner) { - super(); + public MachineUtils(Supplier manager, RunScriptOnNode.Factory scriptRunner, + IpAddressesLoadingCache ipAddressesLoadingCache) { this.manager = manager; this.scriptRunner = scriptRunner; + this.ipAddressesLoadingCache = ipAddressesLoadingCache; } public ListenableFuture runScriptOnNode(NodeMetadata metadata, Statement statement, @@ -207,9 +211,18 @@ public class MachineUtils { private ISession lockSession(String machineId, LockType type, int retries) { int count = 0; ISession session; + IMachine immutableMachine = manager.get().getVBox().findMachine(machineId); + + try { + session = manager.get().openMachineSession(immutableMachine); + if (session.getState().equals(SessionState.Locked)) + return checkNotNull(session, "session"); + } catch (Exception e) { + logger.debug("machine %s is not locked). Error: %s", immutableMachine.getName(), e.getMessage()); + } + while (true) { try { - IMachine immutableMachine = manager.get().getVBox().findMachine(machineId); session = manager.get().getSessionObject(); immutableMachine.lockMachine(session, type); break; @@ -219,13 +232,13 @@ public class MachineUtils { return null; } count++; - logger.warn(e, "Could not lock machine (try %d of %d). Error: %s", count, retries, e.getMessage()); + logger.debug("Could not lock machine (try %d of %d). Error: %s", count, retries, e.getMessage()); if (count == retries) { throw new RuntimeException(String.format("error locking %s with %s lock: %s", machineId, type, e.getMessage()), e); } try { - Thread.sleep(1000L); + Thread.sleep(count * 1000L); } catch (InterruptedException e1) { } } @@ -265,70 +278,24 @@ public class MachineUtils { || e.getMessage().contains("Could not find a registered machine with UUID {"); } - public String getIpAddressFromBridgedNIC(String machineName) { - String ip = ""; - int attempt = 0; - while (!isIpv4(ip) && attempt < 10) { - ip = this.lockSessionOnMachineAndApply(machineName, LockType.Shared, new Function() { - @Override - public String apply(ISession session) { - String ip = session.getMachine().getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP"); - return ip; - } - }); - attempt++; - long sleepTime = 1000 * attempt; - logger.debug("Instance %s is still not ready. Attempt n:%d. Sleeping for %d millisec", machineName, attempt, - sleepTime); - try { - Thread.sleep(sleepTime); - } catch (InterruptedException e) { - Throwables.propagate(e); - } + public String getIpAddressFromFirstNIC(String machineName) { + try { + return ipAddressesLoadingCache.get(machineName); + } catch (ExecutionException e) { + logger.error("Problem in using the ipAddressCache", e.getCause()); + throw Throwables.propagate(e); } - return ip; } + - private boolean isIpv4(String s) { - Pattern pattern = Pattern.compile(this.IP_V4_ADDRESS_PATTERN); + public static boolean isIpv4(String s) { + String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; + Pattern pattern = Pattern.compile(IP_V4_ADDRESS_PATTERN); Matcher matcher = pattern.matcher(s); return matcher.matches(); } - public String getIpAddressFromHostOnlyNIC(String machineName) { - // TODO using a caching mechanism to avoid to call every time this vboxmanage api call - String currentIp = "", previousIp = "1.1.1.1"; - int attempt = 0, count = 0; - while(count < 5) { - currentIp = ""; - attempt = 0; - while (!isIpv4(currentIp) && attempt < 5) { - currentIp = this.lockSessionOnMachineAndApply(machineName, LockType.Shared, new Function() { - @Override - public String apply(ISession session) { - return session.getMachine().getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP"); - } - }); - attempt++; - } - if(previousIp.equals(currentIp)) { - count++; - delayer(500l * (count + 1)); - } else { - count = 0; - delayer(5000l); - } - previousIp = currentIp; - } - return currentIp; - } - - private void delayer(long millisec) { - try { - Thread.sleep(millisec); - } catch (InterruptedException e) { - Throwables.propagate(e); - } - } } diff --git a/labs/virtualbox/src/main/resources/default-images.yaml b/labs/virtualbox/src/main/resources/default-images.yaml index 84380c2b1f..c9ed61fe71 100644 --- a/labs/virtualbox/src/main/resources/default-images.yaml +++ b/labs/virtualbox/src/main/resources/default-images.yaml @@ -15,7 +15,7 @@ images: fb=false debconf/frontend=noninteractive keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false initrd=/install/initrd.gz -- - preseed_cfg: | + preseed_cfg: | ## Options to set on the command line d-i debian-installer/locale string en_US.utf8 d-i console-setup/ask_detect boolean false @@ -132,4 +132,91 @@ images: d-i pkgsel/update-policy select none # debconf-get-selections --install #Use mirror + choose-mirror-bin mirror/http/proxy string + - id: ubuntu-12.04.1-amd64 + name: ubuntu-12.04.1-server-amd64 + description: ubuntu 12.04.1 server (amd64) + os_arch: amd64 + os_family: ubuntu + os_description: ubuntu + os_version: 12.04.1 + os_64bit: true + iso: http://releases.ubuntu.com/12.04/ubuntu-12.04.1-server-amd64.iso + username: toor + credential: $user + keystroke_sequence: | + + /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg + debian-installer=en_US auto locale=en_US kbd-chooser/method=us + hostname=vmName + fb=false debconf/frontend=noninteractive + keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false + initrd=/install/initrd.gz -- + preseed_cfg: | + ## Options to set on the command line + d-i debian-installer/locale string en_US.utf8 + d-i console-setup/ask_detect boolean false + d-i console-setup/layout string USA + #d-i netcfg/get_hostname string dummy + d-i netcfg/get_hostname string unassigned-hostname + d-i netcfg/get_domain string unassigned-domain + # Continue without a default route + # Not working , specify a dummy in the DHCP + #d-i netcfg/no_default_route boolean + d-i time/zone string UTC + d-i clock-setup/utc-auto boolean true + d-i clock-setup/utc boolean true + d-i kbd-chooser/method select American English + d-i netcfg/wireless_wep string + d-i base-installer/kernel/override-image string linux-server + #d-i base-installer/kernel/override-image string linux-image-2.6.32-21-generic + # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive + d-i debconf debconf/frontend select Noninteractive + d-i pkgsel/install-language-support boolean false + tasksel tasksel/first multiselect standard, ubuntu-server + #d-i partman-auto/method string regular + d-i partman-auto/method string lvm + #d-i partman-auto/purge_lvm_from_device boolean true + d-i partman-lvm/confirm boolean true + d-i partman-lvm/device_remove_lvm boolean true + d-i partman-auto/choose_recipe select atomic + d-i partman/confirm_write_new_label boolean true + d-i partman/confirm_nooverwrite boolean true + d-i partman/choose_partition select finish + d-i partman/confirm boolean true + #http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=9626883 + #Message: "write the changes to disk and configure lvm preseed" + #http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input + #preseed partman-lvm/confirm_nooverwrite boolean true + # Write the changes to disks and configure LVM? + d-i partman-lvm/confirm boolean true + d-i partman-lvm/confirm_nooverwrite boolean true + d-i partman-auto-lvm/guided_size string max + ## Default user, we can get away with a recipe to change this + d-i passwd/user-fullname string toor + d-i passwd/username string toor + d-i passwd/user-password password password + d-i passwd/user-password-again password password + d-i user-setup/encrypt-home boolean false + d-i user-setup/allow-password-weak boolean true + ## minimum is ssh and ntp + # Individual additional packages to install + d-i pkgsel/include string openssh-server ntp + # Whether to upgrade packages after debootstrap. + # Allowed values: none, safe-upgrade, full-upgrade + d-i pkgsel/upgrade select full-upgrade + d-i grub-installer/only_debian boolean true + d-i grub-installer/with_other_os boolean true + d-i finish-install/reboot_in_progress note + #For the update + d-i pkgsel/update-policy select none + # debconf-get-selections --install + #Use mirror + #d-i apt-setup/use_mirror boolean true + #d-i mirror/country string manual + #choose-mirror-bin mirror/protocol string http + #choose-mirror-bin mirror/http/hostname string 192.168.4.150 + #choose-mirror-bin mirror/http/directory string /ubuntu + #choose-mirror-bin mirror/suite select maverick + #d-i debian-installer/allow_unauthenticated string true choose-mirror-bin mirror/http/proxy string \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index b2c2c45213..4dbe57877d 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -119,7 +119,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT protected LoadingCache mastersCache; private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor(); - private String masterVmName; + private String masterName; @Override @@ -133,13 +133,13 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT public void setupContext() { super.setupContext(); view.utils().injector().injectMembers(this); - + // try and get a master from the cache, this will initialize the config/download isos and // prepare everything IF a master is not available, subsequent calls should be pretty fast Template template = view.getComputeService().templateBuilder().build(); checkNotNull(mastersCache.apply(template.getImage())); - masterVmName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId(); + masterName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId(); isosDir = workingDir + File.separator + "isos"; hostVersion = Iterables.get(Splitter.on('r').split(view.utils().injector().getInstance(Key.get(String.class, BuildVersion.class))), 0); @@ -173,8 +173,6 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT } public MasterSpec getMasterSpecForTest() { - String masterName = "jclouds-image-0x0-" + template.getImageId(); - StorageController ideController = StorageController .builder() .name("IDE Controller") @@ -220,7 +218,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT protected void destroyMaster() { if (System.getProperty(DONT_DESTROY_MASTER) == null || !Boolean.parseBoolean(System.getProperty(DONT_DESTROY_MASTER))) { - undoVm(masterVmName); + undoVm(masterName); } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java index 28c6001f9e..ad71c22e3f 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java @@ -20,7 +20,6 @@ package org.jclouds.virtualbox; import static org.testng.Assert.assertEquals; -import java.io.File; import java.net.URI; import java.net.URL; import java.util.Map; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java index cf3969d5bd..7cdee2d010 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java @@ -51,7 +51,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien @Test public void testCreatedNodeHasExpectedNameAndWeCanConnectViaSsh() { String group = "foo"; - String name = "foo-ef4"; + String name = "foo-ef9"; Template template = view.getComputeService().templateBuilder().build(); machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template); assertTrue(machine.getNode().getName().contains(group)); @@ -60,7 +60,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials())); } - protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { + protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { SshClient ssh = view.utils().injector().getInstance(IMachineToSshClient.class).apply(machine); try { ssh.connect(); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java index b2929b4a09..fa5e67a83f 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java @@ -36,7 +36,6 @@ import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.scriptbuilder.statements.login.AdminAccess; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; @@ -69,10 +68,10 @@ public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest { @Test public void testLaunchCluster() throws RunNodesException { - int numNodes = 2; + int numNodes = 3; final String clusterName = "test-launch-cluster"; Set nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes, - TemplateOptions.Builder.runScript(AdminAccess.standard())); + TemplateOptions.Builder.overrideLoginUser("toor")); //TODO runScript(AdminAccess.standard())); assertEquals(numNodes, nodes.size(), "wrong number of nodes"); for (NodeMetadata node : nodes) { assertTrue(node.getGroup().equals("test-launch-cluster")); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java index 31a416b4a7..575a182944 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java @@ -19,6 +19,9 @@ package org.jclouds.virtualbox.compute.extensions; +import java.util.concurrent.ExecutionException; + +import org.jclouds.compute.RunNodesException; import org.jclouds.compute.extensions.internal.BaseImageExtensionLiveTest; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; @@ -28,6 +31,22 @@ import com.google.inject.Module; @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxImageExtensionLiveTest") public class VirtualBoxImageExtensionLiveTest extends BaseImageExtensionLiveTest { + @Override + public void testDeleteImage() { + // TODO + } + + @Override + public void testCreateImage() throws RunNodesException, + InterruptedException, ExecutionException { + // TODO + } + + @Override + public void testSpawnNodeFromImage() throws RunNodesException { + // TODO + } + public VirtualBoxImageExtensionLiveTest() { provider = "virtualbox"; } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java index c5576209d3..bd25a24cff 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java @@ -24,14 +24,18 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import static org.testng.Assert.assertTrue; +import java.net.URI; import java.util.Map; +import javax.inject.Inject; + import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.json.Json; import org.jclouds.json.config.GsonModule; +import org.jclouds.location.Provider; import org.jclouds.ssh.SshClient; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.domain.CloneSpec; @@ -49,13 +53,13 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.ISession; import org.virtualbox_4_1.NetworkAttachmentType; import org.virtualbox_4_1.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.base.Supplier; import com.google.common.collect.ImmutableSet; import com.google.inject.Guice; import com.google.inject.Injector; @@ -76,44 +80,11 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { private MasterSpec machineSpec; private String instanceName; - - /* - @Override - @BeforeClass(groups = "live") - public void setupClient() { - super.setupClient(); - this.vmName = VIRTUALBOX_IMAGE_PREFIX - + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); - - HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk(vmName)).autoDelete(true).controllerPort(0) - .deviceSlot(1).build(); - StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE) - .attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build(); - vmSpecification = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).osTypeId("").controller(ideController) - .forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); - - injector = context.utils().injector(); - Function configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class); - - NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule("127.0.0.1", 2222, "", 22).build(); - - NetworkInterfaceCard networkInterfaceCard1 = NetworkInterfaceCard.builder().slot(0l) - .addNetworkAdapter(natAdapter).build(); - - NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard1).build(); - - masterSpec = MasterSpec - .builder() - .vm(vmSpecification) - .iso(IsoSpec - .builder() - .sourcePath(operatingSystemIso) - .installationScript( - configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", - vmSpecification.getVmName())).build()).network(networkSpec).build(); - }*/ + @Inject + @Provider + protected Supplier providerSupplier; + @Override @BeforeClass(groups = "live") public void setupContext() { @@ -142,11 +113,10 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", instanceVmSpec.getVmName())).build(); - NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule("127.0.0.1", 2222, "", 22).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) + NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly) .build(); - + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) + .addHostInterfaceName("vboxnet0").slot(0L).build(); NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build(); } @@ -164,12 +134,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", machine.getName()); - String version = machineUtils.sharedLockMachineAndApplyToSession(machine.getName(), new Function() { - @Override - public String apply(ISession session) { - return session.getMachine().getGuestPropertyValue("/VirtualBox/GuestAdd/Version"); - } - }); + String version = machine.getGuestPropertyValue("/VirtualBox/GuestAdd/Version"); assertTrue(version != null && !version.isEmpty()); } finally { @@ -193,7 +158,6 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { Injector injector = view.utils().injector(); return injector.getInstance(CreateAndInstallVm.class).apply(masterSpecForTest); } catch (IllegalStateException e) { - // already created return manager.get().getVBox().findMachine(masterSpecForTest.getVmSpec().getVmId()); } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java index b3b31da7d1..22016b2c20 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java @@ -64,7 +64,7 @@ public class StartVBoxIfNotAlreadyRunningLiveTest { replay(manager, runScriptOnNodeFactory, client); new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client, - Suppliers.ofInstance(host), Suppliers.ofInstance(provider)).start(); + Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null).start(); verify(manager, runScriptOnNodeFactory, client); @@ -84,26 +84,26 @@ public class StartVBoxIfNotAlreadyRunningLiveTest { expect(client.seconds(3)).andReturn(client); expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(false).once().andReturn(true).once(); - expect( - runScriptOnNodeFactory.create(host, Statements.exec("VBoxManage setproperty websrvauthlibrary null"), + expect(runScriptOnNodeFactory.create(host, + Statements.exec("VBoxManage setproperty websrvauthlibrary null"), runAsRoot(false).wrapInInitScript(false))).andReturn(runScriptOnNode); expect(runScriptOnNode.init()).andReturn(runScriptOnNode); expect(runScriptOnNode.call()).andReturn(new ExecResponse("", "", 0)); - expect( - runScriptOnNodeFactory.create(host, Statements.exec("vboxwebsrv -t 10000 -v -b"), runAsRoot(false) - .wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv"))).andReturn( - runScriptOnNode); + expect(runScriptOnNodeFactory.create(host, + Statements.exec("vboxwebsrv -t 10000 -v -b -H localhost"), runAsRoot(false) + .wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv"))) + .andReturn(runScriptOnNode); expect(runScriptOnNode.init()).andReturn(runScriptOnNode); expect(runScriptOnNode.call()).andReturn(new ExecResponse("", "", 0)); - manager.connect(provider.toASCIIString(), "", ""); + expectLastCall().anyTimes(); replay(manager, runScriptOnNodeFactory, runScriptOnNode, client); new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client, - Suppliers.ofInstance(host), Suppliers.ofInstance(provider)); + Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null); + verify(manager, runScriptOnNodeFactory, runScriptOnNode, client); - } } \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java index 8c79df17fb..b21ce39586 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java @@ -24,9 +24,6 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import static org.testng.Assert.assertTrue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.ssh.SshClient; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; @@ -42,11 +39,12 @@ import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists; import org.jclouds.virtualbox.functions.CreateAndInstallVm; import org.jclouds.virtualbox.functions.IMachineToSshClient; +import org.jclouds.virtualbox.functions.IpAddressesLoadingCache; +import org.jclouds.virtualbox.util.MachineUtils; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.ISession; import org.virtualbox_4_1.NetworkAttachmentType; import org.virtualbox_4_1.StorageBus; @@ -67,6 +65,7 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes private Predicate sshResponds; private MasterSpec machineSpec; + private IpAddressesLoadingCache ipAddressesLoadingCache; @Override @BeforeClass(groups = "live") @@ -118,21 +117,10 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes sshResponds = injector.getInstance(SshResponds.class); checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", machine.getName()); + ipAddressesLoadingCache = injector.getInstance(IpAddressesLoadingCache.class); + + assertTrue(MachineUtils.isIpv4(ipAddressesLoadingCache.apply(machine.getName()))); - assertTrue(machineUtils.sharedLockMachineAndApplyToSession(machine.getName(), - new Function() { - @Override - public Boolean apply(ISession session) { - String s = session.getMachine().getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP"); - return isIpv4(s); - } - - private boolean isIpv4(String s) { - Pattern pattern = Pattern.compile(machineUtils.IP_V4_ADDRESS_PATTERN); - Matcher matcher = pattern.matcher(s); - return matcher.matches(); - } - })); } finally { for (String vmNameOrId : ImmutableSet.of(machine.getName())) { machineController.ensureMachineHasPowerDown(vmNameOrId); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java index 2291d625c7..6b15823488 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java @@ -77,21 +77,25 @@ public class MachineControllerLiveTest extends BaseVirtualBoxClientLiveTest { .cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build(); Injector injector = view.utils().injector(); - Function configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class); + Function configProperties = injector + .getInstance(ValueOfConfigurationKeyOrNull.class); IsoSpec isoSpec = IsoSpec - .builder() - .sourcePath(operatingSystemIso) - .installationScript( - configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", - instanceVmSpec.getVmName())).build(); + .builder() + .sourcePath(operatingSystemIso) + .installationScript( + configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) + .replace("HOSTNAME", instanceVmSpec.getVmName())) + .build(); - NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule("127.0.0.1", 2222, "", 22).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) - .build(); - - NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); - machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build(); + NetworkAdapter networkAdapter = NetworkAdapter.builder() + .networkAttachmentType(NetworkAttachmentType.HostOnly).build(); + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard + .builder().addNetworkAdapter(networkAdapter) + .addHostInterfaceName("vboxnet0").slot(0L).build(); + NetworkSpec networkSpec = NetworkSpec.builder() + .addNIC(networkInterfaceCard).build(); + machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec) + .network(networkSpec).build(); } @Test @@ -106,8 +110,8 @@ public class MachineControllerLiveTest extends BaseVirtualBoxClientLiveTest { @Test(dependsOnMethods="testEnsureMachineisLaunchedAndSessionIsUnlocked") public void testEnsureMachineCanBePoweredOffMoreThanOneTimeAndSessionIsUnlocked() { ISession cloneMachineSession = machineController.ensureMachineHasPowerDown(instanceName); - cloneMachineSession = machineController.ensureMachineHasPowerDown(instanceName); - assertTrue(cloneMachineSession.getState() == SessionState.Unlocked); + SessionState state = cloneMachineSession.getState(); + assertTrue(state.equals(SessionState.Unlocked)); } private IMachine cloneFromMaster() { diff --git a/labs/virtualbox/src/test/resources/default-images.yaml b/labs/virtualbox/src/test/resources/default-images.yaml index 4efa20d277..fddcff3c4a 100644 --- a/labs/virtualbox/src/test/resources/default-images.yaml +++ b/labs/virtualbox/src/test/resources/default-images.yaml @@ -15,7 +15,7 @@ images: fb=false debconf/frontend=noninteractive keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false initrd=/install/initrd.gz -- - preseed_cfg: | + preseed_cfg: | ## Options to set on the command line d-i debian-installer/locale string en_US.utf8 d-i console-setup/ask_detect boolean false @@ -66,7 +66,7 @@ images: # debconf-get-selections --install #Use mirror choose-mirror-bin mirror/http/proxy string - - id: test-ubuntu-11.10-i386 + - id: ubuntu-11.10-i386 name: ubuntu-11.10-server-i386 description: ubuntu 11.10 server (i386) os_arch: x86 @@ -132,4 +132,90 @@ images: d-i pkgsel/update-policy select none # debconf-get-selections --install #Use mirror + choose-mirror-bin mirror/http/proxy string + - id: ubuntu-12.04.1-amd64 + name: ubuntu-12.04.1-server-amd64 + description: ubuntu 12.04.1 server (amd64) + os_arch: amd64 + os_family: ubuntu + os_description: ubuntu + os_version: 12.04.1 + os_64bit: true + iso: http://releases.ubuntu.com/12.04/ubuntu-12.04.1-server-amd64.iso + iso_md5: a8c667e871f48f3a662f3fbf1c3ddb17 + keystroke_sequence: | + + /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg + debian-installer=en_US auto locale=en_US kbd-chooser/method=us + hostname=vmName + fb=false debconf/frontend=noninteractive + keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false + initrd=/install/initrd.gz -- + preseed_cfg: | + ## Options to set on the command line + d-i debian-installer/locale string en_US.utf8 + d-i console-setup/ask_detect boolean false + d-i console-setup/layout string USA + #d-i netcfg/get_hostname string dummy + d-i netcfg/get_hostname string unassigned-hostname + d-i netcfg/get_domain string unassigned-domain + # Continue without a default route + # Not working , specify a dummy in the DHCP + #d-i netcfg/no_default_route boolean + d-i time/zone string UTC + d-i clock-setup/utc-auto boolean true + d-i clock-setup/utc boolean true + d-i kbd-chooser/method select American English + d-i netcfg/wireless_wep string + d-i base-installer/kernel/override-image string linux-server + #d-i base-installer/kernel/override-image string linux-image-2.6.32-21-generic + # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive + d-i debconf debconf/frontend select Noninteractive + d-i pkgsel/install-language-support boolean false + tasksel tasksel/first multiselect standard, ubuntu-server + #d-i partman-auto/method string regular + d-i partman-auto/method string lvm + #d-i partman-auto/purge_lvm_from_device boolean true + d-i partman-lvm/confirm boolean true + d-i partman-lvm/device_remove_lvm boolean true + d-i partman-auto/choose_recipe select atomic + d-i partman/confirm_write_new_label boolean true + d-i partman/confirm_nooverwrite boolean true + d-i partman/choose_partition select finish + d-i partman/confirm boolean true + #http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=9626883 + #Message: "write the changes to disk and configure lvm preseed" + #http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input + #preseed partman-lvm/confirm_nooverwrite boolean true + # Write the changes to disks and configure LVM? + d-i partman-lvm/confirm boolean true + d-i partman-lvm/confirm_nooverwrite boolean true + d-i partman-auto-lvm/guided_size string max + ## Default user, we can get away with a recipe to change this + d-i passwd/user-fullname string toor + d-i passwd/username string toor + d-i passwd/user-password password password + d-i passwd/user-password-again password password + d-i user-setup/encrypt-home boolean false + d-i user-setup/allow-password-weak boolean true + ## minimum is ssh and ntp + # Individual additional packages to install + d-i pkgsel/include string openssh-server ntp + # Whether to upgrade packages after debootstrap. + # Allowed values: none, safe-upgrade, full-upgrade + d-i pkgsel/upgrade select full-upgrade + d-i grub-installer/only_debian boolean true + d-i grub-installer/with_other_os boolean true + d-i finish-install/reboot_in_progress note + #For the update + d-i pkgsel/update-policy select none + # debconf-get-selections --install + #Use mirror + #d-i apt-setup/use_mirror boolean true + #d-i mirror/country string manual + #choose-mirror-bin mirror/protocol string http + #choose-mirror-bin mirror/http/hostname string 192.168.4.150 + #choose-mirror-bin mirror/http/directory string /ubuntu + #choose-mirror-bin mirror/suite select maverick + #d-i debian-installer/allow_unauthenticated string true choose-mirror-bin mirror/http/proxy string \ No newline at end of file From a0b1ffb625c95c2d78935994584e0e0969e8689c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 12 Sep 2012 21:35:41 -0700 Subject: [PATCH 14/60] externalized retry codes --- .../aws/config/AWSRestClientModule.java | 12 ++++++++++ .../handlers/AWSClientErrorRetryHandler.java | 22 ++++++++++++++----- .../AWSClientErrorRetryHandlerTest.java | 12 ++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/common/aws/src/main/java/org/jclouds/aws/config/AWSRestClientModule.java b/common/aws/src/main/java/org/jclouds/aws/config/AWSRestClientModule.java index 7915b4f088..75b4cb5c73 100644 --- a/common/aws/src/main/java/org/jclouds/aws/config/AWSRestClientModule.java +++ b/common/aws/src/main/java/org/jclouds/aws/config/AWSRestClientModule.java @@ -20,6 +20,9 @@ package org.jclouds.aws.config; import java.util.Map; +import java.util.Set; + +import javax.inject.Singleton; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; @@ -31,7 +34,9 @@ import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; +import com.google.common.collect.ImmutableSet; import com.google.common.reflect.TypeToken; +import com.google.inject.Provides; /** @@ -57,6 +62,13 @@ public abstract class AWSRestClientModule extends RestClientModule { super(syncClientType, asyncClientType, sync2Async); } + @Provides + @ClientError + @Singleton + protected Set provideRetryableCodes(){ + return ImmutableSet.of("RequestTimeout", "OperationAborted", "SignatureDoesNotMatch"); + } + @Override protected void bindErrorHandlers() { bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAWSErrorFromXmlContent.class); diff --git a/common/aws/src/main/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandler.java b/common/aws/src/main/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandler.java index f074f99a0f..b99f8b0ec0 100644 --- a/common/aws/src/main/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandler.java +++ b/common/aws/src/main/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandler.java @@ -20,14 +20,16 @@ package org.jclouds.aws.handlers; import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; +import java.util.Set; + import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.util.AWSUtils; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpRetryHandler; +import org.jclouds.http.annotation.ClientError; import org.jclouds.http.handlers.BackoffLimitedRetryHandler; -import com.google.common.collect.ImmutableSet; import com.google.inject.Inject; /** @@ -39,27 +41,35 @@ public class AWSClientErrorRetryHandler implements HttpRetryHandler { private final AWSUtils utils; private final BackoffLimitedRetryHandler backoffLimitedRetryHandler; + private final Set retryableCodes; @Inject - public AWSClientErrorRetryHandler(AWSUtils utils, BackoffLimitedRetryHandler backoffLimitedRetryHandler) { + public AWSClientErrorRetryHandler(AWSUtils utils, BackoffLimitedRetryHandler backoffLimitedRetryHandler, + @ClientError Set retryableCodes) { this.utils = utils; this.backoffLimitedRetryHandler = backoffLimitedRetryHandler; + this.retryableCodes = retryableCodes; } + @Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getStatusCode() == 400 || response.getStatusCode() == 403 || response.getStatusCode() == 409) { // Content can be null in the case of HEAD requests if (response.getPayload() != null) { closeClientButKeepContentStream(response); AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response); - if (error != null - && ImmutableSet.of("RequestTimeout", "OperationAborted", "SignatureDoesNotMatch").contains( - error.getCode())) { - return backoffLimitedRetryHandler.shouldRetryRequest(command, response); + if (error != null) { + return shouldRetryRequestOnError(command, response, error); } } } return false; } + protected boolean shouldRetryRequestOnError(HttpCommand command, HttpResponse response, AWSError error) { + if (retryableCodes.contains(error.getCode())) + return backoffLimitedRetryHandler.shouldRetryRequest(command, response); + return false; + } + } diff --git a/common/aws/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java b/common/aws/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java index 03d978f59b..2d2ab66673 100644 --- a/common/aws/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java +++ b/common/aws/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java @@ -33,6 +33,8 @@ import org.jclouds.io.Payloads; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + /** * Tests behavior of {@code AWSClientErrorRetryHandler} * @@ -49,7 +51,8 @@ public class AWSClientErrorRetryHandlerTest { replay(utils, backoffLimitedRetryHandler, command); - AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler); + AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler, + ImmutableSet. of()); assert !retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(401).build()); @@ -70,10 +73,10 @@ public class AWSClientErrorRetryHandlerTest { HttpCommand command = createMock(HttpCommand.class); HttpRequest putBucket = HttpRequest.builder().method("PUT") - .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build(); + .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build(); HttpResponse operationAborted = HttpResponse.builder().statusCode(409) - .payload(Payloads.newStringPayload(String.format("%s", code))).build(); + .payload(Payloads.newStringPayload(String.format("%s", code))).build(); expect(command.getCurrentRequest()).andReturn(putBucket); @@ -86,7 +89,8 @@ public class AWSClientErrorRetryHandlerTest { replay(utils, backoffLimitedRetryHandler, command); - AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler); + AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler, + ImmutableSet. of("RequestTimeout", "OperationAborted", "SignatureDoesNotMatch")); assert retry.shouldRetryRequest(command, operationAborted); From b0626e33242b0dd5f44fa0a578f61b700402214c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 12 Sep 2012 21:36:03 -0700 Subject: [PATCH 15/60] added tests and attributes calls to sqs --- .../src/main/java/org/jclouds/sqs/SQSApi.java | 240 +++++++++++++++--- .../java/org/jclouds/sqs/SQSApiMetadata.java | 4 + .../java/org/jclouds/sqs/SQSAsyncApi.java | 40 +++ ...BindAttributeNamesToIndexedFormParams.java | 52 ++++ .../org/jclouds/sqs/config/SQSProperties.java | 48 ++++ .../sqs/config/SQSRestClientModule.java | 19 ++ .../handlers/ParseSQSErrorFromXmlContent.java | 66 +++++ .../sqs/handlers/SQSErrorRetryHandler.java | 71 ++++++ .../jclouds/sqs/xml/AttributesHandler.java | 70 +++++ .../jclouds/sqs/xml/RegexQueueHandler.java | 2 +- .../org/jclouds/sqs/SQSApiExpectTest.java | 141 +++++++++- .../java/org/jclouds/sqs/SQSApiLiveTest.java | 97 ++++--- .../handlers/SQSErrorRetryHandlerTest.java | 137 ++++++++++ .../sqs/internal/BaseSQSApiLiveTest.java | 35 ++- .../sqs/parse/CreateQueueResponseTest.java | 54 ++++ .../parse/GetQueueAttributesResponseTest.java | 58 +++++ .../sqs/parse/ReceiveMessageResponseTest.java | 4 +- .../sqs/parse/SendMessageResponseTest.java | 10 +- labs/sqs/src/test/resources/attributes.xml | 12 + labs/sqs/src/test/resources/messages.xml | 6 +- 20 files changed, 1067 insertions(+), 99 deletions(-) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/handlers/ParseSQSErrorFromXmlContent.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java create mode 100644 labs/sqs/src/test/resources/attributes.xml diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index b164c8bc7c..0be40a4fe6 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -19,6 +19,7 @@ package org.jclouds.sqs; import java.net.URI; +import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -61,27 +62,27 @@ public interface SQSApi { Set listQueuesInRegion(@Nullable String region, ListQueuesOptions options); /** - * * The CreateQueue action creates a new queue. - *

+ * * When you request CreateQueue, you provide a name for the queue. To * successfully create a new queue, you must provide a name that is unique - * within the scope of your own queues. If you provide the name of an - * existing queue, a new queue isn't created and an error isn't returned. - * Instead, the request succeeds and the queue URL for the existing queue is - * returned (for more information about queue URLs, see Queue and Message - * Identifiers in the Amazon SQS Developer Guide). Exception: if you provide - * a value for DefaultVisibilityTimeout that is different from the value for - * the existing queue, you receive an error. - *

Note

+ * within the scope of your own queues. + * + *

Note

* * If you delete a queue, you must wait at least 60 seconds before creating a * queue with the same name. - *

- * A default value for the queue's visibility timeout (30 seconds) is set - * when the queue is created. You can override this value with the - * DefaultVisibilityTimeout request parameter. For more information, see - * Visibility Timeout in the Amazon SQS Developer Guide. + * + * If you provide the name of an existing queue, along with the exact names + * and values of all the queue's attributes, CreateQueue returns the queue + * URL for the existing queue. If the queue name, attribute names, or + * attribute values do not match an existing queue, CreateQueue returns an + * error. + * + *

Tip

+ * + * Use GetQueueUrl to get a queue's URL. GetQueueUrl requires only the + * QueueName parameter. * * @param region * Queues are Region-specific. @@ -89,29 +90,39 @@ public interface SQSApi { * The name to use for the queue created. Constraints: Maximum 80 * characters; alphanumeric characters, hyphens (-), and * underscores (_) are allowed. - * @param options - * like the visibility timeout (in seconds) to use for this queue. */ + // this will gracefully attempt to resolve name issues + @Timeout(duration = 61, timeUnit = TimeUnit.SECONDS) URI createQueueInRegion(@Nullable String region, String queueName); + /** + * same as {@link #createQueueInRegion(String, String)} except you can + * control options such as delay seconds. + * + * @param options + * options such as delay seconds + * @see #createQueueInRegion(String, String) + */ + @Timeout(duration = 61, timeUnit = TimeUnit.SECONDS) URI createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions options); /** * The DeleteQueue action deletes the queue specified by the queue URL, * regardless of whether the queue is empty. If the specified queue does not - * exist, SQS returns a successful response.

- * Caution

+ * exist, SQS returns a successful response. + * + *

Caution

* * Use DeleteQueue with care; once you delete your queue, any messages in the * queue are no longer available. - *

+ * * When you delete a queue, the deletion process takes up to 60 seconds. * Requests you send involving that queue during the 60 seconds might * succeed. For example, a SendMessage request might succeed, but after the * 60 seconds, the queue and that message you sent no longer exist. Also, * when you delete a queue, you must wait at least 60 seconds before creating * a queue with the same name. - *

+ * * We reserve the right to delete queues that have had no activity for more * than 30 days. For more information, see About SQS Queues in the Amazon SQS * Developer Guide. @@ -121,37 +132,204 @@ public interface SQSApi { */ void deleteQueue(URI queue); + /** + * The DeleteMessage action deletes the specified message from the specified + * queue. You specify the message by using the message's receipt handle and + * not the message ID you received when you sent the message. Even if the + * message is locked by another reader due to the visibility timeout setting, + * it is still deleted from the queue. If you leave a message in the queue + * for more than 4 days, SQS automatically deletes it. + * + *

Note

+ * + * The receipt handle is associated with a specific instance of receiving the + * message. If you receive a message more than once, the receipt handle you + * get each time you receive the message is different. When you request + * DeleteMessage, if you don't provide the most recently received receipt + * handle for the message, the request will still succeed, but the message + * might not be deleted. + * + *

Important

+ * + * It is possible you will receive a message even after you have deleted it. + * This might happen on rare occasions if one of the servers storing a copy + * of the message is unavailable when you request to delete the message. The + * copy remains on the server and might be returned to you again on a + * subsequent receive request. You should create your system to be idempotent + * so that receiving a particular message more than once is not a problem. + * + * @param queue + * the queue the message is in + * @param receiptHandle + * The receipt handle associated with the message you want to + * delete. + */ + void deleteMessage(URI queue, String receiptHandle); + /** * The SendMessage action delivers a message to the specified queue. The - * maximum allowed message size is 8 KB. - *

- * Important - *

+ * maximum allowed message size is 64 KB. + * + *

Important

+ * * The following list shows the characters (in Unicode) allowed in your * message, according to the W3C XML specification (for more information, go * to http://www.w3.org/TR/REC-xml/#charsets). If you send any characters not * included in the list, your request will be rejected. - *

- * #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to - * #x10FFFF] + * + * + * {@code #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]} * * @param queue * queue you want to send to * * @param message - * The message to send. Type: String maximum 8 KB in size. For a - * list of allowed characters, see the preceding important note - * @return md5 of the content sent + * Type: String maximum 64 KB in size. For a list of allowed + * characters, see the preceding important note. + * @return id of the message and md5 of the content sent */ MessageIdAndMD5 sendMessage(URI queue, String message); + /** + * same as {@link #sendMessage(URI, String)} except you can control options + * such as delay seconds. + * + * @param options + * options such as delay seconds + * @see #sendMessage(URI, String) + */ MessageIdAndMD5 sendMessage(URI queue, String message, SendMessageOptions options); + /** + * The ReceiveMessage action retrieves one or more messages from the + * specified queue. The ReceiveMessage action does not delete the message + * after it is retrieved. To delete a message, you must use the DeleteMessage + * action. For more information about message deletion in the message life + * cycle, see Message Lifecycle. + * + *

Note

+ * + * Due to the distributed nature of the queue, a weighted random set of + * machines is sampled on a ReceiveMessage call. That means only the messages + * on the sampled machines are returned. If the number of messages in the + * queue is small (less than 1000), it is likely you will get fewer messages + * than you requested per ReceiveMessage call. If the number of messages in + * the queue is extremely small, you might not receive any messages in a + * particular ReceiveMessage response; in which case you should repeat the + * request. + * + * @param queue + * from where you are receiving messages + * @return message including the receipt handle you can use to delete it + */ Message receiveMessage(URI queue); + /** + * same as {@link #receiveMessage(URI)} except you can provide options like + * VisibilityTimeout parameter in your request, which will be applied to the + * messages that SQS returns in the response. If you do not include the + * parameter, the overall visibility timeout for the queue is used for the + * returned messages. + * + * @param options + * options such as VisibilityTimeout + * @see #receiveMessage(URI) + */ Message receiveMessage(URI queue, ReceiveMessageOptions options); + /** + * same as {@link #receiveMessage(URI)} except you can receive multiple + * messages. + * + * @param max + * maximum messages to receive, current limit is 10 + * @see #receiveMessage(URI) + */ Set receiveMessages(URI queue, int max); + /** + * returns all attributes of a queue. + * + * @param queue + * queue to get the attributes of + */ + Map getQueueAttributes(URI queue); + + /** + * The SetQueueAttributes action sets one attribute of a queue per request. + * When you change a queue's attributes, the change can take up to 60 seconds + * to propagate throughout the SQS system. + * + * @param queue + * queue to set the attribute on + * @param name + * + * The name of the attribute you want to set. + * + * VisibilityTimeout - The length of time (in seconds) that a + * message received from a queue will be invisible to other + * receiving components when they ask to receive messages. For more + * information about VisibilityTimeout, see Visibility Timeout in + * the Amazon SQS Developer Guide. + * + * Policy - The formal description of the permissions for a + * resource. For more information about Policy, see Basic Policy + * Structure in the Amazon SQS Developer Guide. + * + * MaximumMessageSize - The limit of how many bytes a message can + * contain before Amazon SQS rejects it. + * + * MessageRetentionPeriod - The number of seconds Amazon SQS + * retains a message. + * + * DelaySeconds - The time in seconds that the delivery of all + * messages in the queue will be delayed. + * @param value + * The value of the attribute you want to set. To delete a queue's + * access control policy, set the policy to "". + * + * Constraints: Constraints are specific for each value. + * + * VisibilityTimeout - An integer from 0 to 43200 (12 hours). The + * default for this attribute is 30 seconds. + * + * Policy - A valid form-url-encoded policy. For more information + * about policy structure, see Basic Policy Structure in the Amazon + * SQS Developer Guide. For more information about + * form-url-encoding, see + * http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1. + * + * MaximumMessageSize - An integer from 1024 bytes (1 KiB) up to + * 65536 bytes (64 KiB). The default for this attribute is 65536 + * (64 KiB). + * + * MessageRetentionPeriod - Integer representing seconds, from 60 + * (1 minute) to 1209600 (14 days). The default for this attribute + * is 345600 (4 days). + * + * DelaySeconds - An integer from 0 to 900 (15 minutes). The + * default for this attribute is 0. + */ + void setQueueAttribute(URI queue, String name, String value); + + /** + * returns some attributes of a queue. + * + * @param queue + * queue to get the attributes of + */ + Map getQueueAttributes(URI queue, Iterable attributeNames); + + /** + * same as {@link #receiveMessages(URI, int)} except you can provide options + * like VisibilityTimeout parameter in your request, which will be applied to + * the messages that SQS returns in the response. If you do not include the + * parameter, the overall visibility timeout for the queue is used for the + * returned messages. + * + * @param options + * options such as VisibilityTimeout + * @see #receiveMessages(URI, int) + */ Set receiveMessages(URI queue, int max, ReceiveMessageOptions options); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java index 6c23ba0dba..04081df106 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java @@ -20,6 +20,8 @@ package org.jclouds.sqs; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; +import static org.jclouds.sqs.config.SQSProperties.CREATE_QUEUE_MAX_RETRIES; +import static org.jclouds.sqs.config.SQSProperties.CREATE_QUEUE_RETRY_INTERVAL; import java.net.URI; import java.util.Properties; @@ -62,6 +64,8 @@ public class SQSApiMetadata extends BaseRestApiMetadata { public static Properties defaultProperties() { Properties properties = BaseRestApiMetadata.defaultProperties(); + properties.setProperty(CREATE_QUEUE_MAX_RETRIES, "60"); + properties.setProperty(CREATE_QUEUE_RETRY_INTERVAL, "1000"); properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); properties.setProperty(PROPERTY_HEADER_TAG, "amz"); return properties; diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index cdb88d9275..8099acd174 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -22,6 +22,7 @@ import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.jclouds.sqs.reference.SQSParameters.VERSION; import java.net.URI; +import java.util.Map; import java.util.Set; import javax.ws.rs.FormParam; @@ -32,18 +33,21 @@ import org.jclouds.Constants; import org.jclouds.aws.filters.FormSigner; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams; import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.domain.MessageIdAndMD5; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; import org.jclouds.sqs.options.ReceiveMessageOptions; import org.jclouds.sqs.options.SendMessageOptions; +import org.jclouds.sqs.xml.AttributesHandler; import org.jclouds.sqs.xml.MessageHandler; import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; @@ -114,6 +118,14 @@ public interface SQSAsyncApi { @FormParams(keys = ACTION, values = "DeleteQueue") ListenableFuture deleteQueue(@EndpointParam URI queue); + /** + * @see SQSApi#deleteMessage + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteMessage") + ListenableFuture deleteMessage(@EndpointParam URI queue, @FormParam("ReceiptHandle") String receiptHandle); + /** * @see SQSApi#sendMessage */ @@ -151,6 +163,34 @@ public interface SQSAsyncApi { @XMLResponseParser(MessageHandler.class) ListenableFuture receiveMessage(@EndpointParam URI queue, ReceiveMessageOptions options); + /** + * @see SQSApi#getQueueAttributes(URI) + */ + @POST + @Path("/") + @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" }) + @XMLResponseParser(AttributesHandler.class) + ListenableFuture> getQueueAttributes(@EndpointParam URI queue); + + /** + * @see SQSApi#getQueueAttributes(URI, Iterable) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "GetQueueAttributes") + @XMLResponseParser(AttributesHandler.class) + ListenableFuture> getQueueAttributes(@EndpointParam URI queue, + @BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable attributeNames); + + /** + * @see SQSApi#setQueueAttribute + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SetQueueAttributes") + ListenableFuture setQueueAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name, + @FormParam("Attribute.Value") String value); + /** * @see SQSApi#receiveMessages */ diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java new file mode 100644 index 0000000000..13edefe1f6 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java @@ -0,0 +1,52 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.binders; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableMultimap.Builder; + +/** + * Binds the Iterable to form parameters named with AttributeName.index + * + * @author Adrian Cole + */ +@Singleton +public class BindAttributeNamesToIndexedFormParams implements Binder { + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + Iterable values = Iterable.class.cast(checkNotNull(input, "attributeNames")); + Builder builder = ImmutableMultimap.builder(); + int i = 0; + for (Object o : values) { + builder.put("AttributeName." + (i++ + 1), o.toString()); + } + ImmutableMultimap forms = builder.build(); + return (R) (forms.size() == 0 ? request : request.toBuilder().replaceFormParams(forms).build()); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java new file mode 100644 index 0000000000..5833672c79 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.config; + + +/** + * Configuration properties and constants used in SQS connections. + * + * @author Adrian Cole + */ +public interface SQSProperties { + + /** + * Integer property. + *

+ * When creating a queue, you can encounter + * {@code AWS.SimpleQueueService.QueueDeletedRecently}, which is typically a + * resolvable error. default tries are 60, + */ + public static final String CREATE_QUEUE_MAX_RETRIES = "jclouds.sqs.create-queue.max-retries"; + + /** + * Long property. + *

+ * When creating a queue, you can encounter + * {@code AWS.SimpleQueueService.QueueDeletedRecently}, which is typically a + * resolvable error. default interval between tries is 1000 milliseconds (1 + * second). + */ + public static final String CREATE_QUEUE_RETRY_INTERVAL = "jclouds.sqs.create-queue.retry-interval"; + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java index bcf8de4c65..ea7fe2192b 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java @@ -19,9 +19,16 @@ package org.jclouds.sqs.config; import org.jclouds.aws.config.FormSigningRestClientModule; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpRetryHandler; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.sqs.SQSApi; import org.jclouds.sqs.SQSAsyncApi; +import org.jclouds.sqs.handlers.ParseSQSErrorFromXmlContent; +import org.jclouds.sqs.handlers.SQSErrorRetryHandler; import com.google.common.reflect.TypeToken; @@ -37,4 +44,16 @@ public class SQSRestClientModule extends FormSigningRestClientModule resourceNotFoundCodes = ImmutableSet.of("AWS.SimpleQueueService.NonExistentQueue"); + protected Set illegalStateCodes = ImmutableSet.of("AWS.SimpleQueueService.QueueDeletedRecently", + "AWS.SimpleQueueService.QueueNameExists"); + protected Set illegalArgumentCodes = ImmutableSet.of("InvalidAttributeName", "ReadCountOutOfRange", + "InvalidMessageContents", "MessageTooLong"); + + @Inject + public ParseSQSErrorFromXmlContent(AWSUtils utils) { + super(utils); + } + + @Override + protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, AWSError error, + String message) { + String errorCode = (error != null && error.getCode() != null) ? error.getCode() : null; + if (resourceNotFoundCodes.contains(errorCode)) + exception = new ResourceNotFoundException(message, exception); + else if (illegalStateCodes.contains(errorCode)) + exception = new IllegalStateException(message, exception); + else if (illegalArgumentCodes.contains(errorCode)) + exception = new IllegalArgumentException(message, exception); + else + exception = super.refineException(command, response, exception, error, message); + return exception; + } +} \ No newline at end of file diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java new file mode 100644 index 0000000000..7af16804b2 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.handlers; + +import static org.jclouds.sqs.config.SQSProperties.CREATE_QUEUE_MAX_RETRIES; +import static org.jclouds.sqs.config.SQSProperties.CREATE_QUEUE_RETRY_INTERVAL; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import javax.inject.Named; + +import org.jclouds.aws.domain.AWSError; +import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; +import org.jclouds.aws.util.AWSUtils; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.handlers.BackoffLimitedRetryHandler; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.util.concurrent.Uninterruptibles; +import com.google.inject.Inject; + +/** + * + * @author Adrian Cole + */ +public class SQSErrorRetryHandler extends AWSClientErrorRetryHandler { + + private final long retryInterval; + private final int maxTries; + + @Inject + public SQSErrorRetryHandler(AWSUtils utils, BackoffLimitedRetryHandler backoffLimitedRetryHandler, + @ClientError Set retryableCodes, @Named(CREATE_QUEUE_MAX_RETRIES) int maxTries, + @Named(CREATE_QUEUE_RETRY_INTERVAL) long retryInterval) { + super(utils, backoffLimitedRetryHandler, retryableCodes); + this.maxTries = maxTries; + this.retryInterval = retryInterval; + } + + @VisibleForTesting + public boolean shouldRetryRequestOnError(HttpCommand command, HttpResponse response, AWSError error) { + if ("AWS.SimpleQueueService.QueueDeletedRecently".equals(error.getCode())) { + if (command.incrementFailureCount() - 1 < maxTries) { + Uninterruptibles.sleepUninterruptibly(retryInterval, TimeUnit.MILLISECONDS); + return true; + } + return false; + } + return super.shouldRetryRequestOnError(command, response, error); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java new file mode 100644 index 0000000000..eb9ea4c2c4 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; + +/** + * @see + * + * @author Adrian Cole + */ +public class AttributesHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { + + private StringBuilder currentText = new StringBuilder(); + private Builder builder = ImmutableMap. builder(); + private String name; + + @Override + public Map getResult() { + try { + return builder.build(); + } catch (NullPointerException e) { + return null; + } finally { + builder = ImmutableMap. builder(); + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals("Name")) { + this.name = currentOrNull(currentText); + } else if (qName.equals("Value")) { + builder.put(this.name, currentOrNull(currentText)); + this.name = null; + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java index e79a763b74..1308545044 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java @@ -42,7 +42,7 @@ public class RegexQueueHandler extends BaseRegexQueueHandler implements Function private final ReturnStringIf2xx returnStringIf200; @Inject - RegexQueueHandler(ReturnStringIf2xx returnStringIf200) { + public RegexQueueHandler(ReturnStringIf2xx returnStringIf200) { this.returnStringIf200 = returnStringIf200; } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java index 10b636ff14..2ccbd1f259 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java @@ -25,10 +25,13 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.sqs.internal.BaseSQSApiExpectTest; +import org.jclouds.sqs.parse.CreateQueueResponseTest; +import org.jclouds.sqs.parse.GetQueueAttributesResponseTest; import org.jclouds.sqs.parse.ReceiveMessageResponseTest; import org.jclouds.sqs.parse.SendMessageResponseTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; /** @@ -37,7 +40,30 @@ import com.google.common.collect.Iterables; @Test(groups = "unit", testName = "SQSApiExpectTest") public class SQSApiExpectTest extends BaseSQSApiExpectTest { - HttpRequest sendMessage = HttpRequest.builder() + public HttpRequest createQueue = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "CreateQueue") + .addFormParam("QueueName", "queueName") + .addFormParam("Signature", "I7tmwiCzJ9cvw79pmlz1rOILh2C2ZV6OpLk23JGx6AU%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testCreateQueueWhenResponseIs2xx() throws Exception { + + HttpResponse createQueueResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/create_queue.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(createQueue, createQueueResponse); + + assertEquals(apiWhenExist.createQueueInRegion(null, "queueName").toString(), new CreateQueueResponseTest().expected().toString()); + } + + public HttpRequest sendMessage = HttpRequest.builder() .method("POST") .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") .addHeader("Host", "sqs.us-east-1.amazonaws.com") @@ -61,7 +87,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { } - HttpRequest receiveMessage = HttpRequest.builder() + public HttpRequest receiveMessage = HttpRequest.builder() .method("POST") .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") .addHeader("Host", "sqs.us-east-1.amazonaws.com") @@ -86,7 +112,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { } - HttpRequest receiveMessages = HttpRequest.builder() + public HttpRequest receiveMessages = HttpRequest.builder() .method("POST") .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") .addHeader("Host", "sqs.us-east-1.amazonaws.com") @@ -110,4 +136,113 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { apiWhenExist.receiveMessages(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), 10) .toString(), new ReceiveMessageResponseTest().expected().toString()); } + + public HttpRequest deleteMessage = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "DeleteMessage") + .addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe") + .addFormParam("Signature", "9%2FkuCc2i78gMsmul%2BRsOPcdQ1OLUKrItqgGIRRBJb8M%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testDeleteMessageWhenResponseIs2xx() throws Exception { + + HttpResponse deleteMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(deleteMessage, deleteMessageResponse); + + apiWhenExist.deleteMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), + "eXJYhj5rDr9cAe"); + } + + public HttpRequest getQueueAttributes = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "GetQueueAttributes") + .addFormParam("AttributeName.1", "All") + .addFormParam("Signature", "welFLn0TV6JlH6s6s60XZTJeJfFXGiXN4qNPrBx7aHc%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testGetQueueAttributesWhenResponseIs2xx() throws Exception { + + HttpResponse getQueueAttributesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/attributes.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(getQueueAttributes, getQueueAttributesResponse); + + assertEquals(apiWhenExist.getQueueAttributes(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")).toString(), new GetQueueAttributesResponseTest().expected().toString()); + } + + public HttpRequest getQueueAttributesSubset = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "GetQueueAttributes") + .addFormParam("AttributeName.1", "VisibilityTimeout") + .addFormParam("AttributeName.2", "DelaySeconds") + .addFormParam("Signature", "9KaiOOWWyFPTVMOnyHA3ZoXbPBPSD4AZ4q460UNMfDs%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testGetQueueAttributesSubsetWhenResponseIs2xx() throws Exception { + + HttpResponse getQueueAttributesSubsetResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/attributes.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(getQueueAttributesSubset, getQueueAttributesSubsetResponse); + + assertEquals( + apiWhenExist.getQueueAttributes( + URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), + ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(), + new GetQueueAttributesResponseTest().expected().toString()); + } + + public HttpRequest setQueueAttribute = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SetQueueAttributes") + .addFormParam("Attribute.Name", "MaximumMessageSize") + .addFormParam("Attribute.Value", "1") + .addFormParam("Signature", "ktBkQ3c%2FrwGcBSec0fkckfo73xmcoTuub5fxudM1qh0%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSetQueueAttributeWhenResponseIs2xx() throws Exception { + + HttpResponse setQueueAttributeResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(setQueueAttribute, setQueueAttributeResponse); + + apiWhenExist.setQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), + "MaximumMessageSize", "1"); + } + } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index eddb8356f8..eb6a8db36d 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -19,18 +19,17 @@ package org.jclouds.sqs; import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; +import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; import java.net.URI; +import java.util.Map; import java.util.Set; import java.util.SortedSet; -import org.jclouds.aws.AWSResponseException; import org.jclouds.sqs.internal.BaseSQSApiLiveTest; -import org.jclouds.sqs.options.ReceiveMessageOptions; -import org.testng.annotations.AfterTest; +import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import com.google.common.base.Charsets; @@ -55,7 +54,7 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { } protected void listQueuesInRegion(String region) throws InterruptedException { - SortedSet allResults = Sets.newTreeSet(context.getApi().listQueuesInRegion(region)); + SortedSet allResults = Sets.newTreeSet(api().listQueuesInRegion(region)); assertNotNull(allResults); if (allResults.size() >= 1) { URI queue = allResults.last(); @@ -66,35 +65,17 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { public static final String PREFIX = System.getProperty("user.name") + "-sqs"; @Test - protected void testCreateQueue() throws InterruptedException { - createQueueInRegion(null, PREFIX + "1"); + protected void testCanRecreateQueueGracefully() throws InterruptedException { + recreateQueueInRegion(PREFIX + "1", null); + recreateQueueInRegion(PREFIX + "1", null); } - public String createQueueInRegion(final String region, String queueName) throws InterruptedException { - try { - Set result = context.getApi().listQueuesInRegion(region, queuePrefix(queueName)); - if (result.size() >= 1) { - context.getApi().deleteQueue(Iterables.getLast(result)); - queueName += 1;// cannot recreate a queue within 60 seconds - } - } catch (Exception e) { - - } - URI queue = null; - int tries = 0; - while (queue == null && tries < 5) { - try { - tries++; - queue = context.getApi().createQueueInRegion(region, queueName); - } catch (AWSResponseException e) { - queueName += "1"; - if (e.getError().getCode().equals("AWS.SimpleQueueService.QueueDeletedRecently"))// TODO - // retry - // handler - continue; - throw e; - } + public String recreateQueueInRegion(String queueName, String region) throws InterruptedException { + Set result = api().listQueuesInRegion(region, queuePrefix(queueName)); + if (result.size() >= 1) { + api().deleteQueue(Iterables.getLast(result)); } + URI queue = api().createQueueInRegion(region, queueName); assertQueueInList(region, queue); queues.add(queue); return queueName; @@ -103,35 +84,53 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { String message = "hardyharhar"; HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); - @Test(dependsOnMethods = "testCreateQueue") + @Test(dependsOnMethods = "testCanRecreateQueueGracefully") + protected void testGetQueueAttributes() { + for (URI queue : queues) { + Map attributes = api().getQueueAttributes(queue); + assertEquals(api().getQueueAttributes(queue, attributes.keySet()), attributes); + } + } + @Test(dependsOnMethods = "testCanRecreateQueueGracefully") + protected void testSetQueueAttribute() { + for (URI queue : queues) { + api().setQueueAttribute(queue, "MaximumMessageSize", "1024"); + assertEquals(api().getQueueAttributes(queue).get("MaximumMessageSize"), "1024"); + } + } + @Test(dependsOnMethods = "testCanRecreateQueueGracefully") protected void testSendMessage() { for (URI queue : queues) { - assertEquals(context.getApi().sendMessage(queue, message).getMD5(), md5); + assertEquals(api().sendMessage(queue, message).getMD5(), md5); } } @Test(dependsOnMethods = "testSendMessage") - protected void testReceiveMessage() { + protected void testReceiveMessageWithoutHidingMessage() { for (URI queue : queues) { - assertEquals(context.getApi().receiveMessage(queue, ReceiveMessageOptions.Builder.attribute("All")).getMD5(), - md5); + assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5); } } - private void assertQueueInList(final String region, URI queue) throws InterruptedException { - final URI finalQ = queue; - assertEventually(new Runnable() { - public void run() { - Set result = context.getApi().listQueuesInRegion(region); - assertNotNull(result); - assert result.size() >= 1 : result; - assertTrue(result.contains(finalQ), finalQ + " not in " + result); - } - }); + @Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage") + protected void testDeleteMessage() throws InterruptedException { + for (URI queue : queues) { + String receiptHandle = api().receiveMessage(queue, attribute("None").visibilityTimeout(0)).getReceiptHandle(); + api().deleteMessage(queue, receiptHandle); + assertNoMessages(queue); + } } - @AfterTest - public void shutdown() { - context.close(); + @Override + @AfterClass(groups = "live") + protected void tearDownContext() { + for (URI queue : queues) { + api().deleteQueue(queue); + } + super.tearDownContext(); + } + + protected SQSApi api() { + return context.getApi(); } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java new file mode 100644 index 0000000000..b5b9bfcb64 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java @@ -0,0 +1,137 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.handlers; + +import static org.easymock.EasyMock.createMock; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.aws.domain.AWSError; +import org.jclouds.aws.util.AWSUtils; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.handlers.BackoffLimitedRetryHandler; +import org.testng.annotations.Test; + +import com.google.common.base.Stopwatch; +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code SQSErrorRetryHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "SQSErrorRetryHandlerTest") +public class SQSErrorRetryHandlerTest { + + String code = "AWS.SimpleQueueService.QueueDeletedRecently"; + AWSError error; + HttpResponse response = HttpResponse.builder().statusCode(400) + .payload(String.format("%s", code)).build(); + + public SQSErrorRetryHandlerTest() { + error = new AWSError(); + error.setCode(code); + } + + public void testQueueDeletedRecentlyRetriesWhen59SleepsAndTries() { + + SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), + createMock(BackoffLimitedRetryHandler.class), ImmutableSet. of(), 60, 100); + + HttpCommand command = createHttpCommandForFailureCount(59); + + Stopwatch watch = new Stopwatch().start(); + assertTrue(retry.shouldRetryRequestOnError(command, response, error)); + assertEquals(command.getFailureCount(), 60); + assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) >= 100); + } + + + + public void testQueueDeletedRecentlyRetriesWhen60DoesntTry() { + + SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class), + createMock(BackoffLimitedRetryHandler.class), ImmutableSet. of(), 60, 100); + + HttpCommand command = createHttpCommandForFailureCount(60); + + Stopwatch watch = new Stopwatch().start(); + assertFalse(retry.shouldRetryRequestOnError(command, response, error)); + assertEquals(command.getFailureCount(), 61); + assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) < 100); + } + + //TODO: make a builder for this + HttpCommand createHttpCommandForFailureCount(final int failureCount) { + return new HttpCommand() { + int fCount = failureCount; + + @Override + public int incrementRedirectCount() { + return 0; + } + + @Override + public int getRedirectCount() { + return 0; + } + + @Override + public boolean isReplayable() { + return false; + } + + @Override + public int incrementFailureCount() { + return ++fCount; + } + + @Override + public int getFailureCount() { + return fCount; + } + + @Override + public HttpRequest getCurrentRequest() { + return null; + } + + @Override + public void setCurrentRequest(HttpRequest request) { + + } + + @Override + public void setException(Exception exception) { + } + + @Override + public Exception getException() { + return null; + } + }; + } + + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index 1d0b35e2fa..ace17bdd8c 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -18,11 +18,19 @@ */ package org.jclouds.sqs.internal; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Set; + import org.jclouds.apis.BaseContextLiveTest; import org.jclouds.rest.RestContext; import org.jclouds.sqs.SQSApi; import org.jclouds.sqs.SQSApiMetadata; import org.jclouds.sqs.SQSAsyncApi; +import org.jclouds.sqs.domain.Message; import org.testng.annotations.Test; import com.google.common.reflect.TypeToken; @@ -37,12 +45,37 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest> contextType() { return SQSApiMetadata.CONTEXT_TOKEN; } + protected void assertNoMessages(final URI queue) throws InterruptedException { + assertEventually(new Runnable() { + public void run() { + Message message = api().receiveMessage(queue); + assertNull(message, "message: " + message + " left in queue " + queue); + } + }); + } + + protected void assertQueueInList(final String region, URI queue) throws InterruptedException { + final URI finalQ = queue; + assertEventually(new Runnable() { + public void run() { + Set result = api().listQueuesInRegion(region); + assertNotNull(result); + assert result.size() >= 1 : result; + assertTrue(result.contains(finalQ), finalQ + " not in " + result); + } + }); + } + + private SQSApi api() { + return context.getApi(); + } + private static final int INCONSISTENCY_WINDOW = 10000; /** diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java new file mode 100644 index 0000000000..f3d92264ca --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java @@ -0,0 +1,54 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ReturnStringIf2xx; +import org.jclouds.sqs.xml.RegexQueueHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "CreateQueueResponseTest") +public class CreateQueueResponseTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/create_queue.xml"); + + URI expected = expected(); + + RegexQueueHandler handler = new RegexQueueHandler(new ReturnStringIf2xx()); + URI result = handler.apply(HttpResponse.builder().statusCode(200).payload(is).build()); + + assertEquals(result.toString(), expected.toString()); + + } + + public URI expected() { + return URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11"); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java new file mode 100644 index 0000000000..553f0bfbbd --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Map; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.sqs.xml.AttributesHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "GetQueueAttributesResponseTest") +public class GetQueueAttributesResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/attributes.xml"); + + Map expected = expected(); + + AttributesHandler handler = injector.getInstance(AttributesHandler.class); + Map result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public Map expected() { + return ImmutableMap.builder() + .put("VisibilityTimeout", "30") + .put("DelaySeconds", "0") + .build(); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java index c06baba868..d345656efd 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java @@ -57,9 +57,7 @@ public class ReceiveMessageResponseTest extends BaseHandlerTest { .builder() .id("5fea7756-0ea4-451a-a703-a558b933e274") .receiptHandle( - "MbZj6wDWli+JvwwJaBV+3dcjk2YW2vA3+STFFljTM8tJJg6HRG6PYSasuWXPJB+Cw" + "\n" - + " Lj1FjgXUv1uSj1gUPAWV66FU/WeR4mq2OKpEGYWbnLmpRCJVAyeMjeU5ZBdtcQ+QE" + "\n" - + " auMZc8ZRv37sIW2iJKq3M9MFx1YvV11A2x/KSbkJ0=") + "+eXJYhj5rDr9cAe/9BuheT5fysi9BoqtEZSkO7IazVbNHg60eCCINxLqaSVv2pFHrWeWNpZwbleSkWRbCtZaQGgpOx/3cWJZiNSG1KKlJX4IOwISFvb3FwByMx4w0lnINeXzcw2VcKQXNrCatO9gdIiVPvJC3SCKatYM/7YTidtjqc8igrtYW2E2mHlCy3NXPCeXxP4tSvyEwIxpDAmMT7IF0mWvTHS6+JBUtFUsrmi61oIHlESNrD1OjdB1QQw+kdvJ6VbsntbJNNYKw+YqdqWNpZkiGQ8y1z9OdHsr1+4=") .md5(HashCodes.fromBytes(CryptoStreams.hex("fafb00f5732ab283681e124bf8747ed1"))) .body("This is a test message") .addAttribute("SenderId", "195004372649") diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java index 1ede1dc154..c49c5d294f 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java @@ -44,17 +44,15 @@ public class SendMessageResponseTest { MessageIdAndMD5 expected = expected(); - RegexMessageIdAndMD5Handler handler = new RegexMessageIdAndMD5Handler( new ReturnStringIf2xx ()); + RegexMessageIdAndMD5Handler handler = new RegexMessageIdAndMD5Handler(new ReturnStringIf2xx()); MessageIdAndMD5 result = handler.apply(HttpResponse.builder().statusCode(200).payload(is).build()); assertEquals(result.toString(), expected.toString()); } - + public MessageIdAndMD5 expected() { - return MessageIdAndMD5.builder() - .id("c332b2b0-b61f-42d3-8832-d03ebd89f68d") - .md5(HashCodes.fromBytes(CryptoStreams.hex("e32aedf2b2b25355d04b1507055532e6"))) - .build(); + return MessageIdAndMD5.builder().id("c332b2b0-b61f-42d3-8832-d03ebd89f68d") + .md5(HashCodes.fromBytes(CryptoStreams.hex("e32aedf2b2b25355d04b1507055532e6"))).build(); } } diff --git a/labs/sqs/src/test/resources/attributes.xml b/labs/sqs/src/test/resources/attributes.xml new file mode 100644 index 0000000000..2ae6de4e68 --- /dev/null +++ b/labs/sqs/src/test/resources/attributes.xml @@ -0,0 +1,12 @@ + + + + VisibilityTimeout + 30 + + + DelaySeconds + 0 + + + \ No newline at end of file diff --git a/labs/sqs/src/test/resources/messages.xml b/labs/sqs/src/test/resources/messages.xml index 496b15980b..fd3224156d 100644 --- a/labs/sqs/src/test/resources/messages.xml +++ b/labs/sqs/src/test/resources/messages.xml @@ -4,11 +4,7 @@ 5fea7756-0ea4-451a-a703-a558b933e274 - - MbZj6wDWli+JvwwJaBV+3dcjk2YW2vA3+STFFljTM8tJJg6HRG6PYSasuWXPJB+Cw - Lj1FjgXUv1uSj1gUPAWV66FU/WeR4mq2OKpEGYWbnLmpRCJVAyeMjeU5ZBdtcQ+QE - auMZc8ZRv37sIW2iJKq3M9MFx1YvV11A2x/KSbkJ0= - + +eXJYhj5rDr9cAe/9BuheT5fysi9BoqtEZSkO7IazVbNHg60eCCINxLqaSVv2pFHrWeWNpZwbleSkWRbCtZaQGgpOx/3cWJZiNSG1KKlJX4IOwISFvb3FwByMx4w0lnINeXzcw2VcKQXNrCatO9gdIiVPvJC3SCKatYM/7YTidtjqc8igrtYW2E2mHlCy3NXPCeXxP4tSvyEwIxpDAmMT7IF0mWvTHS6+JBUtFUsrmi61oIHlESNrD1OjdB1QQw+kdvJ6VbsntbJNNYKw+YqdqWNpZkiGQ8y1z9OdHsr1+4= fafb00f5732ab283681e124bf8747ed1 From 4da4146062081be4c22b04aac71decd3d152a20f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 12 Sep 2012 22:14:14 -0700 Subject: [PATCH 16/60] add ChangeMessageVisibility to sqs --- .../src/main/java/org/jclouds/sqs/SQSApi.java | 42 +++++++++++++++++++ .../java/org/jclouds/sqs/SQSAsyncApi.java | 9 ++++ .../org/jclouds/sqs/SQSApiExpectTest.java | 30 +++++++++++++ .../java/org/jclouds/sqs/SQSApiLiveTest.java | 18 +++++++- 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index 0be40a4fe6..bc39a283d5 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -166,6 +166,48 @@ public interface SQSApi { */ void deleteMessage(URI queue, String receiptHandle); + /** + * The ChangeMessageVisibility action changes the visibility timeout of a + * specified message in a queue to a new value. The maximum allowed timeout + * value you can set the value to is 12 hours. This means you can't extend + * the timeout of a message in an existing queue to more than a total + * visibility timeout of 12 hours. (For more information visibility timeout, + * see Visibility Timeout in the Amazon SQS Developer Guide.) + * + * For example, let's say the timeout for the queue is 30 seconds, and you + * receive a message. Once you're 20 seconds into the timeout for that + * message (i.e., you have 10 seconds left), you extend it by 60 seconds by + * calling ChangeMessageVisibility with VisibilityTimeoutset to 60 seconds. + * You have then changed the remaining visibility timeout from 10 seconds to + * 60 seconds. + * + *

Important

+ * + * If you attempt to set the VisibilityTimeout to an amount more than the + * maximum time left, Amazon SQS returns an error. It will not automatically + * recalculate and increase the timeout to the maximum time remaining. + * + *

Important

+ * + * Unlike with a queue, when you change the visibility timeout for a specific + * message, that timeout value is applied immediately but is not saved in + * memory for that message. If you don't delete a message after it is + * received, the visibility timeout for the message the next time it is + * received reverts to the original timeout value, not the value you set with + * the ChangeMessageVisibility action. + * + * @param queue + * the queue the message is in + * @param receiptHandle + * The receipt handle associated with the message whose visibility + * timeout you want to change. This parameter is returned by the + * ReceiveMessage action. + * @param visibilityTimeout + * The new value for the message's visibility timeout (in seconds) + * from 0 to 43200 (maximum 12 hours) + */ + void changeMessageVisibility(URI queue, String receiptHandle, int visibilityTimeout); + /** * The SendMessage action delivers a message to the specified queue. The * maximum allowed message size is 64 KB. diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index 8099acd174..e3fb939286 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -126,6 +126,15 @@ public interface SQSAsyncApi { @FormParams(keys = ACTION, values = "DeleteMessage") ListenableFuture deleteMessage(@EndpointParam URI queue, @FormParam("ReceiptHandle") String receiptHandle); + /** + * @see SQSApi#changeMessageVisibility + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibility") + ListenableFuture changeMessageVisibility(@EndpointParam URI queue, + @FormParam("ReceiptHandle") String receiptHandle, @FormParam("VisibilityTimeout") int visibilityTimeout); + /** * @see SQSApi#sendMessage */ diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java index 2ccbd1f259..96f01a442c 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java @@ -164,6 +164,36 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { apiWhenExist.deleteMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "eXJYhj5rDr9cAe"); } + + + public HttpRequest changeMessageVisibility = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ChangeMessageVisibility") + .addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe") + .addFormParam("Signature", "gvmSHleGLkmszYU6aURCBImuec2k0O3pg3tAYhDvkNs%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("VisibilityTimeout", "10") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testChangeMessageVisibilityWhenResponseIs2xx() throws Exception { + + HttpResponse changeMessageVisibilityResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibility, changeMessageVisibilityResponse); + + apiWhenExist.changeMessageVisibility(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), + "eXJYhj5rDr9cAe", 10); + } public HttpRequest getQueueAttributes = HttpRequest.builder() .method("POST") diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index eb6a8db36d..806d7648b6 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -22,6 +22,7 @@ import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; import java.net.URI; import java.util.Map; @@ -111,11 +112,26 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5); } } + + String receiptHandle; @Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage") + protected void testChangeMessageVisibility() { + for (URI queue : queues) { + // start hiding it at 5 seconds + receiptHandle = api().receiveMessage(queue, attribute("None").visibilityTimeout(5)).getReceiptHandle(); + // hidden message, so we can't see it + assertNull(api().receiveMessage(queue)); + // this should unhide it + api().changeMessageVisibility(queue, receiptHandle, 0); + // so we can see it again + assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5); + } + } + + @Test(dependsOnMethods = "testChangeMessageVisibility") protected void testDeleteMessage() throws InterruptedException { for (URI queue : queues) { - String receiptHandle = api().receiveMessage(queue, attribute("None").visibilityTimeout(0)).getReceiptHandle(); api().deleteMessage(queue, receiptHandle); assertNoMessages(queue); } From 00da07aec4252413f98e1a5ed872d2c225b43625 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 13 Sep 2012 17:09:26 -0700 Subject: [PATCH 17/60] added all operations except batch --- .../src/main/java/org/jclouds/sqs/SQSApi.java | 63 +++- .../java/org/jclouds/sqs/SQSAsyncApi.java | 54 ++- .../java/org/jclouds/sqs/domain/Action.java | 80 +++++ .../org/jclouds/sqs/domain/Attribute.java | 88 +++++ .../jclouds/sqs/domain/QueueAttributes.java | 314 ++++++++++++++++++ .../sqs/functions/MapToQueueAttributes.java | 57 ++++ .../sqs/xml/RegexMessageIdAndMD5Handler.java | 2 +- .../org/jclouds/sqs/xml/ValueHandler.java | 56 ++++ .../org/jclouds/sqs/SQSApiExpectTest.java | 86 ++++- .../java/org/jclouds/sqs/SQSApiLiveTest.java | 90 ++++- .../functions/MapToQueueAttributesTest.java | 64 ++++ .../sqs/internal/BaseSQSApiLiveTest.java | 23 ++ .../parse/GetQueueAttributesResponseTest.java | 14 +- labs/sqs/src/test/resources/attributes.xml | 38 ++- 14 files changed, 1006 insertions(+), 23 deletions(-) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/Action.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index bc39a283d5..57fb80a70e 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -25,8 +25,10 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.sqs.domain.Action; import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.domain.QueueAttributes; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; import org.jclouds.sqs.options.ReceiveMessageOptions; @@ -208,6 +210,57 @@ public interface SQSApi { */ void changeMessageVisibility(URI queue, String receiptHandle, int visibilityTimeout); + /** + * The AddPermission action adds a permission to a queue for a specific + * principal. This allows for sharing access to the queue. + * + * When you create a queue, you have full control access rights for the + * queue. Only you (as owner of the queue) can grant or deny permissions to + * the queue. For more information about these permissions, see Shared Queues + * in the Amazon SQS Developer Guide. + * + * Note + * + * AddPermission writes an SQS-generated policy. If you want to write your + * own policy, use SetQueueAttributes to upload your policy. + * + * @param queue + * queue to change permissions on + * @param label + * + * The unique identification of the permission you're setting. + * example: AliceSendMessage + * + * Constraints: Maximum 80 characters; alphanumeric characters, + * hyphens (-), and underscores (_) are allowed. + * @param permission + * The action you want to allow for the specified principal. + * @param accountId + * The AWS account number of the principal who will be given + * permission. The principal must have an AWS account, but does not + * need to be signed up for Amazon SQS. For information about + * locating the AWS account identification, see Your AWS + * Identifiers in the Amazon SQS Developer Guide. + * + * Constraints: Valid 12-digit AWS account number, without hyphens + * + */ + void addPermissionToAccount(URI queue, String label, Action permission, String accountId); + + /** + * The RemovePermission action revokes any permissions in the queue policy + * that matches the Label parameter. Only the owner of the queue can remove + * permissions. + * + * @param queue + * queue to change permissions on + * + * @param label + * The identification of the permission you want to remove. This is + * the label you added in AddPermission. example: AliceSendMessage + */ + void removePermission(URI queue, String label); + /** * The SendMessage action delivers a message to the specified queue. The * maximum allowed message size is 64 KB. @@ -295,7 +348,7 @@ public interface SQSApi { * @param queue * queue to get the attributes of */ - Map getQueueAttributes(URI queue); + QueueAttributes getQueueAttributes(URI queue); /** * The SetQueueAttributes action sets one attribute of a queue per request. @@ -362,6 +415,14 @@ public interface SQSApi { */ Map getQueueAttributes(URI queue, Iterable attributeNames); + /** + * returns an attribute of a queue. + * + * @param queue + * queue to get the attributes of + */ + String getQueueAttribute(URI queue, String attributeName); + /** * same as {@link #receiveMessages(URI, int)} except you can provide options * like VisibilityTimeout parameter in your request, which will be applied to diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index e3fb939286..238dee8e3a 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -35,14 +35,20 @@ import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams; +import org.jclouds.sqs.domain.Action; import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.domain.QueueAttributes; +import org.jclouds.sqs.functions.MapToQueueAttributes; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; import org.jclouds.sqs.options.ReceiveMessageOptions; @@ -53,6 +59,7 @@ import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; import org.jclouds.sqs.xml.RegexQueueHandler; +import org.jclouds.sqs.xml.ValueHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -142,7 +149,8 @@ public interface SQSAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "SendMessage") @ResponseParser(RegexMessageIdAndMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message); + ListenableFuture sendMessage(@EndpointParam URI queue, + @FormParam("MessageBody") String message); /** * @see SQSApi#sendMessage @@ -151,8 +159,8 @@ public interface SQSAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "SendMessage") @ResponseParser(RegexMessageIdAndMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message, - SendMessageOptions options); + ListenableFuture sendMessage(@EndpointParam URI queue, + @FormParam("MessageBody") String message, SendMessageOptions options); /** * @see SQSApi#receiveMessage @@ -170,7 +178,7 @@ public interface SQSAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ReceiveMessage") @XMLResponseParser(MessageHandler.class) - ListenableFuture receiveMessage(@EndpointParam URI queue, ReceiveMessageOptions options); + ListenableFuture receiveMessage(@EndpointParam URI queue, ReceiveMessageOptions options); /** * @see SQSApi#getQueueAttributes(URI) @@ -178,8 +186,10 @@ public interface SQSAsyncApi { @POST @Path("/") @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" }) + @Transform(MapToQueueAttributes.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) @XMLResponseParser(AttributesHandler.class) - ListenableFuture> getQueueAttributes(@EndpointParam URI queue); + ListenableFuture getQueueAttributes(@EndpointParam URI queue); /** * @see SQSApi#getQueueAttributes(URI, Iterable) @@ -191,6 +201,16 @@ public interface SQSAsyncApi { ListenableFuture> getQueueAttributes(@EndpointParam URI queue, @BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable attributeNames); + /** + * @see SQSApi#getQueueAttribute + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "GetQueueAttributes") + @XMLResponseParser(ValueHandler.class) + ListenableFuture getQueueAttribute(@EndpointParam URI queue, + @FormParam("AttributeName.1") String attributeName); + /** * @see SQSApi#setQueueAttribute */ @@ -207,7 +227,8 @@ public interface SQSAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ReceiveMessage") @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receiveMessages(@EndpointParam URI queue, @FormParam("MaxNumberOfMessages") int max); + ListenableFuture> receiveMessages(@EndpointParam URI queue, + @FormParam("MaxNumberOfMessages") int max); /** * @see SQSApi#receiveMessages @@ -216,7 +237,24 @@ public interface SQSAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ReceiveMessage") @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receiveMessages(@EndpointParam URI queue, @FormParam("MaxNumberOfMessages") int max, - ReceiveMessageOptions options); + ListenableFuture> receiveMessages(@EndpointParam URI queue, + @FormParam("MaxNumberOfMessages") int max, ReceiveMessageOptions options); + + /** + * @see SQSApi#addPermissionToAccount + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "AddPermission") + ListenableFuture addPermissionToAccount(@EndpointParam URI queue, @FormParam("Label") String label, + @FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId); + + /** + * @see SQSApi#removePermission + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "RemovePermission") + ListenableFuture removePermission(@EndpointParam URI queue, @FormParam("Label") String label); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/Action.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/Action.java new file mode 100644 index 0000000000..7a1f886e63 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/Action.java @@ -0,0 +1,80 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +import com.google.common.base.CaseFormat; + +/** + * + * The action you want to allow for the specified principal. + * + * @see
+ * @author Adrian Cole + */ +public enum Action { + /** + * This permission type grants the following actions to a principal on a + * shared queue: receive messages, send messages, delete messages, change a + * message's visibility, get a queue's attributes. + */ + ALL, + /** + * This grants permission to receive messages in the queue. + */ + RECEIVE_MESSAGE, + /** + * This grants permission to send messages to the queue. SendMessageBatch + * inherits permissions associated with SendMessage. + */ + SEND_MESSAGE, + /** + * This grants permission to delete messages from the queue. + * DeleteMessageBatch inherits permissions associated with DeleteMessage. + */ + DELETE_MESSAGE, + /** + * This grants permission to extend or terminate the read lock timeout of a + * specified message. ChangeMessageVisibilityBatch inherits permissions + * associated with ChangeMessageVisibility. For more information about + * visibility timeout, see Visibility Timeout. For more information about + * this permission type, see the ChangeMessageVisibility operation. + */ + CHANGE_MESSAGE_VISIBILITY, + /** + * This grants permission to receive all of the queue attributes except the + * policy, which can only be accessed by the queue's owner. For more + * information, see the GetQueueAttributes operation. + */ + GET_QUEUE_ATTRIBUTES, + /** + * This grants permission to get the url of a queue by name. + */ + GET_QUEUE_URL; + + public String value() { + return this == ALL ? "*" : CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java new file mode 100644 index 0000000000..048c6922d1 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java @@ -0,0 +1,88 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +/** + * + * The action you want to allow for the specified principal. + * + * @see + * @author Adrian Cole + */ +public interface Attribute { + + /** + * approximate number of visible messages in a queue. + */ + public static final String APPROXIMATE_NUMBER_OF_MESSAGES = "ApproximateNumberOfMessages"; + /** + * approximate number of messages that are not timed-out and not deleted. + */ + public static final String APPROXIMATE_NUMBER_OF_MESSAGES_NOT_VISIBLE = "ApproximateNumberOfMessagesNotVisible"; + + /** + * approximate number of messages that are not visible because you have set a + * positive delay value on the queue + */ + public static final String APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED = "ApproximateNumberOfMessagesDelayed"; + + /** + * visibility timeout for the queue. + */ + public static final String VISIBILITY_TIMEOUT = "VisibilityTimeout"; + + /** + * time when the queue was created (epoch time in seconds). + */ + public static final String CREATED_TIMESTAMP = "CreatedTimestamp"; + + /** + * time when the queue was last changed (epoch time in seconds). + */ + public static final String LAST_MODIFIED_TIMESTAMP = "LastModifiedTimestamp"; + + /** + * queue's policy. + */ + public static final String POLICY = "Policy"; + + /** + * limit of how many bytes a message can contain before Amazon SQS rejects + * it. + */ + public static final String MAXIMUM_MESSAGE_SIZE = "MaximumMessageSize"; + + /** + * number of seconds Amazon SQS retains a message. + */ + public static final String MESSAGE_RETENTION_PERIOD = "MessageRetentionPeriod"; + + /** + * queue's Amazon resource name (ARN). + */ + public static final String QUEUE_ARN = "QueueArn"; + + /** + * The time in seconds that the delivery of all messages in the queue will be + * delayed. + */ + public static final String DELAY_SECONDS = "DelaySeconds"; +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java new file mode 100644 index 0000000000..d2e1e2c4bc --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java @@ -0,0 +1,314 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Date; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +/** + * + * @author Adrian Cole + * + * @see + */ +public class QueueAttributes { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromQueueAttributes(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String queueArn; + protected long approximateNumberOfMessages; + protected long approximateNumberOfMessagesNotVisible; + protected long approximateNumberOfMessagesDelayed; + protected int visibilityTimeout; + protected Date createdTimestamp; + protected Date lastModifiedTimestamp; + protected Optional rawPolicy = Optional.absent(); + protected int maximumMessageSize; + protected int messageRetentionPeriod; + protected int delaySeconds; + + /** + * @see QueueAttributes#getQueueArn() + */ + public T queueArn(String queueArn) { + this.queueArn = queueArn; + return self(); + } + + /** + * @see QueueAttributes#getApproximateNumberOfMessages() + */ + public T approximateNumberOfMessages(long approximateNumberOfMessages) { + this.approximateNumberOfMessages = approximateNumberOfMessages; + return self(); + } + + /** + * @see QueueAttributes#getApproximateNumberOfMessagesNotVisible() + */ + public T approximateNumberOfMessagesNotVisible(long approximateNumberOfMessagesNotVisible) { + this.approximateNumberOfMessagesNotVisible = approximateNumberOfMessagesNotVisible; + return self(); + } + + /** + * @see QueueAttributes#getApproximateNumberOfMessagesDelayed() + */ + public T approximateNumberOfMessagesDelayed(long approximateNumberOfMessagesDelayed) { + this.approximateNumberOfMessagesDelayed = approximateNumberOfMessagesDelayed; + return self(); + } + + /** + * @see QueueAttributes#getVisibilityTimeout() + */ + public T visibilityTimeout(int visibilityTimeout) { + this.visibilityTimeout = visibilityTimeout; + return self(); + } + + /** + * @see QueueAttributes#getCreatedTimestamp() + */ + public T createdTimestamp(Date createdTimestamp) { + this.createdTimestamp = createdTimestamp; + return self(); + } + + /** + * @see QueueAttributes#getLastModifiedTimestamp() + */ + public T lastModifiedTimestamp(Date lastModifiedTimestamp) { + this.lastModifiedTimestamp = lastModifiedTimestamp; + return self(); + } + + /** + * @see QueueAttributes#getRawPolicy() + */ + public T rawPolicy(String rawPolicy) { + this.rawPolicy = Optional.fromNullable(rawPolicy); + return self(); + } + + /** + * @see QueueAttributes#getMaximumMessageSize() + */ + public T maximumMessageSize(int maximumMessageSize) { + this.maximumMessageSize = maximumMessageSize; + return self(); + } + + /** + * @see QueueAttributes#getMessageRetentionPeriod() + */ + public T messageRetentionPeriod(int messageRetentionPeriod) { + this.messageRetentionPeriod = messageRetentionPeriod; + return self(); + } + + /** + * @see QueueAttributes#getDelaySeconds() + */ + public T delaySeconds(int delaySeconds) { + this.delaySeconds = delaySeconds; + return self(); + } + + public QueueAttributes build() { + return new QueueAttributes(queueArn, approximateNumberOfMessages, approximateNumberOfMessagesNotVisible, + approximateNumberOfMessagesDelayed, visibilityTimeout, createdTimestamp, lastModifiedTimestamp, + rawPolicy, maximumMessageSize, messageRetentionPeriod, delaySeconds); + } + + public T fromQueueAttributes(QueueAttributes in) { + return queueArn(in.queueArn).approximateNumberOfMessages(in.approximateNumberOfMessages) + .approximateNumberOfMessagesNotVisible(in.approximateNumberOfMessagesNotVisible) + .approximateNumberOfMessagesDelayed(in.approximateNumberOfMessagesDelayed) + .visibilityTimeout(in.visibilityTimeout).createdTimestamp(in.createdTimestamp) + .lastModifiedTimestamp(in.lastModifiedTimestamp).rawPolicy(in.rawPolicy.orNull()) + .maximumMessageSize(in.maximumMessageSize).messageRetentionPeriod(in.messageRetentionPeriod) + .delaySeconds(in.delaySeconds); + + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + protected final long approximateNumberOfMessages; + protected final long approximateNumberOfMessagesNotVisible; + protected final int visibilityTimeout; + protected final Date createdTimestamp; + protected final Date lastModifiedTimestamp; + protected final long approximateNumberOfMessagesDelayed; + protected final Optional rawPolicy; + protected final int maximumMessageSize; + protected final int messageRetentionPeriod; + protected final String queueArn; + protected int delaySeconds; + + protected QueueAttributes(String queueArn, long approximateNumberOfMessages, + long approximateNumberOfMessagesNotVisible, long approximateNumberOfMessagesDelayed, int visibilityTimeout, + Date createdTimestamp, Date lastModifiedTimestamp, Optional rawPolicy, int maximumMessageSize, + int messageRetentionPeriod, int delaySeconds) { + this.queueArn = checkNotNull(queueArn, "queueArn"); + this.approximateNumberOfMessages = approximateNumberOfMessages; + this.approximateNumberOfMessagesNotVisible = approximateNumberOfMessagesNotVisible; + this.approximateNumberOfMessagesDelayed = approximateNumberOfMessagesDelayed; + this.visibilityTimeout = visibilityTimeout; + this.createdTimestamp = checkNotNull(createdTimestamp, "createdTimestamp of %s", queueArn); + this.lastModifiedTimestamp = checkNotNull(lastModifiedTimestamp, "lastModifiedTimestamp of %s", queueArn); + this.rawPolicy = checkNotNull(rawPolicy, "rawPolicy of %s", queueArn); + this.maximumMessageSize = maximumMessageSize; + this.messageRetentionPeriod = messageRetentionPeriod; + this.delaySeconds = delaySeconds; + } + + /** + * @see Attribute#QUEUE_ARN + */ + public String getQueueArn() { + return queueArn; + } + + /** + * @see Attribute#APPROXIMATE_NUMBER_OF_MESSAGES + */ + public long getApproximateNumberOfMessages() { + return approximateNumberOfMessages; + } + + /** + * @see Attribute#APPROXIMATE_NUMBER_OF_MESSAGES_NOT_VISIBLE + */ + public long getApproximateNumberOfMessagesNotVisible() { + return approximateNumberOfMessagesNotVisible; + } + + /** + * @see Attribute#APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED + */ + public long getApproximateNumberOfMessagesDelayed() { + return approximateNumberOfMessagesDelayed; + } + + /** + * @see Attribute#VISIBILITY_TIMEOUT + */ + public int getVisibilityTimeout() { + return visibilityTimeout; + } + + /** + * @see Attribute#CREATED_TIMESTAMP + */ + public Date getCreatedTimestamp() { + return createdTimestamp; + } + + /** + * @see Attribute#LAST_MODIFIED_TIMESTAMP + */ + public Date getLastModifiedTimestamp() { + return lastModifiedTimestamp; + } + + /** + * Note this is in raw Json + * + * @see Attribute#POLICY + */ + public Optional getRawPolicy() { + return rawPolicy; + } + + /** + * @see Attribute#MAXIMUM_MESSAGE_SIZE + */ + public int getMaximumMessageSize() { + return maximumMessageSize; + } + + /** + * @see Attribute#MESSAGE_RETENTION_PERIOD + */ + public int getMessageRetentionPeriod() { + return messageRetentionPeriod; + } + + /** + * @see Attribute#DELAY_SECONDS + */ + public int getDelaySeconds() { + return delaySeconds; + } + + @Override + public int hashCode() { + return Objects.hashCode(queueArn); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + QueueAttributes other = (QueueAttributes) obj; + return Objects.equal(this.queueArn, other.queueArn); + + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("queueArn", queueArn) + .add("approximateNumberOfMessages", approximateNumberOfMessages) + .add("approximateNumberOfMessagesNotVisible", approximateNumberOfMessagesNotVisible) + .add("approximateNumberOfMessagesDelayed", approximateNumberOfMessagesDelayed) + .add("visibilityTimeout", visibilityTimeout).add("createdTimestamp", createdTimestamp) + .add("lastModifiedTimestamp", lastModifiedTimestamp).add("rawPolicy", rawPolicy.orNull()) + .add("maximumMessageSize", maximumMessageSize).add("messageRetentionPeriod", messageRetentionPeriod) + .add("delaySeconds", delaySeconds).toString(); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java b/labs/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java new file mode 100644 index 0000000000..1728bebd34 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java @@ -0,0 +1,57 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.functions; + +import java.util.Date; +import java.util.Map; + +import org.jclouds.sqs.domain.Attribute; +import org.jclouds.sqs.domain.QueueAttributes; +import org.jclouds.sqs.domain.QueueAttributes.Builder; + +import com.google.common.base.Function; + +/** + * Converts a Map to a typed QueueAttributes object + * + * @author Adrian Cole + */ +public class MapToQueueAttributes implements Function, QueueAttributes> { + + @Override + public QueueAttributes apply(Map input) { + if (input == null) + return null; + Builder builder = QueueAttributes.builder(); + builder.queueArn(input.get(Attribute.QUEUE_ARN)); + builder.approximateNumberOfMessages(Long.parseLong(input.get(Attribute.APPROXIMATE_NUMBER_OF_MESSAGES))); + builder.approximateNumberOfMessagesNotVisible(Long.parseLong(input + .get(Attribute.APPROXIMATE_NUMBER_OF_MESSAGES_NOT_VISIBLE))); + builder.approximateNumberOfMessagesDelayed(Long.parseLong(input + .get(Attribute.APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED))); + builder.visibilityTimeout(Integer.parseInt(input.get(Attribute.VISIBILITY_TIMEOUT))); + builder.createdTimestamp(new Date(Long.parseLong(input.get(Attribute.CREATED_TIMESTAMP)))); + builder.lastModifiedTimestamp(new Date(Long.parseLong(input.get(Attribute.LAST_MODIFIED_TIMESTAMP)))); + builder.rawPolicy(input.get(Attribute.POLICY)); + builder.maximumMessageSize(Integer.parseInt(input.get(Attribute.MAXIMUM_MESSAGE_SIZE))); + builder.messageRetentionPeriod(Integer.parseInt(input.get(Attribute.MESSAGE_RETENTION_PERIOD))); + builder.delaySeconds(Integer.parseInt(input.get(Attribute.DELAY_SECONDS))); + return builder.build(); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java index 9baf8a5531..c7cf3c0ca2 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java @@ -40,7 +40,7 @@ import com.google.inject.Singleton; */ @Singleton public class RegexMessageIdAndMD5Handler implements Function { - Pattern pattern = Pattern.compile("([\\S&&[^<]]+)\\s*([\\S&&[^<]]+)", Pattern.DOTALL); + private static final Pattern pattern = Pattern.compile("([\\S&&[^<]]+)\\s*([\\S&&[^<]]+)", Pattern.DOTALL); private final ReturnStringIf2xx returnStringIf200; @Inject diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java new file mode 100644 index 0000000000..b30c622f27 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; + +import org.jclouds.http.functions.ParseSax; + +/** + * @see + * + * @author Adrian Cole + */ +public class ValueHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private String value; + + @Override + public String getResult() { + return value; + } + + // this could be done with regex, if we had an unescaper + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals("Value")) { + value = currentOrNull(currentText); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java index 96f01a442c..ec4303ff7b 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java @@ -24,6 +24,8 @@ import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.sqs.domain.Action; +import org.jclouds.sqs.functions.MapToQueueAttributesTest; import org.jclouds.sqs.internal.BaseSQSApiExpectTest; import org.jclouds.sqs.parse.CreateQueueResponseTest; import org.jclouds.sqs.parse.GetQueueAttributesResponseTest; @@ -195,6 +197,33 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { "eXJYhj5rDr9cAe", 10); } + public HttpRequest getQueueAttribute = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "GetQueueAttributes") + .addFormParam("AttributeName.1", "VisibilityTimeout") + .addFormParam("Signature", "AfydayBBaIk4UGikHHY1CFNmOOAcTnogpFWydZyNass%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testGetQueueAttributeWhenResponseIs2xx() throws Exception { + + HttpResponse getQueueAttributeResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "VisibilityTimeout30", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(getQueueAttribute, getQueueAttributeResponse); + + assertEquals(apiWhenExist.getQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "VisibilityTimeout"), "30"); + } + public HttpRequest getQueueAttributes = HttpRequest.builder() .method("POST") .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") @@ -215,7 +244,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(getQueueAttributes, getQueueAttributesResponse); - assertEquals(apiWhenExist.getQueueAttributes(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")).toString(), new GetQueueAttributesResponseTest().expected().toString()); + assertEquals(apiWhenExist.getQueueAttributes(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")).toString(), new MapToQueueAttributesTest().expected().toString()); } public HttpRequest getQueueAttributesSubset = HttpRequest.builder() @@ -274,5 +303,60 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { apiWhenExist.setQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "MaximumMessageSize", "1"); } + + public HttpRequest addPermission = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "AddPermission") + .addFormParam("ActionName.1", "ReceiveMessage") + .addFormParam("AWSAccountId.1", "125074342641") + .addFormParam("Label", "testLabel") + .addFormParam("Signature", "J9sV4q1rJ7dWYJDQp9JxsfEKNXQhpQBYIwBYi1IeXV0%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + public void testAddPermissionWhenResponseIs2xx() throws Exception { + + HttpResponse addPermissionResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(addPermission, addPermissionResponse); + + apiWhenExist.addPermissionToAccount(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "testLabel", Action.RECEIVE_MESSAGE, "125074342641"); + } + + public HttpRequest removePermission = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "RemovePermission") + .addFormParam("Label", "testLabel") + .addFormParam("Signature", "VOA0L1uRVKQDQL1Klt0cYUajGoxN4Ur%2B7ISQ2I4RpRs%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testRemovePermissionWhenResponseIs2xx() throws Exception { + + HttpResponse removePermissionResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(removePermission, removePermissionResponse); + + apiWhenExist.removePermission(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "testLabel"); + } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index 806d7648b6..ee61013517 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -18,8 +18,11 @@ */ package org.jclouds.sqs; +import static org.jclouds.concurrent.MoreExecutors.sameThreadExecutor; +import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint; import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; +import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; @@ -28,16 +31,32 @@ import java.net.URI; import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.concurrent.TimeUnit; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.ContextBuilder; +import org.jclouds.concurrent.Timeout; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.sqs.domain.Action; +import org.jclouds.sqs.domain.QueueAttributes; import org.jclouds.sqs.internal.BaseSQSApiLiveTest; +import org.jclouds.sqs.xml.ValueHandler; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import com.google.common.base.Charsets; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.inject.Module; /** * Tests behavior of {@code SQSApi} @@ -82,24 +101,69 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { return queueName; } - String message = "hardyharhar"; - HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); - @Test(dependsOnMethods = "testCanRecreateQueueGracefully") protected void testGetQueueAttributes() { for (URI queue : queues) { - Map attributes = api().getQueueAttributes(queue); + Map attributes = api().getQueueAttributes(queue, ImmutableSet.of("All")); assertEquals(api().getQueueAttributes(queue, attributes.keySet()), attributes); } } - @Test(dependsOnMethods = "testCanRecreateQueueGracefully") + + String message = "hardyharhar"; + HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); + + @Timeout(duration = 5, timeUnit = TimeUnit.SECONDS) + static interface AnonymousAttributesApi { + String getQueueArn(); + } + + static interface AnonymousAttributesAsyncApi { + @POST + @Path("/") + @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "QueueArn" }) + @XMLResponseParser(ValueHandler.class) + ListenableFuture getQueueArn(); + } + + @Test(dependsOnMethods = "testGetQueueAttributes") + protected void testAddAnonymousPermission() throws InterruptedException { + for (URI queue : queues) { + QueueAttributes attributes = api().getQueueAttributes(queue); + assertNoPermissions(queue); + + String accountToAuthorize = getAccountToAuthorize(queue); + api().addPermissionToAccount(queue, "fubar", Action.GET_QUEUE_ATTRIBUTES, accountToAuthorize); + + String policyForAuthorizationByAccount = assertPolicyPresent(queue); + + String policyForAnonymous = policyForAuthorizationByAccount.replace("\"" + accountToAuthorize + "\"", "\"*\""); + api().setQueueAttribute(queue, "Policy", policyForAnonymous); + + assertEquals(getAnonymousAttributesApi(queue).getQueueArn(), attributes.getQueueArn()); + } + } + + protected String getAccountToAuthorize(URI queue) { + return Iterables.get(Splitter.on('/').split(queue.getPath()), 1); + } + + @Test(dependsOnMethods = "testAddAnonymousPermission") + protected void testRemovePermission() throws InterruptedException { + for (URI queue : queues) { + api().removePermission(queue, "fubar"); + assertNoPermissions(queue); + } + } + + @Test(dependsOnMethods = "testGetQueueAttributes") protected void testSetQueueAttribute() { for (URI queue : queues) { api().setQueueAttribute(queue, "MaximumMessageSize", "1024"); - assertEquals(api().getQueueAttributes(queue).get("MaximumMessageSize"), "1024"); + assertEquals(api().getQueueAttributes(queue).getMaximumMessageSize(), 1024); } } - @Test(dependsOnMethods = "testCanRecreateQueueGracefully") + + @Test(dependsOnMethods = "testGetQueueAttributes") protected void testSendMessage() { for (URI queue : queues) { assertEquals(api().sendMessage(queue, message).getMD5(), md5); @@ -112,7 +176,7 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5); } } - + String receiptHandle; @Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage") @@ -149,4 +213,14 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { protected SQSApi api() { return context.getApi(); } + + private AnonymousAttributesApi getAnonymousAttributesApi(URI queue) { + return ContextBuilder + .newBuilder( + forClientMappedToAsyncClientOnEndpoint(AnonymousAttributesApi.class, + AnonymousAttributesAsyncApi.class, queue.toASCIIString())) + .modules(ImmutableSet. of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) + .buildInjector().getInstance(AnonymousAttributesApi.class); + } + } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java new file mode 100644 index 0000000000..203a5b78f1 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java @@ -0,0 +1,64 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.functions; + +import static org.testng.Assert.assertEquals; + +import java.util.Date; + +import org.jclouds.sqs.domain.QueueAttributes; +import org.jclouds.sqs.parse.GetQueueAttributesResponseTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "MapToQueueAttributesTest") +public class MapToQueueAttributesTest { + + public void test() { + + + QueueAttributes expected = expected(); + + MapToQueueAttributes fn = new MapToQueueAttributes(); + + QueueAttributes result = fn.apply(new GetQueueAttributesResponseTest().expected()); + + assertEquals(result.toString(), expected.toString()); + + } + + public QueueAttributes expected() { + return QueueAttributes.builder() + .queueArn("arn:aws:sqs:us-east-1:993194456877:adrian-sqs1") + .approximateNumberOfMessages(0) + .approximateNumberOfMessagesNotVisible(0) + .approximateNumberOfMessagesDelayed(0) + .createdTimestamp(new Date(1347566436l)) + .lastModifiedTimestamp(new Date(1347566436)) + .visibilityTimeout(30) + .maximumMessageSize(65536) + .messageRetentionPeriod(345600) + .delaySeconds(0) + .build(); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index ace17bdd8c..c95d3def31 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import org.jclouds.apis.BaseContextLiveTest; import org.jclouds.rest.RestContext; @@ -51,6 +52,28 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest policy = new AtomicReference(); + assertEventually(new Runnable() { + public void run() { + String policyForAuthorizationByAccount = api().getQueueAttribute(queue, "Policy"); + + assertNotNull(policyForAuthorizationByAccount); + policy.set(policyForAuthorizationByAccount); + } + }); + return policy.get(); + } + + protected void assertNoPermissions(final URI queue) throws InterruptedException { + assertEventually(new Runnable() { + public void run() { + String policy = api().getQueueAttribute(queue, "Policy"); + assertTrue(policy == null || policy.indexOf("\"Statement\":[]") != -1, policy); + } + }); + } + protected void assertNoMessages(final URI queue) throws InterruptedException { assertEventually(new Runnable() { public void run() { diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java index 553f0bfbbd..143d293e6d 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java @@ -51,8 +51,16 @@ public class GetQueueAttributesResponseTest extends BaseHandlerTest { public Map expected() { return ImmutableMap.builder() - .put("VisibilityTimeout", "30") - .put("DelaySeconds", "0") - .build(); + .put("QueueArn", "arn:aws:sqs:us-east-1:993194456877:adrian-sqs1") + .put("ApproximateNumberOfMessages", "0") + .put("ApproximateNumberOfMessagesNotVisible", "0") + .put("ApproximateNumberOfMessagesDelayed", "0") + .put("CreatedTimestamp", "1347566436") + .put("LastModifiedTimestamp", "1347566436") + .put("VisibilityTimeout","30") + .put("MaximumMessageSize", "65536") + .put("MessageRetentionPeriod", "345600") + .put("DelaySeconds", "0") + .build(); } } diff --git a/labs/sqs/src/test/resources/attributes.xml b/labs/sqs/src/test/resources/attributes.xml index 2ae6de4e68..726c246b7f 100644 --- a/labs/sqs/src/test/resources/attributes.xml +++ b/labs/sqs/src/test/resources/attributes.xml @@ -1,12 +1,48 @@ - + + + + QueueArn + arn:aws:sqs:us-east-1:993194456877:adrian-sqs1 + + + ApproximateNumberOfMessages + 0 + + + ApproximateNumberOfMessagesNotVisible + 0 + + + ApproximateNumberOfMessagesDelayed + 0 + + + CreatedTimestamp + 1347566436 + + + LastModifiedTimestamp + 1347566436 + VisibilityTimeout 30 + + MaximumMessageSize + 65536 + + + MessageRetentionPeriod + 345600 + DelaySeconds 0 + + 35566a87-caa1-5841-b60b-224bf7068bf5 + \ No newline at end of file From 887d4d1de8bd7287d5d3a00786e5b873672d374a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 14 Sep 2012 09:11:04 -0700 Subject: [PATCH 18/60] modularized sqs --- .../main/java/org/jclouds/sqs/MessageApi.java | 209 +++++++++ .../java/org/jclouds/sqs/MessageAsyncApi.java | 130 ++++++ .../java/org/jclouds/sqs/PermissionApi.java | 87 ++++ .../org/jclouds/sqs/PermissionAsyncApi.java | 65 +++ .../main/java/org/jclouds/sqs/QueueApi.java | 212 +++++++++ .../java/org/jclouds/sqs/QueueAsyncApi.java | 150 +++++++ .../src/main/java/org/jclouds/sqs/SQSApi.java | 419 ++---------------- .../java/org/jclouds/sqs/SQSAsyncApi.java | 237 ++-------- .../sqs/config/SQSRestClientModule.java | 18 +- .../org/jclouds/sqs/SQSApiExpectTest.java | 44 +- .../java/org/jclouds/sqs/SQSApiLiveTest.java | 51 ++- .../sqs/internal/BaseSQSApiLiveTest.java | 8 +- 12 files changed, 977 insertions(+), 653 deletions(-) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java new file mode 100644 index 0000000000..63fdc8ce4a --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java @@ -0,0 +1,209 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import java.net.URI; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.options.ReceiveMessageOptions; +import org.jclouds.sqs.options.SendMessageOptions; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @see SQSAsyncApi + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface MessageApi { + + /** + * The DeleteMessage action deletes the specified message from the specified + * queue. You specify the message by using the message's receipt handle and + * not the message ID you received when you sent the message. Even if the + * message is locked by another reader due to the visibility timeout setting, + * it is still deleted from the queue. If you leave a message in the queue + * for more than 4 days, SQS automatically deletes it. + * + *

Note

+ * + * The receipt handle is associated with a specific instance of receiving the + * message. If you receive a message more than once, the receipt handle you + * get each time you receive the message is different. When you request + * DeleteMessage, if you don't provide the most recently received receipt + * handle for the message, the request will still succeed, but the message + * might not be deleted. + * + *

Important

+ * + * It is possible you will receive a message even after you have deleted it. + * This might happen on rare occasions if one of the servers storing a copy + * of the message is unavailable when you request to delete the message. The + * copy remains on the server and might be returned to you again on a + * subsequent receive request. You should create your system to be idempotent + * so that receiving a particular message more than once is not a problem. + * + * @param queue + * the queue the message is in + * @param receiptHandle + * The receipt handle associated with the message you want to + * delete. + */ + void delete(String receiptHandle); + + /** + * The ChangeMessageVisibility action changes the visibility timeout of a + * specified message in a queue to a new value. The maximum allowed timeout + * value you can set the value to is 12 hours. This means you can't extend + * the timeout of a message in an existing queue to more than a total + * visibility timeout of 12 hours. (For more information visibility timeout, + * see Visibility Timeout in the Amazon SQS Developer Guide.) + * + * For example, let's say the timeout for the queue is 30 seconds, and you + * receive a message. Once you're 20 seconds into the timeout for that + * message (i.e., you have 10 seconds left), you extend it by 60 seconds by + * calling ChangeMessageVisibility with VisibilityTimeoutset to 60 seconds. + * You have then changed the remaining visibility timeout from 10 seconds to + * 60 seconds. + * + *

Important

+ * + * If you attempt to set the VisibilityTimeout to an amount more than the + * maximum time left, Amazon SQS returns an error. It will not automatically + * recalculate and increase the timeout to the maximum time remaining. + * + *

Important

+ * + * Unlike with a queue, when you change the visibility timeout for a specific + * message, that timeout value is applied immediately but is not saved in + * memory for that message. If you don't delete a message after it is + * received, the visibility timeout for the message the next time it is + * received reverts to the original timeout value, not the value you set with + * the ChangeMessageVisibility action. + * + * @param queue + * the queue the message is in + * @param receiptHandle + * The receipt handle associated with the message whose visibility + * timeout you want to change. This parameter is returned by the + * ReceiveMessage action. + * @param visibilityTimeout + * The new value for the message's visibility timeout (in seconds) + * from 0 to 43200 (maximum 12 hours) + */ + void changeVisibility(String receiptHandle, int visibilityTimeout); + + /** + * The SendMessage action delivers a message to the specified queue. The + * maximum allowed message size is 64 KB. + * + *

Important

+ * + * The following list shows the characters (in Unicode) allowed in your + * message, according to the W3C XML specification (for more information, go + * to http://www.w3.org/TR/REC-xml/#charsets). If you send any characters not + * included in the list, your request will be rejected. + * + * + * {@code #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]} + * + * @param queue + * queue you want to send to + * + * @param message + * Type: String maximum 64 KB in size. For a list of allowed + * characters, see the preceding important note. + * @return id of the message and md5 of the content sent + */ + MessageIdAndMD5 send(String message); + + /** + * same as {@link #sendMessage(URI, String)} except you can control options + * such as delay seconds. + * + * @param options + * options such as delay seconds + * @see #sendMessage(URI, String) + */ + MessageIdAndMD5 send(String message, SendMessageOptions options); + + /** + * The ReceiveMessage action retrieves one or more messages from the + * specified queue. The ReceiveMessage action does not delete the message + * after it is retrieved. To delete a message, you must use the DeleteMessage + * action. For more information about message deletion in the message life + * cycle, see Message Lifecycle. + * + *

Note

+ * + * Due to the distributed nature of the queue, a weighted random set of + * machines is sampled on a ReceiveMessage call. That means only the messages + * on the sampled machines are returned. If the number of messages in the + * queue is small (less than 1000), it is likely you will get fewer messages + * than you requested per ReceiveMessage call. If the number of messages in + * the queue is extremely small, you might not receive any messages in a + * particular ReceiveMessage response; in which case you should repeat the + * request. + * + * @param queue + * from where you are receiving messages + * @return message including the receipt handle you can use to delete it + */ + Message receive(); + + /** + * same as {@link #receive(URI)} except you can provide options like + * VisibilityTimeout parameter in your request, which will be applied to the + * messages that SQS returns in the response. If you do not include the + * parameter, the overall visibility timeout for the queue is used for the + * returned messages. + * + * @param options + * options such as VisibilityTimeout + * @see #receive(URI) + */ + Message receive(ReceiveMessageOptions options); + + /** + * same as {@link #receive(URI)} except you can receive multiple messages. + * + * @param max + * maximum messages to receive, current limit is 10 + * @see #receive(URI) + */ + Set receive(int max); + + /** + * same as {@link #receive(URI, int)} except you can provide options like + * VisibilityTimeout parameter in your request, which will be applied to the + * messages that SQS returns in the response. If you do not include the + * parameter, the overall visibility timeout for the queue is used for the + * returned messages. + * + * @param options + * options such as VisibilityTimeout + * @see #receive(URI, int) + */ + Set receive(int max, ReceiveMessageOptions options); +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java new file mode 100644 index 0000000000..c52701cfb4 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java @@ -0,0 +1,130 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import static org.jclouds.sqs.reference.SQSParameters.ACTION; +import static org.jclouds.sqs.reference.SQSParameters.VERSION; + +import java.util.Set; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.Constants; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.options.ReceiveMessageOptions; +import org.jclouds.sqs.options.SendMessageOptions; +import org.jclouds.sqs.xml.MessageHandler; +import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; +import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") +@VirtualHost +public interface MessageAsyncApi { + + /** + * @see SQSApi#delete + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteMessage") + ListenableFuture delete(@FormParam("ReceiptHandle") String receiptHandle); + + /** + * @see SQSApi#changeVisibility + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibility") + ListenableFuture changeVisibility(@FormParam("ReceiptHandle") String receiptHandle, + @FormParam("VisibilityTimeout") int visibilityTimeout); + + /** + * @see SQSApi#send + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessage") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + ListenableFuture send(@FormParam("MessageBody") String message); + + /** + * @see SQSApi#send + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessage") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + ListenableFuture send(@FormParam("MessageBody") String message, SendMessageOptions options); + + /** + * @see SQSApi#receive + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(MessageHandler.class) + ListenableFuture receive(); + + /** + * @see SQSApi#receive + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(MessageHandler.class) + ListenableFuture receive(ReceiveMessageOptions options); + + /** + * @see SQSApi#receive + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(ReceiveMessageResponseHandler.class) + ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max); + + /** + * @see SQSApi#receive + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(ReceiveMessageResponseHandler.class) + ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max, + ReceiveMessageOptions options); + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java new file mode 100644 index 0000000000..71a2b4852b --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java @@ -0,0 +1,87 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.sqs.domain.Action; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @see SQSAsyncApi + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface PermissionApi { + + /** + * The AddPermission action adds a permission to a queue for a specific + * principal. This allows for sharing access to the queue. + * + * When you create a queue, you have full control access rights for the + * queue. Only you (as owner of the queue) can grant or deny permissions to + * the queue. For more information about these permissions, see Shared Queues + * in the Amazon SQS Developer Guide. + * + * Note + * + * AddPermission writes an SQS-generated policy. If you want to write your + * own policy, use SetQueueAttributes to upload your policy. + * + * @param queue + * queue to change permissions on + * @param label + * + * The unique identification of the permission you're setting. + * example: AliceSendMessage + * + * Constraints: Maximum 80 characters; alphanumeric characters, + * hyphens (-), and underscores (_) are allowed. + * @param permission + * The action you want to allow for the specified principal. + * @param accountId + * The AWS account number of the principal who will be given + * permission. The principal must have an AWS account, but does not + * need to be signed up for Amazon SQS. For information about + * locating the AWS account identification, see Your AWS + * Identifiers in the Amazon SQS Developer Guide. + * + * Constraints: Valid 12-digit AWS account number, without hyphens + * + */ + void addPermissionToAccount(String label, Action permission, String accountId); + + /** + * The RemovePermission action revokes any permissions in the queue policy + * that matches the Label parameter. Only the owner of the queue can remove + * permissions. + * + * @param queue + * queue to change permissions on + * + * @param label + * The identification of the permission you want to remove. This is + * the label you added in AddPermission. example: AliceSendMessage + */ + void remove(String label); + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java new file mode 100644 index 0000000000..9eccd9b228 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import static org.jclouds.sqs.reference.SQSParameters.ACTION; +import static org.jclouds.sqs.reference.SQSParameters.VERSION; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.Constants; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.sqs.domain.Action; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") +@VirtualHost +public interface PermissionAsyncApi { + + /** + * @see SQSApi#addPermissionToAccount + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "AddPermission") + ListenableFuture addPermissionToAccount(@FormParam("Label") String label, + @FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId); + + /** + * @see SQSApi#remove + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "RemovePermission") + ListenableFuture remove(@FormParam("Label") String label); + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java new file mode 100644 index 0000000000..0492b819a0 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java @@ -0,0 +1,212 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import java.net.URI; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.sqs.domain.QueueAttributes; +import org.jclouds.sqs.options.CreateQueueOptions; +import org.jclouds.sqs.options.ListQueuesOptions; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @see SQSAsyncApi + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface QueueApi { + + /** + * The ListQueues action returns a list of your queues. The maximum number of + * queues that can be returned is 1000. If you specify a value for the + * optional QueueNamePrefix parameter, only queues with a name beginning with + * the specified value are returned + * + * @param region + * Queues are Region-specific. + * @param options + * specify prefix or other options + * + * @see + */ + Set list(); + + Set list(ListQueuesOptions options); + + /** + * The CreateQueue action creates a new queue. + * + * When you request CreateQueue, you provide a name for the queue. To + * successfully create a new queue, you must provide a name that is unique + * within the scope of your own queues. + * + *

Note

+ * + * If you delete a queue, you must wait at least 60 seconds before creating a + * queue with the same name. + * + * If you provide the name of an existing queue, along with the exact names + * and values of all the queue's attributes, CreateQueue returns the queue + * URL for the existing queue. If the queue name, attribute names, or + * attribute values do not match an existing queue, CreateQueue returns an + * error. + * + *

Tip

+ * + * Use GetQueueUrl to get a queue's URL. GetQueueUrl requires only the + * QueueName parameter. + * + * @param region + * Queues are Region-specific. + * @param queueName + * The name to use for the queue created. Constraints: Maximum 80 + * characters; alphanumeric characters, hyphens (-), and + * underscores (_) are allowed. + */ + // this will gracefully attempt to resolve name issues + @Timeout(duration = 61, timeUnit = TimeUnit.SECONDS) + URI create(String queueName); + + /** + * same as {@link #create(String, String)} except you can + * control options such as delay seconds. + * + * @param options + * options such as delay seconds + * @see #create(String, String) + */ + @Timeout(duration = 61, timeUnit = TimeUnit.SECONDS) + URI create(String queueName, CreateQueueOptions options); + + /** + * The DeleteQueue action deletes the queue specified by the queue URL, + * regardless of whether the queue is empty. If the specified queue does not + * exist, SQS returns a successful response. + * + *

Caution

+ * + * Use DeleteQueue with care; once you delete your queue, any messages in the + * queue are no longer available. + * + * When you delete a queue, the deletion process takes up to 60 seconds. + * Requests you send involving that queue during the 60 seconds might + * succeed. For example, a SendMessage request might succeed, but after the + * 60 seconds, the queue and that message you sent no longer exist. Also, + * when you delete a queue, you must wait at least 60 seconds before creating + * a queue with the same name. + * + * We reserve the right to delete queues that have had no activity for more + * than 30 days. For more information, see About SQS Queues in the Amazon SQS + * Developer Guide. + * + * @param queue + * queue you want to delete + */ + void delete(URI queue); + + /** + * returns all attributes of a queue. + * + * @param queue + * queue to get the attributes of + */ + QueueAttributes getAttributes(URI queue); + + /** + * The SetQueueAttributes action sets one attribute of a queue per request. + * When you change a queue's attributes, the change can take up to 60 seconds + * to propagate throughout the SQS system. + * + * @param queue + * queue to set the attribute on + * @param name + * + * The name of the attribute you want to set. + * + * VisibilityTimeout - The length of time (in seconds) that a + * message received from a queue will be invisible to other + * receiving components when they ask to receive messages. For more + * information about VisibilityTimeout, see Visibility Timeout in + * the Amazon SQS Developer Guide. + * + * Policy - The formal description of the permissions for a + * resource. For more information about Policy, see Basic Policy + * Structure in the Amazon SQS Developer Guide. + * + * MaximumMessageSize - The limit of how many bytes a message can + * contain before Amazon SQS rejects it. + * + * MessageRetentionPeriod - The number of seconds Amazon SQS + * retains a message. + * + * DelaySeconds - The time in seconds that the delivery of all + * messages in the queue will be delayed. + * @param value + * The value of the attribute you want to set. To delete a queue's + * access control policy, set the policy to "". + * + * Constraints: Constraints are specific for each value. + * + * VisibilityTimeout - An integer from 0 to 43200 (12 hours). The + * default for this attribute is 30 seconds. + * + * Policy - A valid form-url-encoded policy. For more information + * about policy structure, see Basic Policy Structure in the Amazon + * SQS Developer Guide. For more information about + * form-url-encoding, see + * http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1. + * + * MaximumMessageSize - An integer from 1024 bytes (1 KiB) up to + * 65536 bytes (64 KiB). The default for this attribute is 65536 + * (64 KiB). + * + * MessageRetentionPeriod - Integer representing seconds, from 60 + * (1 minute) to 1209600 (14 days). The default for this attribute + * is 345600 (4 days). + * + * DelaySeconds - An integer from 0 to 900 (15 minutes). The + * default for this attribute is 0. + */ + void setAttribute(URI queue, String name, String value); + + /** + * returns some attributes of a queue. + * + * @param queue + * queue to get the attributes of + */ + Map getAttributes(URI queue, Iterable attributeNames); + + /** + * returns an attribute of a queue. + * + * @param queue + * queue to get the attributes of + */ + String getAttribute(URI queue, String attributeName); + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java new file mode 100644 index 0000000000..4621b90dad --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java @@ -0,0 +1,150 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs; + +import static org.jclouds.sqs.reference.SQSParameters.ACTION; +import static org.jclouds.sqs.reference.SQSParameters.VERSION; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.Constants; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams; +import org.jclouds.sqs.domain.QueueAttributes; +import org.jclouds.sqs.functions.MapToQueueAttributes; +import org.jclouds.sqs.options.CreateQueueOptions; +import org.jclouds.sqs.options.ListQueuesOptions; +import org.jclouds.sqs.xml.AttributesHandler; +import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; +import org.jclouds.sqs.xml.RegexQueueHandler; +import org.jclouds.sqs.xml.ValueHandler; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") +@VirtualHost +public interface QueueAsyncApi { + + /** + * @see SQSApi#list + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ListQueues") + @ResponseParser(RegexListQueuesResponseHandler.class) + ListenableFuture> list(); + + /** + * @see SQSApi#list + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ListQueues") + @ResponseParser(RegexListQueuesResponseHandler.class) + ListenableFuture> list(ListQueuesOptions options); + + /** + * @see SQSApi#create + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "CreateQueue") + @ResponseParser(RegexQueueHandler.class) + ListenableFuture create(@FormParam("QueueName") String queueName); + + /** + * @see SQSApi#create + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "CreateQueue") + @ResponseParser(RegexQueueHandler.class) + ListenableFuture create(@FormParam("QueueName") String queueName, CreateQueueOptions options); + + /** + * @see SQSApi#delete + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteQueue") + ListenableFuture delete(@EndpointParam URI queue); + + /** + * @see SQSApi#getAttributes(URI) + */ + @POST + @Path("/") + @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" }) + @Transform(MapToQueueAttributes.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @XMLResponseParser(AttributesHandler.class) + ListenableFuture getAttributes(@EndpointParam URI queue); + + /** + * @see SQSApi#getAttributes(URI, Iterable) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "GetQueueAttributes") + @XMLResponseParser(AttributesHandler.class) + ListenableFuture> getAttributes(@EndpointParam URI queue, + @BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable attributeNames); + + /** + * @see SQSApi#getAttribute + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "GetQueueAttributes") + @XMLResponseParser(ValueHandler.class) + ListenableFuture getAttribute(@EndpointParam URI queue, @FormParam("AttributeName.1") String attributeName); + + /** + * @see SQSApi#setAttribute + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SetQueueAttributes") + ListenableFuture setAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name, + @FormParam("Attribute.Value") String value); + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index 57fb80a70e..51636dbf0d 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -19,420 +19,57 @@ package org.jclouds.sqs; import java.net.URI; -import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.sqs.domain.Action; -import org.jclouds.sqs.domain.Message; -import org.jclouds.sqs.domain.MessageIdAndMD5; -import org.jclouds.sqs.domain.QueueAttributes; -import org.jclouds.sqs.options.CreateQueueOptions; -import org.jclouds.sqs.options.ListQueuesOptions; -import org.jclouds.sqs.options.ReceiveMessageOptions; -import org.jclouds.sqs.options.SendMessageOptions; +import org.jclouds.location.Region; +import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; + +import com.google.common.annotations.Beta; +import com.google.inject.Provides; /** * Provides access to SQS via their REST API. *

* - * @see SQSAsyncApi * @author Adrian Cole + * @see SQSAsyncApi */ +@Beta @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface SQSApi { + + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); /** - * The ListQueues action returns a list of your queues. The maximum number of - * queues that can be returned is 1000. If you specify a value for the - * optional QueueNamePrefix parameter, only queues with a name beginning with - * the specified value are returned - * - * @param region - * Queues are Region-specific. - * @param options - * specify prefix or other options - * - * @see + * Provides synchronous access to Queue features. */ - Set listQueuesInRegion(@Nullable String region); + @Delegate + QueueApi getQueueApi(); - Set listQueuesInRegion(@Nullable String region, ListQueuesOptions options); + @Delegate + QueueApi getQueueApiForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** - * The CreateQueue action creates a new queue. - * - * When you request CreateQueue, you provide a name for the queue. To - * successfully create a new queue, you must provide a name that is unique - * within the scope of your own queues. - * - *

Note

- * - * If you delete a queue, you must wait at least 60 seconds before creating a - * queue with the same name. - * - * If you provide the name of an existing queue, along with the exact names - * and values of all the queue's attributes, CreateQueue returns the queue - * URL for the existing queue. If the queue name, attribute names, or - * attribute values do not match an existing queue, CreateQueue returns an - * error. - * - *

Tip

- * - * Use GetQueueUrl to get a queue's URL. GetQueueUrl requires only the - * QueueName parameter. - * - * @param region - * Queues are Region-specific. - * @param queueName - * The name to use for the queue created. Constraints: Maximum 80 - * characters; alphanumeric characters, hyphens (-), and - * underscores (_) are allowed. + * Provides synchronous access to Message features. */ - // this will gracefully attempt to resolve name issues - @Timeout(duration = 61, timeUnit = TimeUnit.SECONDS) - URI createQueueInRegion(@Nullable String region, String queueName); + @Delegate + MessageApi getMessageApiForQueue(@EndpointParam URI queue); /** - * same as {@link #createQueueInRegion(String, String)} except you can - * control options such as delay seconds. - * - * @param options - * options such as delay seconds - * @see #createQueueInRegion(String, String) + * Provides synchronous access to Permission features. */ - @Timeout(duration = 61, timeUnit = TimeUnit.SECONDS) - URI createQueueInRegion(@Nullable String region, String queueName, CreateQueueOptions options); + @Delegate + PermissionApi getPermissionApiForQueue(@EndpointParam URI queue); - /** - * The DeleteQueue action deletes the queue specified by the queue URL, - * regardless of whether the queue is empty. If the specified queue does not - * exist, SQS returns a successful response. - * - *

Caution

- * - * Use DeleteQueue with care; once you delete your queue, any messages in the - * queue are no longer available. - * - * When you delete a queue, the deletion process takes up to 60 seconds. - * Requests you send involving that queue during the 60 seconds might - * succeed. For example, a SendMessage request might succeed, but after the - * 60 seconds, the queue and that message you sent no longer exist. Also, - * when you delete a queue, you must wait at least 60 seconds before creating - * a queue with the same name. - * - * We reserve the right to delete queues that have had no activity for more - * than 30 days. For more information, see About SQS Queues in the Amazon SQS - * Developer Guide. - * - * @param queue - * queue you want to delete - */ - void deleteQueue(URI queue); - - /** - * The DeleteMessage action deletes the specified message from the specified - * queue. You specify the message by using the message's receipt handle and - * not the message ID you received when you sent the message. Even if the - * message is locked by another reader due to the visibility timeout setting, - * it is still deleted from the queue. If you leave a message in the queue - * for more than 4 days, SQS automatically deletes it. - * - *

Note

- * - * The receipt handle is associated with a specific instance of receiving the - * message. If you receive a message more than once, the receipt handle you - * get each time you receive the message is different. When you request - * DeleteMessage, if you don't provide the most recently received receipt - * handle for the message, the request will still succeed, but the message - * might not be deleted. - * - *

Important

- * - * It is possible you will receive a message even after you have deleted it. - * This might happen on rare occasions if one of the servers storing a copy - * of the message is unavailable when you request to delete the message. The - * copy remains on the server and might be returned to you again on a - * subsequent receive request. You should create your system to be idempotent - * so that receiving a particular message more than once is not a problem. - * - * @param queue - * the queue the message is in - * @param receiptHandle - * The receipt handle associated with the message you want to - * delete. - */ - void deleteMessage(URI queue, String receiptHandle); - - /** - * The ChangeMessageVisibility action changes the visibility timeout of a - * specified message in a queue to a new value. The maximum allowed timeout - * value you can set the value to is 12 hours. This means you can't extend - * the timeout of a message in an existing queue to more than a total - * visibility timeout of 12 hours. (For more information visibility timeout, - * see Visibility Timeout in the Amazon SQS Developer Guide.) - * - * For example, let's say the timeout for the queue is 30 seconds, and you - * receive a message. Once you're 20 seconds into the timeout for that - * message (i.e., you have 10 seconds left), you extend it by 60 seconds by - * calling ChangeMessageVisibility with VisibilityTimeoutset to 60 seconds. - * You have then changed the remaining visibility timeout from 10 seconds to - * 60 seconds. - * - *

Important

- * - * If you attempt to set the VisibilityTimeout to an amount more than the - * maximum time left, Amazon SQS returns an error. It will not automatically - * recalculate and increase the timeout to the maximum time remaining. - * - *

Important

- * - * Unlike with a queue, when you change the visibility timeout for a specific - * message, that timeout value is applied immediately but is not saved in - * memory for that message. If you don't delete a message after it is - * received, the visibility timeout for the message the next time it is - * received reverts to the original timeout value, not the value you set with - * the ChangeMessageVisibility action. - * - * @param queue - * the queue the message is in - * @param receiptHandle - * The receipt handle associated with the message whose visibility - * timeout you want to change. This parameter is returned by the - * ReceiveMessage action. - * @param visibilityTimeout - * The new value for the message's visibility timeout (in seconds) - * from 0 to 43200 (maximum 12 hours) - */ - void changeMessageVisibility(URI queue, String receiptHandle, int visibilityTimeout); - - /** - * The AddPermission action adds a permission to a queue for a specific - * principal. This allows for sharing access to the queue. - * - * When you create a queue, you have full control access rights for the - * queue. Only you (as owner of the queue) can grant or deny permissions to - * the queue. For more information about these permissions, see Shared Queues - * in the Amazon SQS Developer Guide. - * - * Note - * - * AddPermission writes an SQS-generated policy. If you want to write your - * own policy, use SetQueueAttributes to upload your policy. - * - * @param queue - * queue to change permissions on - * @param label - * - * The unique identification of the permission you're setting. - * example: AliceSendMessage - * - * Constraints: Maximum 80 characters; alphanumeric characters, - * hyphens (-), and underscores (_) are allowed. - * @param permission - * The action you want to allow for the specified principal. - * @param accountId - * The AWS account number of the principal who will be given - * permission. The principal must have an AWS account, but does not - * need to be signed up for Amazon SQS. For information about - * locating the AWS account identification, see Your AWS - * Identifiers in the Amazon SQS Developer Guide. - * - * Constraints: Valid 12-digit AWS account number, without hyphens - * - */ - void addPermissionToAccount(URI queue, String label, Action permission, String accountId); - - /** - * The RemovePermission action revokes any permissions in the queue policy - * that matches the Label parameter. Only the owner of the queue can remove - * permissions. - * - * @param queue - * queue to change permissions on - * - * @param label - * The identification of the permission you want to remove. This is - * the label you added in AddPermission. example: AliceSendMessage - */ - void removePermission(URI queue, String label); - - /** - * The SendMessage action delivers a message to the specified queue. The - * maximum allowed message size is 64 KB. - * - *

Important

- * - * The following list shows the characters (in Unicode) allowed in your - * message, according to the W3C XML specification (for more information, go - * to http://www.w3.org/TR/REC-xml/#charsets). If you send any characters not - * included in the list, your request will be rejected. - * - * - * {@code #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]} - * - * @param queue - * queue you want to send to - * - * @param message - * Type: String maximum 64 KB in size. For a list of allowed - * characters, see the preceding important note. - * @return id of the message and md5 of the content sent - */ - MessageIdAndMD5 sendMessage(URI queue, String message); - - /** - * same as {@link #sendMessage(URI, String)} except you can control options - * such as delay seconds. - * - * @param options - * options such as delay seconds - * @see #sendMessage(URI, String) - */ - MessageIdAndMD5 sendMessage(URI queue, String message, SendMessageOptions options); - - /** - * The ReceiveMessage action retrieves one or more messages from the - * specified queue. The ReceiveMessage action does not delete the message - * after it is retrieved. To delete a message, you must use the DeleteMessage - * action. For more information about message deletion in the message life - * cycle, see Message Lifecycle. - * - *

Note

- * - * Due to the distributed nature of the queue, a weighted random set of - * machines is sampled on a ReceiveMessage call. That means only the messages - * on the sampled machines are returned. If the number of messages in the - * queue is small (less than 1000), it is likely you will get fewer messages - * than you requested per ReceiveMessage call. If the number of messages in - * the queue is extremely small, you might not receive any messages in a - * particular ReceiveMessage response; in which case you should repeat the - * request. - * - * @param queue - * from where you are receiving messages - * @return message including the receipt handle you can use to delete it - */ - Message receiveMessage(URI queue); - - /** - * same as {@link #receiveMessage(URI)} except you can provide options like - * VisibilityTimeout parameter in your request, which will be applied to the - * messages that SQS returns in the response. If you do not include the - * parameter, the overall visibility timeout for the queue is used for the - * returned messages. - * - * @param options - * options such as VisibilityTimeout - * @see #receiveMessage(URI) - */ - Message receiveMessage(URI queue, ReceiveMessageOptions options); - - /** - * same as {@link #receiveMessage(URI)} except you can receive multiple - * messages. - * - * @param max - * maximum messages to receive, current limit is 10 - * @see #receiveMessage(URI) - */ - Set receiveMessages(URI queue, int max); - - /** - * returns all attributes of a queue. - * - * @param queue - * queue to get the attributes of - */ - QueueAttributes getQueueAttributes(URI queue); - - /** - * The SetQueueAttributes action sets one attribute of a queue per request. - * When you change a queue's attributes, the change can take up to 60 seconds - * to propagate throughout the SQS system. - * - * @param queue - * queue to set the attribute on - * @param name - * - * The name of the attribute you want to set. - * - * VisibilityTimeout - The length of time (in seconds) that a - * message received from a queue will be invisible to other - * receiving components when they ask to receive messages. For more - * information about VisibilityTimeout, see Visibility Timeout in - * the Amazon SQS Developer Guide. - * - * Policy - The formal description of the permissions for a - * resource. For more information about Policy, see Basic Policy - * Structure in the Amazon SQS Developer Guide. - * - * MaximumMessageSize - The limit of how many bytes a message can - * contain before Amazon SQS rejects it. - * - * MessageRetentionPeriod - The number of seconds Amazon SQS - * retains a message. - * - * DelaySeconds - The time in seconds that the delivery of all - * messages in the queue will be delayed. - * @param value - * The value of the attribute you want to set. To delete a queue's - * access control policy, set the policy to "". - * - * Constraints: Constraints are specific for each value. - * - * VisibilityTimeout - An integer from 0 to 43200 (12 hours). The - * default for this attribute is 30 seconds. - * - * Policy - A valid form-url-encoded policy. For more information - * about policy structure, see Basic Policy Structure in the Amazon - * SQS Developer Guide. For more information about - * form-url-encoding, see - * http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1. - * - * MaximumMessageSize - An integer from 1024 bytes (1 KiB) up to - * 65536 bytes (64 KiB). The default for this attribute is 65536 - * (64 KiB). - * - * MessageRetentionPeriod - Integer representing seconds, from 60 - * (1 minute) to 1209600 (14 days). The default for this attribute - * is 345600 (4 days). - * - * DelaySeconds - An integer from 0 to 900 (15 minutes). The - * default for this attribute is 0. - */ - void setQueueAttribute(URI queue, String name, String value); - - /** - * returns some attributes of a queue. - * - * @param queue - * queue to get the attributes of - */ - Map getQueueAttributes(URI queue, Iterable attributeNames); - - /** - * returns an attribute of a queue. - * - * @param queue - * queue to get the attributes of - */ - String getQueueAttribute(URI queue, String attributeName); - - /** - * same as {@link #receiveMessages(URI, int)} except you can provide options - * like VisibilityTimeout parameter in your request, which will be applied to - * the messages that SQS returns in the response. If you do not include the - * parameter, the overall visibility timeout for the queue is used for the - * returned messages. - * - * @param options - * options such as VisibilityTimeout - * @see #receiveMessages(URI, int) - */ - Set receiveMessages(URI queue, int max, ReceiveMessageOptions options); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index 238dee8e3a..164b3e98e7 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -18,243 +18,62 @@ */ package org.jclouds.sqs; -import static org.jclouds.sqs.reference.SQSParameters.ACTION; -import static org.jclouds.sqs.reference.SQSParameters.VERSION; - import java.net.URI; -import java.util.Map; import java.util.Set; -import javax.ws.rs.FormParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.jclouds.Constants; import org.jclouds.aws.filters.FormSigner; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.location.Region; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; -import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.EndpointParam; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.VirtualHost; -import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams; -import org.jclouds.sqs.domain.Action; -import org.jclouds.sqs.domain.Message; -import org.jclouds.sqs.domain.MessageIdAndMD5; -import org.jclouds.sqs.domain.QueueAttributes; -import org.jclouds.sqs.functions.MapToQueueAttributes; -import org.jclouds.sqs.options.CreateQueueOptions; -import org.jclouds.sqs.options.ListQueuesOptions; -import org.jclouds.sqs.options.ReceiveMessageOptions; -import org.jclouds.sqs.options.SendMessageOptions; -import org.jclouds.sqs.xml.AttributesHandler; -import org.jclouds.sqs.xml.MessageHandler; -import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; -import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; -import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; -import org.jclouds.sqs.xml.RegexQueueHandler; -import org.jclouds.sqs.xml.ValueHandler; -import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.annotations.Beta; +import com.google.inject.Provides; /** - * Provides access to SQS via their REST API. + * Provides access to SQS via REST API. *

* + * @see SQS + * documentation * @author Adrian Cole */ +@Beta @RequestFilters(FormSigner.class) -@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") @VirtualHost public interface SQSAsyncApi { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); /** - * @see SQSApi#listQueuesInRegion + * Provides asynchronous access to Queue features. */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ListQueues") - @ResponseParser(RegexListQueuesResponseHandler.class) - ListenableFuture> listQueuesInRegion( + @Delegate + QueueAsyncApi getQueueApi(); + + @Delegate + QueueAsyncApi getQueueApiForRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** - * @see SQSApi#listQueuesInRegion + * Provides asynchronous access to Message features. */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ListQueues") - @ResponseParser(RegexListQueuesResponseHandler.class) - ListenableFuture> listQueuesInRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - ListQueuesOptions options); + @Delegate + MessageAsyncApi getMessageApiForQueue(@EndpointParam URI queue); /** - * @see SQSApi#createQueueInRegion + * Provides asynchronous access to Permission features. */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "CreateQueue") - @ResponseParser(RegexQueueHandler.class) - ListenableFuture createQueueInRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - @FormParam("QueueName") String queueName); - - /** - * @see SQSApi#createQueueInRegion - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "CreateQueue") - @ResponseParser(RegexQueueHandler.class) - ListenableFuture createQueueInRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - @FormParam("QueueName") String queueName, CreateQueueOptions options); - - /** - * @see SQSApi#deleteQueue - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "DeleteQueue") - ListenableFuture deleteQueue(@EndpointParam URI queue); - - /** - * @see SQSApi#deleteMessage - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "DeleteMessage") - ListenableFuture deleteMessage(@EndpointParam URI queue, @FormParam("ReceiptHandle") String receiptHandle); - - /** - * @see SQSApi#changeMessageVisibility - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ChangeMessageVisibility") - ListenableFuture changeMessageVisibility(@EndpointParam URI queue, - @FormParam("ReceiptHandle") String receiptHandle, @FormParam("VisibilityTimeout") int visibilityTimeout); - - /** - * @see SQSApi#sendMessage - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "SendMessage") - @ResponseParser(RegexMessageIdAndMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam URI queue, - @FormParam("MessageBody") String message); - - /** - * @see SQSApi#sendMessage - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "SendMessage") - @ResponseParser(RegexMessageIdAndMD5Handler.class) - ListenableFuture sendMessage(@EndpointParam URI queue, - @FormParam("MessageBody") String message, SendMessageOptions options); - - /** - * @see SQSApi#receiveMessage - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(MessageHandler.class) - ListenableFuture receiveMessage(@EndpointParam URI queue); - - /** - * @see SQSApi#receiveMessage - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(MessageHandler.class) - ListenableFuture receiveMessage(@EndpointParam URI queue, ReceiveMessageOptions options); - - /** - * @see SQSApi#getQueueAttributes(URI) - */ - @POST - @Path("/") - @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" }) - @Transform(MapToQueueAttributes.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @XMLResponseParser(AttributesHandler.class) - ListenableFuture getQueueAttributes(@EndpointParam URI queue); - - /** - * @see SQSApi#getQueueAttributes(URI, Iterable) - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "GetQueueAttributes") - @XMLResponseParser(AttributesHandler.class) - ListenableFuture> getQueueAttributes(@EndpointParam URI queue, - @BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable attributeNames); - - /** - * @see SQSApi#getQueueAttribute - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "GetQueueAttributes") - @XMLResponseParser(ValueHandler.class) - ListenableFuture getQueueAttribute(@EndpointParam URI queue, - @FormParam("AttributeName.1") String attributeName); - - /** - * @see SQSApi#setQueueAttribute - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "SetQueueAttributes") - ListenableFuture setQueueAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name, - @FormParam("Attribute.Value") String value); - - /** - * @see SQSApi#receiveMessages - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receiveMessages(@EndpointParam URI queue, - @FormParam("MaxNumberOfMessages") int max); - - /** - * @see SQSApi#receiveMessages - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receiveMessages(@EndpointParam URI queue, - @FormParam("MaxNumberOfMessages") int max, ReceiveMessageOptions options); - - /** - * @see SQSApi#addPermissionToAccount - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "AddPermission") - ListenableFuture addPermissionToAccount(@EndpointParam URI queue, @FormParam("Label") String label, - @FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId); - - /** - * @see SQSApi#removePermission - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "RemovePermission") - ListenableFuture removePermission(@EndpointParam URI queue, @FormParam("Label") String label); + @Delegate + PermissionAsyncApi getPermissionApiForQueue(@EndpointParam URI queue); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java index ea7fe2192b..1839c951b6 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java @@ -18,6 +18,8 @@ */ package org.jclouds.sqs.config; +import java.util.Map; + import org.jclouds.aws.config.FormSigningRestClientModule; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpRetryHandler; @@ -25,11 +27,18 @@ import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.sqs.MessageApi; +import org.jclouds.sqs.MessageAsyncApi; +import org.jclouds.sqs.PermissionApi; +import org.jclouds.sqs.PermissionAsyncApi; +import org.jclouds.sqs.QueueApi; +import org.jclouds.sqs.QueueAsyncApi; import org.jclouds.sqs.SQSApi; import org.jclouds.sqs.SQSAsyncApi; import org.jclouds.sqs.handlers.ParseSQSErrorFromXmlContent; import org.jclouds.sqs.handlers.SQSErrorRetryHandler; +import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; /** @@ -39,11 +48,16 @@ import com.google.common.reflect.TypeToken; */ @ConfiguresRestClient public class SQSRestClientModule extends FormSigningRestClientModule { + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// + .put(QueueApi.class, QueueAsyncApi.class) + .put(MessageApi.class, MessageAsyncApi.class) + .put(PermissionApi.class, PermissionAsyncApi.class) + .build(); public SQSRestClientModule() { - super(TypeToken.of(SQSApi.class), TypeToken.of(SQSAsyncApi.class)); + super(TypeToken.of(SQSApi.class), TypeToken.of(SQSAsyncApi.class), DELEGATE_MAP); } - + @Override protected void bindErrorHandlers() { bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSQSErrorFromXmlContent.class); diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java index ec4303ff7b..24567740b8 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java @@ -41,7 +41,9 @@ import com.google.common.collect.Iterables; */ @Test(groups = "unit", testName = "SQSApiExpectTest") public class SQSApiExpectTest extends BaseSQSApiExpectTest { - + + URI queue = URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"); + public HttpRequest createQueue = HttpRequest.builder() .method("POST") .endpoint("https://sqs.us-east-1.amazonaws.com/") @@ -62,7 +64,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(createQueue, createQueueResponse); - assertEquals(apiWhenExist.createQueueInRegion(null, "queueName").toString(), new CreateQueueResponseTest().expected().toString()); + assertEquals(apiWhenExist.getQueueApi().create("queueName").toString(), new CreateQueueResponseTest().expected() + .toString()); } public HttpRequest sendMessage = HttpRequest.builder() @@ -85,7 +88,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(sendMessage, sendMessageResponse); - assertEquals(apiWhenExist.sendMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "hardyharhar").toString(), new SendMessageResponseTest().expected().toString()); + assertEquals(apiWhenExist.getMessageApiForQueue(queue).send("hardyharhar").toString(), + new SendMessageResponseTest().expected().toString()); } @@ -108,9 +112,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(receiveMessage, receiveMessageResponse); - assertEquals( - apiWhenExist.receiveMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")) - .toString(), Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString()); + assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive().toString(), + Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString()); } @@ -134,9 +137,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(receiveMessages, receiveMessagesResponse); - assertEquals( - apiWhenExist.receiveMessages(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), 10) - .toString(), new ReceiveMessageResponseTest().expected().toString()); + assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive(10).toString(), new ReceiveMessageResponseTest() + .expected().toString()); } public HttpRequest deleteMessage = HttpRequest.builder() @@ -163,8 +165,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(deleteMessage, deleteMessageResponse); - apiWhenExist.deleteMessage(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), - "eXJYhj5rDr9cAe"); + apiWhenExist.getMessageApiForQueue(queue).delete("eXJYhj5rDr9cAe"); } @@ -193,8 +194,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibility, changeMessageVisibilityResponse); - apiWhenExist.changeMessageVisibility(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), - "eXJYhj5rDr9cAe", 10); + apiWhenExist.getMessageApiForQueue(queue).changeVisibility("eXJYhj5rDr9cAe", 10); } public HttpRequest getQueueAttribute = HttpRequest.builder() @@ -221,7 +221,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(getQueueAttribute, getQueueAttributeResponse); - assertEquals(apiWhenExist.getQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "VisibilityTimeout"), "30"); + assertEquals(apiWhenExist.getQueueApi().getAttribute(queue, "VisibilityTimeout"), "30"); } public HttpRequest getQueueAttributes = HttpRequest.builder() @@ -244,7 +244,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(getQueueAttributes, getQueueAttributesResponse); - assertEquals(apiWhenExist.getQueueAttributes(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")).toString(), new MapToQueueAttributesTest().expected().toString()); + assertEquals(apiWhenExist.getQueueApi().getAttributes(queue).toString(), new MapToQueueAttributesTest() + .expected().toString()); } public HttpRequest getQueueAttributesSubset = HttpRequest.builder() @@ -268,10 +269,8 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(getQueueAttributesSubset, getQueueAttributesSubsetResponse); - assertEquals( - apiWhenExist.getQueueAttributes( - URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), - ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(), + assertEquals(apiWhenExist.getQueueApi() + .getAttributes(queue, ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(), new GetQueueAttributesResponseTest().expected().toString()); } @@ -300,8 +299,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(setQueueAttribute, setQueueAttributeResponse); - apiWhenExist.setQueueAttribute(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), - "MaximumMessageSize", "1"); + apiWhenExist.getQueueApi().setAttribute(queue, "MaximumMessageSize", "1"); } public HttpRequest addPermission = HttpRequest.builder() @@ -330,7 +328,7 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(addPermission, addPermissionResponse); - apiWhenExist.addPermissionToAccount(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "testLabel", Action.RECEIVE_MESSAGE, "125074342641"); + apiWhenExist.getPermissionApiForQueue(queue).addPermissionToAccount("testLabel", Action.RECEIVE_MESSAGE, "125074342641"); } public HttpRequest removePermission = HttpRequest.builder() @@ -357,6 +355,6 @@ public class SQSApiExpectTest extends BaseSQSApiExpectTest { SQSApi apiWhenExist = requestSendsResponse(removePermission, removePermissionResponse); - apiWhenExist.removePermission(URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"), "testLabel"); + apiWhenExist.getPermissionApiForQueue(queue).remove("testLabel"); } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java index ee61013517..200c89b0d2 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.sqs; +import static com.google.common.collect.Iterables.get; +import static com.google.common.collect.Iterables.getLast; import static org.jclouds.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint; import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; @@ -30,7 +32,6 @@ import static org.testng.Assert.assertNull; import java.net.URI; import java.util.Map; import java.util.Set; -import java.util.SortedSet; import java.util.concurrent.TimeUnit; import javax.ws.rs.POST; @@ -51,7 +52,6 @@ import org.testng.annotations.Test; import com.google.common.base.Charsets; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; @@ -74,10 +74,10 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { } protected void listQueuesInRegion(String region) throws InterruptedException { - SortedSet allResults = Sets.newTreeSet(api().listQueuesInRegion(region)); + Set allResults = api().getQueueApiForRegion(region).list(); assertNotNull(allResults); if (allResults.size() >= 1) { - URI queue = allResults.last(); + URI queue = getLast(allResults); assertQueueInList(region, queue); } } @@ -91,11 +91,12 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { } public String recreateQueueInRegion(String queueName, String region) throws InterruptedException { - Set result = api().listQueuesInRegion(region, queuePrefix(queueName)); + QueueApi api = api().getQueueApiForRegion(region); + Set result = api.list(queuePrefix(queueName)); if (result.size() >= 1) { - api().deleteQueue(Iterables.getLast(result)); + api.delete(getLast(result)); } - URI queue = api().createQueueInRegion(region, queueName); + URI queue = api.create(queueName); assertQueueInList(region, queue); queues.add(queue); return queueName; @@ -104,8 +105,8 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { @Test(dependsOnMethods = "testCanRecreateQueueGracefully") protected void testGetQueueAttributes() { for (URI queue : queues) { - Map attributes = api().getQueueAttributes(queue, ImmutableSet.of("All")); - assertEquals(api().getQueueAttributes(queue, attributes.keySet()), attributes); + Map attributes = api().getQueueApi().getAttributes(queue, ImmutableSet.of("All")); + assertEquals(api().getQueueApi().getAttributes(queue, attributes.keySet()), attributes); } } @@ -128,29 +129,30 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { @Test(dependsOnMethods = "testGetQueueAttributes") protected void testAddAnonymousPermission() throws InterruptedException { for (URI queue : queues) { - QueueAttributes attributes = api().getQueueAttributes(queue); + QueueAttributes attributes = api().getQueueApi().getAttributes(queue); assertNoPermissions(queue); String accountToAuthorize = getAccountToAuthorize(queue); - api().addPermissionToAccount(queue, "fubar", Action.GET_QUEUE_ATTRIBUTES, accountToAuthorize); + api().getPermissionApiForQueue(queue).addPermissionToAccount("fubar", Action.GET_QUEUE_ATTRIBUTES, + accountToAuthorize); String policyForAuthorizationByAccount = assertPolicyPresent(queue); String policyForAnonymous = policyForAuthorizationByAccount.replace("\"" + accountToAuthorize + "\"", "\"*\""); - api().setQueueAttribute(queue, "Policy", policyForAnonymous); + api().getQueueApi().setAttribute(queue, "Policy", policyForAnonymous); assertEquals(getAnonymousAttributesApi(queue).getQueueArn(), attributes.getQueueArn()); } } protected String getAccountToAuthorize(URI queue) { - return Iterables.get(Splitter.on('/').split(queue.getPath()), 1); + return get(Splitter.on('/').split(queue.getPath()), 1); } @Test(dependsOnMethods = "testAddAnonymousPermission") protected void testRemovePermission() throws InterruptedException { for (URI queue : queues) { - api().removePermission(queue, "fubar"); + api().getPermissionApiForQueue(queue).remove("fubar"); assertNoPermissions(queue); } } @@ -158,22 +160,22 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { @Test(dependsOnMethods = "testGetQueueAttributes") protected void testSetQueueAttribute() { for (URI queue : queues) { - api().setQueueAttribute(queue, "MaximumMessageSize", "1024"); - assertEquals(api().getQueueAttributes(queue).getMaximumMessageSize(), 1024); + api().getQueueApi().setAttribute(queue, "MaximumMessageSize", "1024"); + assertEquals(api().getQueueApi().getAttributes(queue).getMaximumMessageSize(), 1024); } } @Test(dependsOnMethods = "testGetQueueAttributes") protected void testSendMessage() { for (URI queue : queues) { - assertEquals(api().sendMessage(queue, message).getMD5(), md5); + assertEquals(api().getMessageApiForQueue(queue).send(message).getMD5(), md5); } } @Test(dependsOnMethods = "testSendMessage") protected void testReceiveMessageWithoutHidingMessage() { for (URI queue : queues) { - assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5); + assertEquals(api().getMessageApiForQueue(queue).receive(attribute("All").visibilityTimeout(0)).getMD5(), md5); } } @@ -182,21 +184,22 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { @Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage") protected void testChangeMessageVisibility() { for (URI queue : queues) { + MessageApi api = api().getMessageApiForQueue(queue); // start hiding it at 5 seconds - receiptHandle = api().receiveMessage(queue, attribute("None").visibilityTimeout(5)).getReceiptHandle(); + receiptHandle = api.receive(attribute("None").visibilityTimeout(5)).getReceiptHandle(); // hidden message, so we can't see it - assertNull(api().receiveMessage(queue)); + assertNull(api.receive()); // this should unhide it - api().changeMessageVisibility(queue, receiptHandle, 0); + api.changeVisibility(receiptHandle, 0); // so we can see it again - assertEquals(api().receiveMessage(queue, attribute("All").visibilityTimeout(0)).getMD5(), md5); + assertEquals(api.receive(attribute("All").visibilityTimeout(0)).getMD5(), md5); } } @Test(dependsOnMethods = "testChangeMessageVisibility") protected void testDeleteMessage() throws InterruptedException { for (URI queue : queues) { - api().deleteMessage(queue, receiptHandle); + api().getMessageApiForQueue(queue).delete(receiptHandle); assertNoMessages(queue); } } @@ -205,7 +208,7 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest { @AfterClass(groups = "live") protected void tearDownContext() { for (URI queue : queues) { - api().deleteQueue(queue); + api().getQueueApi().delete(queue); } super.tearDownContext(); } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index c95d3def31..7b60c8df48 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -56,7 +56,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest policy = new AtomicReference(); assertEventually(new Runnable() { public void run() { - String policyForAuthorizationByAccount = api().getQueueAttribute(queue, "Policy"); + String policyForAuthorizationByAccount = api().getQueueApi().getAttribute(queue, "Policy"); assertNotNull(policyForAuthorizationByAccount); policy.set(policyForAuthorizationByAccount); @@ -68,7 +68,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest result = api().listQueuesInRegion(region); + Set result = api().getQueueApiForRegion(region).list(); assertNotNull(result); assert result.size() >= 1 : result; assertTrue(result.contains(finalQ), finalQ + " not in " + result); From 2984626b9c269b2bc4ce17bafb9a9e19057a5bb8 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 14 Sep 2012 12:30:44 -0400 Subject: [PATCH 19/60] issue 1069: Allowing @Nullable container to be null in compareTo --- .../openstack/swift/domain/internal/ObjectInfoImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/internal/ObjectInfoImpl.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/internal/ObjectInfoImpl.java index 3d88cace84..e4022ce3e9 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/internal/ObjectInfoImpl.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/internal/ObjectInfoImpl.java @@ -33,6 +33,7 @@ import org.jclouds.openstack.swift.domain.ObjectInfo; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ComparisonChain; +import com.google.common.collect.Ordering; /** * Class ObjectInfoImpl @@ -243,6 +244,6 @@ public class ObjectInfoImpl implements ObjectInfo { @Override public int compareTo(ObjectInfo other) { - return ComparisonChain.start().compare(name, other.getName()).compare(container, other.getContainer()).result(); + return ComparisonChain.start().compare(name, other.getName()).compare(container, other.getContainer(), Ordering.natural().nullsLast()).result(); } } From 6782d8d4d6afbc628817a82cf6d6465fb2eab331 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 14 Sep 2012 17:42:31 -0700 Subject: [PATCH 20/60] added base binders for indexing amazon apis --- .../binders/BindMapToIndexedFormParams.java | 78 ++++++++++++++++++ .../binders/BindTableToIndexedFormParams.java | 81 +++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 common/aws/src/main/java/org/jclouds/aws/binders/BindMapToIndexedFormParams.java create mode 100644 common/aws/src/main/java/org/jclouds/aws/binders/BindTableToIndexedFormParams.java diff --git a/common/aws/src/main/java/org/jclouds/aws/binders/BindMapToIndexedFormParams.java b/common/aws/src/main/java/org/jclouds/aws/binders/BindMapToIndexedFormParams.java new file mode 100644 index 0000000000..4d390797fc --- /dev/null +++ b/common/aws/src/main/java/org/jclouds/aws/binders/BindMapToIndexedFormParams.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; + +import java.util.Map; +import java.util.Map.Entry; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; + +/** + * @author Adrian Cole + */ +public class BindMapToIndexedFormParams implements Binder { + + private final String keyPattern; + private final String valuePattern; + + protected BindMapToIndexedFormParams(String keyPattern, String valuePattern) { + this.keyPattern = keyPattern; + this.valuePattern = valuePattern; + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + if (checkNotNull(input, "input") instanceof Iterable) + input = Maps.uniqueIndex((Iterable) input, new Function() { + int index = 1; + + @Override + public String apply(String input) { + return index++ + ""; + } + }); + checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map"); + Map mapping = (Map) input; + + ImmutableMap.Builder builder = ImmutableMap.builder(); + int amazonOneBasedIndex = 1; // according to docs, counters must start + // with 1 + for (Entry entry : mapping.entrySet()) { + // not null by contract + builder.put(format(keyPattern, amazonOneBasedIndex), entry.getKey()); + builder.put(format(valuePattern, amazonOneBasedIndex), entry.getValue()); + amazonOneBasedIndex++; + } + Multimap forms = Multimaps.forMap(builder.build()); + return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); + } + +} diff --git a/common/aws/src/main/java/org/jclouds/aws/binders/BindTableToIndexedFormParams.java b/common/aws/src/main/java/org/jclouds/aws/binders/BindTableToIndexedFormParams.java new file mode 100644 index 0000000000..3d0d91d6d7 --- /dev/null +++ b/common/aws/src/main/java/org/jclouds/aws/binders/BindTableToIndexedFormParams.java @@ -0,0 +1,81 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; + +import java.util.Map; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.ImmutableTable.Builder; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; +import com.google.common.collect.Table; +import com.google.common.collect.Table.Cell; + +/** + * @author Adrian Cole + */ +public class BindTableToIndexedFormParams implements Binder { + + private final String rowPattern; + private final String columnPattern; + private final String valuePattern; + + protected BindTableToIndexedFormParams(String rowPattern, String columnPattern, String valuePattern) { + this.rowPattern = rowPattern; + this.columnPattern = columnPattern; + this.valuePattern = valuePattern; + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + if (checkNotNull(input, "input") instanceof Map) { + Builder builder = ImmutableTable.builder(); + int index = 1; + for (Map.Entry entry : ((Map) input).entrySet()) + builder.put(index++, entry.getKey(), entry.getValue()); + input = builder.build(); + } + checkArgument(checkNotNull(input, "input") instanceof Table, "this binder is only valid for Table"); + Table table = Table.class.cast(input); + + ImmutableMap.Builder builder = ImmutableMap.builder(); + int amazonOneBasedIndex = 1; // according to docs, counters must start + // with 1 + for (Cell cell : table.cellSet()) { + // not null by contract + builder.put(format(rowPattern, amazonOneBasedIndex), cell.getRowKey().toString()); + builder.put(format(columnPattern, amazonOneBasedIndex), cell.getColumnKey().toString()); + builder.put(format(valuePattern, amazonOneBasedIndex), cell.getValue().toString()); + + amazonOneBasedIndex++; + } + Multimap forms = Multimaps.forMap(builder.build()); + return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); + } + +} From bc9cffad40264ac6f13cd08e503ebe2d151c221b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 14 Sep 2012 17:42:56 -0700 Subject: [PATCH 21/60] completed batch ops for sqs and modularized tests --- .../java/org/jclouds/sqs/MessageAsyncApi.java | 130 ----- .../src/main/java/org/jclouds/sqs/SQSApi.java | 3 + .../java/org/jclouds/sqs/SQSAsyncApi.java | 3 + ...yBatchRequestEntryToIndexedFormParams.java | 69 +++ ...eBatchRequestEntryToIndexedFormParams.java | 31 + ...eBatchRequestEntryToIndexedFormParams.java | 31 + ...estEntryWithDelaysToIndexedFormParams.java | 68 +++ .../sqs/config/SQSRestClientModule.java | 12 +- .../org/jclouds/sqs/domain/BatchError.java | 155 +++++ .../org/jclouds/sqs/domain/BatchResult.java | 146 +++++ .../sqs/{ => features}/MessageApi.java | 220 ++++++- .../jclouds/sqs/features/MessageAsyncApi.java | 275 +++++++++ .../sqs/{ => features}/PermissionApi.java | 4 +- .../{ => features}/PermissionAsyncApi.java | 6 +- .../jclouds/sqs/{ => features}/QueueApi.java | 4 +- .../sqs/{ => features}/QueueAsyncApi.java | 22 +- .../jclouds/sqs/xml/BatchErrorHandler.java | 68 +++ .../jclouds/sqs/xml/BatchResponseHandler.java | 106 ++++ ...MessageVisibilityBatchResponseHandler.java | 36 ++ .../DeleteMessageBatchResponseHandler.java | 37 ++ .../java/org/jclouds/sqs/xml/IdHandler.java | 46 ++ .../xml/ReceiveMessageResponseHandler.java | 12 +- .../xml/SendMessageBatchResponseHandler.java | 40 ++ .../SendMessageBatchResultEntryHandler.java | 74 +++ .../sqs/xml/TextFromSingleElementHandler.java | 63 ++ .../org/jclouds/sqs/xml/ValueHandler.java | 29 +- .../org/jclouds/sqs/SQSApiExpectTest.java | 360 ------------ .../java/org/jclouds/sqs/SQSApiLiveTest.java | 229 -------- .../sqs/features/BulkMessageApiLiveTest.java | 130 +++++ .../sqs/features/MessageApiExpectTest.java | 542 ++++++++++++++++++ .../sqs/features/MessageApiLiveTest.java | 94 +++ .../sqs/features/PermissionApiExpectTest.java | 89 +++ .../sqs/features/PermissionApiLiveTest.java | 121 ++++ .../sqs/features/QueueApiExpectTest.java | 169 ++++++ .../sqs/features/QueueApiLiveTest.java | 80 +++ .../sqs/internal/BaseSQSApiLiveTest.java | 53 +- .../sqs/internal/BaseSQSExpectTest.java | 3 + ...ngeMessageVisibilityBatchResponseTest.java | 56 ++ .../parse/DeleteMessageBatchResponseTest.java | 56 ++ .../sqs/parse/ReceiveMessageResponseTest.java | 12 +- .../parse/SendMessageBatchResponseTest.java | 65 +++ .../change_message_visibility_batch.xml | 13 + .../test/resources/delete_message_batch.xml | 13 + .../src/test/resources/send_message_batch.xml | 17 + 44 files changed, 3001 insertions(+), 791 deletions(-) delete mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java rename labs/sqs/src/main/java/org/jclouds/sqs/{ => features}/MessageApi.java (52%) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java rename labs/sqs/src/main/java/org/jclouds/sqs/{ => features}/PermissionApi.java (98%) rename labs/sqs/src/main/java/org/jclouds/sqs/{ => features}/PermissionAsyncApi.java (94%) rename labs/sqs/src/main/java/org/jclouds/sqs/{ => features}/QueueApi.java (99%) rename labs/sqs/src/main/java/org/jclouds/sqs/{ => features}/QueueAsyncApi.java (91%) create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java create mode 100644 labs/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java delete mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java delete mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java create mode 100644 labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java create mode 100644 labs/sqs/src/test/resources/change_message_visibility_batch.xml create mode 100644 labs/sqs/src/test/resources/delete_message_batch.xml create mode 100644 labs/sqs/src/test/resources/send_message_batch.xml diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java deleted file mode 100644 index c52701cfb4..0000000000 --- a/labs/sqs/src/main/java/org/jclouds/sqs/MessageAsyncApi.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs; - -import static org.jclouds.sqs.reference.SQSParameters.ACTION; -import static org.jclouds.sqs.reference.SQSParameters.VERSION; - -import java.util.Set; - -import javax.ws.rs.FormParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.jclouds.Constants; -import org.jclouds.aws.filters.FormSigner; -import org.jclouds.rest.annotations.FormParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.annotations.VirtualHost; -import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.sqs.domain.Message; -import org.jclouds.sqs.domain.MessageIdAndMD5; -import org.jclouds.sqs.options.ReceiveMessageOptions; -import org.jclouds.sqs.options.SendMessageOptions; -import org.jclouds.sqs.xml.MessageHandler; -import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; -import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * Provides access to SQS via their REST API. - *

- * - * @author Adrian Cole - */ -@RequestFilters(FormSigner.class) -@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") -@VirtualHost -public interface MessageAsyncApi { - - /** - * @see SQSApi#delete - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "DeleteMessage") - ListenableFuture delete(@FormParam("ReceiptHandle") String receiptHandle); - - /** - * @see SQSApi#changeVisibility - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ChangeMessageVisibility") - ListenableFuture changeVisibility(@FormParam("ReceiptHandle") String receiptHandle, - @FormParam("VisibilityTimeout") int visibilityTimeout); - - /** - * @see SQSApi#send - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "SendMessage") - @ResponseParser(RegexMessageIdAndMD5Handler.class) - ListenableFuture send(@FormParam("MessageBody") String message); - - /** - * @see SQSApi#send - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "SendMessage") - @ResponseParser(RegexMessageIdAndMD5Handler.class) - ListenableFuture send(@FormParam("MessageBody") String message, SendMessageOptions options); - - /** - * @see SQSApi#receive - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(MessageHandler.class) - ListenableFuture receive(); - - /** - * @see SQSApi#receive - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(MessageHandler.class) - ListenableFuture receive(ReceiveMessageOptions options); - - /** - * @see SQSApi#receive - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max); - - /** - * @see SQSApi#receive - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "ReceiveMessage") - @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max, - ReceiveMessageOptions options); - -} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java index 51636dbf0d..8804e24904 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java @@ -28,6 +28,9 @@ import org.jclouds.location.Region; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.sqs.features.MessageApi; +import org.jclouds.sqs.features.PermissionApi; +import org.jclouds.sqs.features.QueueApi; import com.google.common.annotations.Beta; import com.google.inject.Provides; diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java index 164b3e98e7..c9a8f0ed56 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java @@ -29,6 +29,9 @@ import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.sqs.features.MessageAsyncApi; +import org.jclouds.sqs.features.PermissionAsyncApi; +import org.jclouds.sqs.features.QueueAsyncApi; import com.google.common.annotations.Beta; import com.google.inject.Provides; diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java new file mode 100644 index 0000000000..1a722aa84c --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.binders; + +import java.util.Map; + +import org.jclouds.aws.binders.BindTableToIndexedFormParams; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.ImmutableTable.Builder; +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams extends BindTableToIndexedFormParams + implements MapBinder { + + protected BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams() { + super("ChangeMessageVisibilityBatchRequestEntry.%d.Id", + "ChangeMessageVisibilityBatchRequestEntry.%d.ReceiptHandle", + "ChangeMessageVisibilityBatchRequestEntry.%d.VisibilityTimeout"); + } + + public Map idReceiptHandle(Iterable input) { + return Maps.uniqueIndex((Iterable) input, new Function() { + int index = 1; + + @Override + public String apply(String input) { + return index++ + ""; + } + }); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Map postParams) { + Map idReceiptHandle = (Map) postParams.get("idReceiptHandle"); + if (idReceiptHandle == null) { + idReceiptHandle = idReceiptHandle((Iterable) postParams.get("receiptHandles")); + } + int visibilityTimeout = (Integer) postParams.get("visibilityTimeout"); + + Builder builder = ImmutableTable.builder(); + for (Map.Entry entry : idReceiptHandle.entrySet()) + builder.put(entry.getKey(), entry.getValue(), visibilityTimeout); + return bindToRequest(request, (Object) builder.build()); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java new file mode 100644 index 0000000000..dd1ba5e9ad --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java @@ -0,0 +1,31 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.binders; + +import org.jclouds.aws.binders.BindMapToIndexedFormParams; + +/** + * @author Adrian Cole + */ +public class BindDeleteMessageBatchRequestEntryToIndexedFormParams extends BindMapToIndexedFormParams { + + protected BindDeleteMessageBatchRequestEntryToIndexedFormParams() { + super("DeleteMessageBatchRequestEntry.%d.Id", "DeleteMessageBatchRequestEntry.%d.ReceiptHandle"); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java new file mode 100644 index 0000000000..748c7d0fcb --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java @@ -0,0 +1,31 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.binders; + +import org.jclouds.aws.binders.BindMapToIndexedFormParams; + +/** + * @author Adrian Cole + */ +public class BindSendMessageBatchRequestEntryToIndexedFormParams extends BindMapToIndexedFormParams { + + protected BindSendMessageBatchRequestEntryToIndexedFormParams() { + super("SendMessageBatchRequestEntry.%d.Id", "SendMessageBatchRequestEntry.%d.MessageBody"); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java new file mode 100644 index 0000000000..0727a47989 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.binders; + +import java.util.Map; + +import org.jclouds.aws.binders.BindTableToIndexedFormParams; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.ImmutableTable.Builder; +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams extends BindTableToIndexedFormParams + implements MapBinder { + + protected BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams() { + super("SendMessageBatchRequestEntry.%d.Id", "SendMessageBatchRequestEntry.%d.MessageBody", + "SendMessageBatchRequestEntry.%d.DelaySeconds"); + } + + public Map idMessageBody(Iterable input) { + return Maps.uniqueIndex((Iterable) input, new Function() { + int index = 1; + + @Override + public String apply(String input) { + return index++ + ""; + } + }); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Map postParams) { + Map idMessageBody = (Map) postParams.get("idMessageBody"); + if (idMessageBody == null) { + idMessageBody = idMessageBody((Iterable) postParams.get("messageBodies")); + } + int delaySeconds = (Integer) postParams.get("delaySeconds"); + + Builder builder = ImmutableTable.builder(); + for (Map.Entry entry : idMessageBody.entrySet()) + builder.put(entry.getKey(), entry.getValue(), delaySeconds); + return bindToRequest(request, (Object) builder.build()); + } +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java index 1839c951b6..09b4882d07 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java @@ -27,14 +27,14 @@ import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.sqs.MessageApi; -import org.jclouds.sqs.MessageAsyncApi; -import org.jclouds.sqs.PermissionApi; -import org.jclouds.sqs.PermissionAsyncApi; -import org.jclouds.sqs.QueueApi; -import org.jclouds.sqs.QueueAsyncApi; import org.jclouds.sqs.SQSApi; import org.jclouds.sqs.SQSAsyncApi; +import org.jclouds.sqs.features.MessageApi; +import org.jclouds.sqs.features.MessageAsyncApi; +import org.jclouds.sqs.features.PermissionApi; +import org.jclouds.sqs.features.PermissionAsyncApi; +import org.jclouds.sqs.features.QueueApi; +import org.jclouds.sqs.features.QueueAsyncApi; import org.jclouds.sqs.handlers.ParseSQSErrorFromXmlContent; import org.jclouds.sqs.handlers.SQSErrorRetryHandler; diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java new file mode 100644 index 0000000000..45696f4d70 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java @@ -0,0 +1,155 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class BatchError { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromErrorEntry(this); + } + + public static class Builder { + + private String id; + private boolean senderFault; + private String code; + private String message; + + /** + * @see BatchError#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see BatchError#isSenderFault() + */ + public Builder senderFault(boolean senderFault) { + this.senderFault = senderFault; + return this; + } + + /** + * @see BatchError#getCode() + */ + public Builder code(String code) { + this.code = code; + return this; + } + + /** + * @see BatchError#getMessage() + */ + public Builder message(String message) { + this.message = message; + return this; + } + + public BatchError build() { + return new BatchError(id, senderFault, code, message); + } + + public Builder fromErrorEntry(BatchError in) { + return id(in.getId()).senderFault(in.isSenderFault()).code(in.getCode()).message(in.getMessage()); + } + } + + private final String id; + private final boolean senderFault; + private final String code; + private final String message; + + private BatchError(String id, boolean senderFault, String code, String message) { + this.id = checkNotNull(id, "id"); + this.senderFault = checkNotNull(senderFault, "senderFault of %s", id); + this.code = checkNotNull(code, "code of %s", id); + this.message = checkNotNull(message, "message of %s", id); + } + + /** + * The Id name that you assigned to the message. + */ + public String getId() { + return id; + } + + /** + * + */ + public boolean isSenderFault() { + return senderFault; + } + + /** + * A short string description of the error. + */ + public String getCode() { + return code; + } + + /** + * A description of the error. + */ + public String getMessage() { + return message; + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + BatchError that = BatchError.class.cast(obj); + return Objects.equal(this.id, that.id); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("senderFault", senderFault) + .add("message", message).add("code", code).toString(); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java b/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java new file mode 100644 index 0000000000..cbb2d4b496 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java @@ -0,0 +1,146 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class BatchResult extends ForwardingMap { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return BatchResult. builder().fromBatchResult(this); + } + + public static class Builder { + + private ImmutableMap.Builder results = ImmutableMap. builder(); + private ImmutableSet.Builder errors = ImmutableSet. builder(); + + /** + * @see BatchResult#getErrors() + */ + public Builder addError(BatchError error) { + this.errors.add(checkNotNull(error, "error")); + return this; + } + + /** + * @see BatchResult#getErrors() + */ + public Builder errors(Iterable errors) { + this.errors = ImmutableSet. builder().addAll(checkNotNull(errors, "errors")); + return this; + } + + /** + * @see BatchResult#get + */ + public Builder putAll(Map results) { + this.results.putAll(checkNotNull(results, "results")); + return this; + } + + /** + * @see BatchResult#get + */ + public Builder put(String name, V value) { + this.results.put(checkNotNull(name, "name"), checkNotNull(value, "value")); + return this; + } + + public BatchResult build() { + return new BatchResult(results.build(), errors.build()); + } + + public Builder fromBatchResult(BatchResult in) { + return putAll(in).errors(in.getErrors().values()); + } + } + + private final Map results; + private final Map errors; + + private BatchResult(Map results, Iterable errors) { + this.results = ImmutableMap.copyOf(checkNotNull(results, "results")); + this.errors = Maps.uniqueIndex(checkNotNull(errors, "errors"), new Function() { + @Override + public String apply(BatchError in) { + return in.getId(); + } + + }); + } + + @Override + protected Map delegate() { + return results; + } + + /** + * Errors indexed by requestor supplied id + */ + public Map getErrors() { + return errors; + } + + @Override + public int hashCode() { + return Objects.hashCode(results, errors); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + @SuppressWarnings("unchecked") + BatchResult that = BatchResult.class.cast(obj); + return Objects.equal(this.results, that.results) && Objects.equal(this.errors, that.errors); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("results", results).add("errors", errors).toString(); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java similarity index 52% rename from labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java rename to labs/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java index 63fdc8ce4a..fa4b96ae4a 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/MessageApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java @@ -16,23 +16,27 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs; +package org.jclouds.sqs.features; import java.net.URI; -import java.util.Set; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.sqs.domain.BatchResult; import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.domain.MessageIdAndMD5; import org.jclouds.sqs.options.ReceiveMessageOptions; import org.jclouds.sqs.options.SendMessageOptions; +import com.google.common.collect.Table; + /** * Provides access to SQS via their REST API. *

* - * @see SQSAsyncApi + * @see MessageAsyncApi * @author Adrian Cole */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @@ -72,6 +76,40 @@ public interface MessageApi { */ void delete(String receiptHandle); + /** + * Currently, you can send up to 10 {@link #delete} requests. + * + *

Example usage

+ * + *
+    * BatchResult results = api.delete(ImmutableMap.builder()
+    *                                  .put("id1", "handle1")
+    *                                  .put("id2", "handle2")
+    *                                  .build());
+    * 
+    * if (results.keySet().equals(ImmutableSet.of("id", "id2"))
+    *    // all ok
+    * else
+    *   results.getErrors();
+    * 
+ * + * @param idReceiptHandle + * id for correlating the result to receipt handle + * @return result that contains success or errors of the operation + * @see #delete(String) + */ + BatchResult delete(Map idReceiptHandle); + + /** + * Same as {@link #delete(Map)}, except that we generate numeric ids starting + * with {@code 1} + * + * @param receiptHandles + * receipt handles to delete + * @see #delete(Map) + */ + BatchResult delete(Iterable receiptHandles); + /** * The ChangeMessageVisibility action changes the visibility timeout of a * specified message in a queue to a new value. The maximum allowed timeout @@ -114,6 +152,77 @@ public interface MessageApi { */ void changeVisibility(String receiptHandle, int visibilityTimeout); + /** + * Currently, you can send up to 10 {@link #changeVisibility} requests. + * + * action.

Example usage

+ * + *
+    * BatchResult results = api.changeVisibility(ImmutableTable.builder()
+    *                                  .put("id1", "handle1", 45)
+    *                                  .put("id2", "handle2", 10)
+    *                                  .build());
+    * 
+    * if (results.keySet().equals(ImmutableSet.of("id", "id2"))
+    *    // all ok
+    * else
+    *   results.getErrors();
+    * 
+ * + * @param idReceiptHandleVisibilityTimeout + * id for correlating the result, receipt handle, and visibility + * timeout + * @return result that contains success or errors of the operation + * @see #changeVisibility(String, int) + */ + BatchResult changeVisibility(Table idReceiptHandleVisibilityTimeout); + + /** + * Same as {@link #changeVisibility(Table)}, except that we generate numeric + * ids starting with {@code 1} + * + * @param receiptHandleVisibilityTimeout + * receipt handle to visibility timeout + * @see #changeVisibility(Table) + */ + BatchResult changeVisibility(Map receiptHandleVisibilityTimeout); + + /** + * Currently, you can send up to 10 {@link #changeVisibility} requests. + * + * action.

Example usage

+ * + *
+    * BatchResult results = api.changeVisibility(ImmutableMap.builder()
+    *                                  .put("id1", "handle1")
+    *                                  .put("id2", "handle2")
+    *                                  .build(), 45);
+    * 
+    * if (results.keySet().equals(ImmutableSet.of("id", "id2"))
+    *    // all ok
+    * else
+    *   results.getErrors();
+    * 
+ * + * @param idReceiptHandle + * id for correlating the result to receipt handle + * @param visibilityTimeout + * The new value for the message's visibility timeout (in seconds). + * @return result that contains success or errors of the operation + * @see #changeVisibility(String, int) + */ + BatchResult changeVisibility(Map idReceiptHandle, int visibilityTimeout); + + /** + * Same as {@link #changeVisibility(Map, int)}, except that we generate + * numeric ids starting with {@code 1} + * + * @param receiptHandles + * receipt handles to change visibility + * @see #changeVisibility(Map, int) + */ + BatchResult changeVisibility(Iterable receiptHandles, int visibilityTimeout); + /** * The SendMessage action delivers a message to the specified queue. The * maximum allowed message size is 64 KB. @@ -138,6 +247,107 @@ public interface MessageApi { */ MessageIdAndMD5 send(String message); + /** + * Same as {@link #send(Map)} except you can set a delay for each message in + * the request. + * + *

Example usage

+ * + *
+    * BatchResult results = api.sendWithDelays(ImmutableTable.builder()
+    *                                  .put("id1", "test message one", 1)
+    *                                  .put("id2", "test message two", 10)
+    *                                  .build());
+    * 
+    * if (results.keySet().equals(ImmutableSet.of("id", "id2"))
+    *    // all ok
+    * else
+    *   results.getErrors();
+    * 
+ * + * @param idMessageBodyDelaySeconds + * id for correlating the result, message body, and delay seconds + * + * @return result that contains success or errors of the operation + * @see #send(String, SendMessageOptions) + */ + BatchResult sendWithDelays(Table idMessageBodyDelaySeconds); + + /** + * Same as {@link #sendWithDelays(Table)}, except that we generate numeric + * ids starting with {@code 1} + * + * @param messageBodyDelaySeconds + * message body to the delay desired + * @see #sendWithDelays(Table) + */ + BatchResult sendWithDelays(Map messageBodyDelaySeconds); + + /** + * Same as {@link #send(Map)} except you set a delay for all messages in the + * request + * + * @param delaySeconds + * The number of seconds to delay a specific message. Messages with + * a positive DelaySeconds value become available for processing + * after the delay time is finished. + * + * @see #send(String, SendMessageOptions) + */ + BatchResult sendWithDelay(Map idMessageBody, int delaySeconds); + + /** + * Same as {@link #sendWithDelay(Map, int)}, except that we generate numeric + * ids starting with {@code 1} + * + * @param messageBodies + * message bodies to send + * @see #sendWithDelay(Map, int) + */ + BatchResult sendWithDelay(Iterable messageBodies, int delaySeconds); + + /** + * The SendMessageBatch action delivers up to ten messages to the specified + * queue. The maximum allowed individual message size is 64 KiB (65,536 + * bytes). + * + * The maximum total payload size (i.e., the sum of all a batch's individual + * message lengths) is also 64 KiB (65,536 bytes). + * + * Currently, you can send up to 10 {@link #send} requests. + * + * action.

Example usage

+ * + *
+    * BatchResult results = api.send(ImmutableMap.builder()
+    *                                  .put("id1", "test message one")
+    *                                  .put("id2", "test message two")
+    *                                  .build());
+    * 
+    * if (results.keySet().equals(ImmutableSet.of("id", "id2"))
+    *    // all ok
+    * else
+    *   results.getErrors();
+    * 
+ * + * @param idMessageBody + * id for correlating the result to message body + * + * @return result that contains success or errors of the operation + * @see #send(String) + */ + BatchResult send(Map idMessageBody); + + /** + * Same as {@link #send(Map)}, except that we generate numeric ids starting + * with {@code 1} + * + * @param messageBodies + * message bodies to send + * @see #send(Map) + */ + BatchResult send(Iterable messageBodies); + /** * same as {@link #sendMessage(URI, String)} except you can control options * such as delay seconds. @@ -192,7 +402,7 @@ public interface MessageApi { * maximum messages to receive, current limit is 10 * @see #receive(URI) */ - Set receive(int max); + List receive(int max); /** * same as {@link #receive(URI, int)} except you can provide options like @@ -205,5 +415,5 @@ public interface MessageApi { * options such as VisibilityTimeout * @see #receive(URI, int) */ - Set receive(int max, ReceiveMessageOptions options); + List receive(int max, ReceiveMessageOptions options); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java new file mode 100644 index 0000000000..6eb9db388d --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java @@ -0,0 +1,275 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static org.jclouds.sqs.reference.SQSParameters.ACTION; +import static org.jclouds.sqs.reference.SQSParameters.VERSION; + +import java.util.List; +import java.util.Map; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.Constants; +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.sqs.binders.BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams; +import org.jclouds.sqs.binders.BindDeleteMessageBatchRequestEntryToIndexedFormParams; +import org.jclouds.sqs.binders.BindSendMessageBatchRequestEntryToIndexedFormParams; +import org.jclouds.sqs.binders.BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams; +import org.jclouds.sqs.domain.BatchResult; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.options.ReceiveMessageOptions; +import org.jclouds.sqs.options.SendMessageOptions; +import org.jclouds.sqs.xml.ChangeMessageVisibilityBatchResponseHandler; +import org.jclouds.sqs.xml.DeleteMessageBatchResponseHandler; +import org.jclouds.sqs.xml.MessageHandler; +import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; +import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; +import org.jclouds.sqs.xml.SendMessageBatchResponseHandler; + +import com.google.common.collect.Table; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to SQS via their REST API. + *

+ * + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}") +@VirtualHost +public interface MessageAsyncApi { + + /** + * @see MessageApi#delete(String) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteMessage") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture delete(@FormParam("ReceiptHandle") String receiptHandle); + + /** + * @see MessageApi#delete(Map) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteMessageBatch") + @XMLResponseParser(DeleteMessageBatchResponseHandler.class) + ListenableFuture> delete( + @BinderParam(BindDeleteMessageBatchRequestEntryToIndexedFormParams.class) Map idReceiptHandle); + + /** + * @see MessageApi#delete(Iterable) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteMessageBatch") + @XMLResponseParser(DeleteMessageBatchResponseHandler.class) + ListenableFuture> delete( + @BinderParam(BindDeleteMessageBatchRequestEntryToIndexedFormParams.class) Iterable receiptHandles); + + /** + * @see MessageApi#changeVisibility(String, int) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibility") + ListenableFuture changeVisibility(@FormParam("ReceiptHandle") String receiptHandle, + @FormParam("VisibilityTimeout") int visibilityTimeout); + + /** + * @see MessageApi#changeVisibility(Table) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch") + @XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class) + ListenableFuture> changeVisibility( + @BinderParam(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) Table idReceiptHandleVisibilityTimeout); + + /** + * @see MessageApi#changeVisibility(Map) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch") + @XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class) + ListenableFuture> changeVisibility( + @BinderParam(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) Map receiptHandleVisibilityTimeout); + + /** + * @see MessageApi#changeVisibility(Map, int) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch") + @MapBinder(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) + @XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class) + ListenableFuture> changeVisibility( + @PayloadParam("idReceiptHandle") Map idReceiptHandle, + @PayloadParam("visibilityTimeout") int visibilityTimeout); + + /** + * @see MessageApi#changeVisibility(Iterable, int) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch") + @MapBinder(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) + @XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class) + ListenableFuture> changeVisibility( + @PayloadParam("receiptHandles") Iterable receiptHandles, + @PayloadParam("visibilityTimeout") int visibilityTimeout); + + /** + * @see MessageApi#send(String) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessage") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + ListenableFuture send(@FormParam("MessageBody") String message); + + /** + * @see MessageApi#send(String, SendMessageOptions) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessage") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + ListenableFuture send(@FormParam("MessageBody") String message, SendMessageOptions options); + + /** + * @see MessageApi#sendWithDelays(Table) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessageBatch") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + @XMLResponseParser(SendMessageBatchResponseHandler.class) + ListenableFuture> sendWithDelays( + @BinderParam(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) Table idMessageBodyDelaySeconds); + + /** + * @see MessageApi#sendWithDelays(Map) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessageBatch") + @ResponseParser(RegexMessageIdAndMD5Handler.class) + @XMLResponseParser(SendMessageBatchResponseHandler.class) + ListenableFuture> sendWithDelays( + @BinderParam(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) Map messageBodyDelaySeconds); + + /** + * @see MessageApi#sendWithDelay(Map, int) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessageBatch") + @MapBinder(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) + @XMLResponseParser(SendMessageBatchResponseHandler.class) + ListenableFuture> sendWithDelay( + @PayloadParam("idMessageBody") Map idMessageBody, + @PayloadParam("delaySeconds") int delaySeconds); + + /** + * @see MessageApi#sendWithDelay(Iterable, int) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessageBatch") + @MapBinder(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) + @XMLResponseParser(SendMessageBatchResponseHandler.class) + ListenableFuture> sendWithDelay( + @PayloadParam("messageBodies") Iterable messageBodies, @PayloadParam("delaySeconds") int delaySeconds); + + /** + * @see MessageApi#send(Map) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessageBatch") + @XMLResponseParser(SendMessageBatchResponseHandler.class) + ListenableFuture> send( + @BinderParam(BindSendMessageBatchRequestEntryToIndexedFormParams.class) Map idMessageBody); + + /** + * @see MessageApi#send(Iterable) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "SendMessageBatch") + @XMLResponseParser(SendMessageBatchResponseHandler.class) + ListenableFuture> send( + @BinderParam(BindSendMessageBatchRequestEntryToIndexedFormParams.class) Iterable messageBodies); + + /** + * @see MessageApi#receive() + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(MessageHandler.class) + ListenableFuture receive(); + + /** + * @see MessageApi#receive(ReceiveMessageOptions) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(MessageHandler.class) + ListenableFuture receive(ReceiveMessageOptions options); + + /** + * @see MessageApi#receive(int) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(ReceiveMessageResponseHandler.class) + ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max); + + /** + * @see MessageApi#receive(int, ReceiveMessageOptions) + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "ReceiveMessage") + @XMLResponseParser(ReceiveMessageResponseHandler.class) + ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max, + ReceiveMessageOptions options); + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java similarity index 98% rename from labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java rename to labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java index 71a2b4852b..2f2498e1a3 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/PermissionApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs; +package org.jclouds.sqs.features; import java.util.concurrent.TimeUnit; @@ -27,7 +27,7 @@ import org.jclouds.sqs.domain.Action; * Provides access to SQS via their REST API. *

* - * @see SQSAsyncApi + * @see PermissionAsyncApi * @author Adrian Cole */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java similarity index 94% rename from labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java rename to labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java index 9eccd9b228..54902bd0ef 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/PermissionAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs; +package org.jclouds.sqs.features; import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.jclouds.sqs.reference.SQSParameters.VERSION; @@ -46,7 +46,7 @@ import com.google.common.util.concurrent.ListenableFuture; public interface PermissionAsyncApi { /** - * @see SQSApi#addPermissionToAccount + * @see PermissionApi#addPermissionToAccount */ @POST @Path("/") @@ -55,7 +55,7 @@ public interface PermissionAsyncApi { @FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId); /** - * @see SQSApi#remove + * @see PermissionApi#remove */ @POST @Path("/") diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java similarity index 99% rename from labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java rename to labs/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java index 0492b819a0..ccd6dbec67 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/QueueApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs; +package org.jclouds.sqs.features; import java.net.URI; import java.util.Map; @@ -32,7 +32,7 @@ import org.jclouds.sqs.options.ListQueuesOptions; * Provides access to SQS via their REST API. *

* - * @see SQSAsyncApi + * @see QueueAsyncApi * @author Adrian Cole */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java b/labs/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java similarity index 91% rename from labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java rename to labs/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java index 4621b90dad..251cc9dec1 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/QueueAsyncApi.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.sqs; +package org.jclouds.sqs.features; import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.jclouds.sqs.reference.SQSParameters.VERSION; @@ -41,6 +41,7 @@ import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams; import org.jclouds.sqs.domain.QueueAttributes; import org.jclouds.sqs.functions.MapToQueueAttributes; @@ -65,7 +66,7 @@ import com.google.common.util.concurrent.ListenableFuture; public interface QueueAsyncApi { /** - * @see SQSApi#list + * @see QueueApi#list */ @POST @Path("/") @@ -74,7 +75,7 @@ public interface QueueAsyncApi { ListenableFuture> list(); /** - * @see SQSApi#list + * @see QueueApi#list(ListQueuesOptions) */ @POST @Path("/") @@ -83,7 +84,7 @@ public interface QueueAsyncApi { ListenableFuture> list(ListQueuesOptions options); /** - * @see SQSApi#create + * @see QueueApi#create */ @POST @Path("/") @@ -92,7 +93,7 @@ public interface QueueAsyncApi { ListenableFuture create(@FormParam("QueueName") String queueName); /** - * @see SQSApi#create + * @see QueueApi#create */ @POST @Path("/") @@ -101,15 +102,16 @@ public interface QueueAsyncApi { ListenableFuture create(@FormParam("QueueName") String queueName, CreateQueueOptions options); /** - * @see SQSApi#delete + * @see QueueApi#delete */ @POST @Path("/") @FormParams(keys = ACTION, values = "DeleteQueue") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) ListenableFuture delete(@EndpointParam URI queue); /** - * @see SQSApi#getAttributes(URI) + * @see QueueApi#getAttributes(URI) */ @POST @Path("/") @@ -120,7 +122,7 @@ public interface QueueAsyncApi { ListenableFuture getAttributes(@EndpointParam URI queue); /** - * @see SQSApi#getAttributes(URI, Iterable) + * @see QueueApi#getAttributes(URI, Iterable) */ @POST @Path("/") @@ -130,7 +132,7 @@ public interface QueueAsyncApi { @BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable attributeNames); /** - * @see SQSApi#getAttribute + * @see QueueApi#getAttribute */ @POST @Path("/") @@ -139,7 +141,7 @@ public interface QueueAsyncApi { ListenableFuture getAttribute(@EndpointParam URI queue, @FormParam("AttributeName.1") String attributeName); /** - * @see SQSApi#setAttribute + * @see QueueApi#setAttribute */ @POST @Path("/") diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java new file mode 100644 index 0000000000..24889e29e6 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.sqs.domain.BatchError; + +/** + * @see + * + * @author Adrian Cole + */ +public class BatchErrorHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private BatchError.Builder builder = BatchError.builder(); + + @Override + public BatchError getResult() { + try { + return builder.build(); + } catch (NullPointerException e) { + return null; + } finally { + builder = BatchError.builder(); + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals("Id")) { + builder.id(currentOrNull(currentText)); + } else if (qName.equals("SenderFault")) { + builder.senderFault(Boolean.parseBoolean(currentOrNull(currentText))); + } else if (qName.equals("Code")) { + builder.code(currentOrNull(currentText)); + } else if (qName.equals("Message")) { + builder.message(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java new file mode 100644 index 0000000000..07bd366d42 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java @@ -0,0 +1,106 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult; +import org.jclouds.sqs.domain.BatchError; +import org.jclouds.sqs.domain.BatchResult; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class BatchResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { + + private final String resultElement; + private final ParseSax.HandlerForGeneratedRequestWithResult> resultHandler; + private final BatchErrorHandler errorHandler; + + private ImmutableMap.Builder results = ImmutableMap. builder(); + private Builder errors = ImmutableSet. builder(); + + private boolean inResult; + private boolean inError; + + protected BatchResponseHandler(String resultElement, HandlerForGeneratedRequestWithResult> resultHandler, + BatchErrorHandler errorHandler) { + this.resultElement = checkNotNull(resultElement, "resultElement");; + this.resultHandler = checkNotNull(resultHandler, "resultHandler");; + this.errorHandler = checkNotNull(errorHandler, "errorHandler");; + } + + @Override + public BatchResult getResult() { + return BatchResult. builder().putAll(results.build()).errors(errors.build()) + .build(); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (qName.equals(resultElement)) { + inResult = true; + } else if (qName.equals("BatchResultErrorEntry")) { + inError = true; + } + if (inResult) { + resultHandler.startElement(url, name, qName, attributes); + } else if (inError) { + errorHandler.startElement(url, name, qName, attributes); + } + } + + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (qName.equals(resultElement)) { + results.put(resultHandler.getResult()); + inResult = false; + } else if (qName.equals("BatchResultErrorEntry")) { + errors.add(errorHandler.getResult()); + inError = false; + } else if (inResult) { + resultHandler.endElement(uri, name, qName); + } else if (inError) { + errorHandler.endElement(uri, name, qName); + } + } + + @Override + public void characters(char ch[], int start, int length) throws SAXException { + if (inResult) { + resultHandler.characters(ch, start, length); + } else if (inError) { + errorHandler.characters(ch, start, length); + } + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java new file mode 100644 index 0000000000..819f67158f --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import javax.inject.Inject; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class ChangeMessageVisibilityBatchResponseHandler extends BatchResponseHandler { + @Inject + protected ChangeMessageVisibilityBatchResponseHandler(IdHandler resultHandler, BatchErrorHandler errorHandler) { + super("ChangeMessageVisibilityBatchResultEntry", resultHandler, errorHandler); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java new file mode 100644 index 0000000000..1933851b15 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import javax.inject.Inject; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class DeleteMessageBatchResponseHandler extends BatchResponseHandler { + + @Inject + protected DeleteMessageBatchResponseHandler(IdHandler resultHandler, BatchErrorHandler errorHandler) { + super("DeleteMessageBatchResultEntry", resultHandler, errorHandler); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java new file mode 100644 index 0000000000..35d9f42191 --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import java.util.Map; + +import javax.inject.Inject; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + +/** + * @see + * + * @author Adrian Cole + */ +public class IdHandler extends TextFromSingleElementHandler> { + @Inject + protected IdHandler(String elementName) { + super("Id"); + } + + @Override + public Map.Entry apply(String in) { + return Iterables.getOnlyElement(ImmutableMap.of(in, in).entrySet()); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java index 7976476acc..76c5551add 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java @@ -20,15 +20,15 @@ package org.jclouds.sqs.xml; import static org.jclouds.util.SaxUtils.equalsOrSuffix; -import java.util.Set; +import java.util.List; import org.jclouds.http.functions.ParseSax; import org.jclouds.sqs.domain.Message; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; import com.google.inject.Inject; /** @@ -38,11 +38,11 @@ import com.google.inject.Inject; * * @author Adrian Cole */ -public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { +public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { private final MessageHandler messageHandler; - private Builder messages = ImmutableSet. builder(); + private Builder messages = ImmutableList. builder(); private boolean inMessages; @@ -52,7 +52,7 @@ public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedR } @Override - public Set getResult() { + public List getResult() { return messages.build(); } diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java new file mode 100644 index 0000000000..bb7780e29b --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java @@ -0,0 +1,40 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import javax.inject.Inject; + +import org.jclouds.sqs.domain.MessageIdAndMD5; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class SendMessageBatchResponseHandler extends BatchResponseHandler { + + @Inject + protected SendMessageBatchResponseHandler(SendMessageBatchResultEntryHandler resultHandler, + BatchErrorHandler errorHandler) { + super("SendMessageBatchResultEntry", resultHandler, errorHandler); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java new file mode 100644 index 0000000000..0474e2e75f --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; + +import java.util.Map; +import java.util.Map.Entry; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.sqs.domain.MessageIdAndMD5; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import com.google.common.hash.HashCodes; + +/** + * @see + * + * @author Adrian Cole + */ +public class SendMessageBatchResultEntryHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + + private StringBuilder currentText = new StringBuilder(); + private MessageIdAndMD5.Builder builder = MessageIdAndMD5.builder(); + private String id; + + @Override + public Entry getResult() { + try { + return Iterables.getOnlyElement(ImmutableMap.of(id, builder.build()).entrySet()); + } finally { + builder = MessageIdAndMD5.builder(); + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals("Id")) { + this.id = currentOrNull(currentText); + } else if (qName.equals("MessageId")) { + builder.id(currentOrNull(currentText)); + } else if (qName.equals("MD5OfMessageBody")) { + builder.md5(HashCodes.fromBytes(CryptoStreams.hex(currentOrNull(currentText)))); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java new file mode 100644 index 0000000000..cfde3d14df --- /dev/null +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java @@ -0,0 +1,63 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.xml; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.util.SaxUtils.currentOrNull; + +import org.jclouds.http.functions.ParseSax; + +import com.google.common.base.Function; + +/** + * looks for a single value in the xml + * + * @author Adrian Cole + */ +public abstract class TextFromSingleElementHandler extends ParseSax.HandlerForGeneratedRequestWithResult + implements Function { + private final String elementName; + + protected TextFromSingleElementHandler(String elementName) { + this.elementName = checkNotNull(elementName, "elementName"); + } + + private StringBuilder currentText = new StringBuilder(); + private String text; + + @Override + public V getResult() { + return apply(text); + } + + // this could be done with regex, if we had an unescaper + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals(elementName)) { + text = currentOrNull(currentText); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java index b30c622f27..c3764d3a83 100644 --- a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java +++ b/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java @@ -18,9 +18,7 @@ */ package org.jclouds.sqs.xml; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.http.functions.ParseSax; +import javax.inject.Inject; /** * @see { - - private StringBuilder currentText = new StringBuilder(); - private String value; - - @Override - public String getResult() { - return value; - } - - // this could be done with regex, if we had an unescaper - @Override - public void endElement(String uri, String name, String qName) { - if (qName.equals("Value")) { - value = currentOrNull(currentText); - } - currentText = new StringBuilder(); +public class ValueHandler extends TextFromSingleElementHandler { + @Inject + protected ValueHandler(String elementName) { + super("Value"); } @Override - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); + public String apply(String in) { + return in; } } diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java deleted file mode 100644 index 24567740b8..0000000000 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiExpectTest.java +++ /dev/null @@ -1,360 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.sqs.domain.Action; -import org.jclouds.sqs.functions.MapToQueueAttributesTest; -import org.jclouds.sqs.internal.BaseSQSApiExpectTest; -import org.jclouds.sqs.parse.CreateQueueResponseTest; -import org.jclouds.sqs.parse.GetQueueAttributesResponseTest; -import org.jclouds.sqs.parse.ReceiveMessageResponseTest; -import org.jclouds.sqs.parse.SendMessageResponseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "SQSApiExpectTest") -public class SQSApiExpectTest extends BaseSQSApiExpectTest { - - URI queue = URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"); - - public HttpRequest createQueue = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "CreateQueue") - .addFormParam("QueueName", "queueName") - .addFormParam("Signature", "I7tmwiCzJ9cvw79pmlz1rOILh2C2ZV6OpLk23JGx6AU%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testCreateQueueWhenResponseIs2xx() throws Exception { - - HttpResponse createQueueResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/create_queue.xml", "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(createQueue, createQueueResponse); - - assertEquals(apiWhenExist.getQueueApi().create("queueName").toString(), new CreateQueueResponseTest().expected() - .toString()); - } - - public HttpRequest sendMessage = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "SendMessage") - .addFormParam("MessageBody", "hardyharhar") - .addFormParam("Signature", "PVzszzgIcT1xt9%2BEzGzWB2Bt8zDadBc48HsgF89AoJE%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testSendMessageWhenResponseIs2xx() throws Exception { - - HttpResponse sendMessageResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/send_message.xml", "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(sendMessage, sendMessageResponse); - - assertEquals(apiWhenExist.getMessageApiForQueue(queue).send("hardyharhar").toString(), - new SendMessageResponseTest().expected().toString()); - } - - - public HttpRequest receiveMessage = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "ReceiveMessage") - .addFormParam("Signature", "UURXsAjggoaz5P1h2EFswRd8Ji9euHmXhHvrAmIqM1E%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testReceiveMessageWhenResponseIs2xx() throws Exception { - - HttpResponse receiveMessageResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/messages.xml", "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(receiveMessage, receiveMessageResponse); - - assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive().toString(), - Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString()); - } - - - public HttpRequest receiveMessages = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "ReceiveMessage") - .addFormParam("MaxNumberOfMessages", "10") - .addFormParam("Signature", "pZ9B4%2BTBvQA4n0joP4t8ue5x0xmKMd9prpVLVoT%2F7qU%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testReceiveMessagesWhenResponseIs2xx() throws Exception { - - HttpResponse receiveMessagesResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/messages.xml", "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(receiveMessages, receiveMessagesResponse); - - assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive(10).toString(), new ReceiveMessageResponseTest() - .expected().toString()); - } - - public HttpRequest deleteMessage = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "DeleteMessage") - .addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe") - .addFormParam("Signature", "9%2FkuCc2i78gMsmul%2BRsOPcdQ1OLUKrItqgGIRRBJb8M%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testDeleteMessageWhenResponseIs2xx() throws Exception { - - HttpResponse deleteMessageResponse = HttpResponse.builder() - .statusCode(200) - .payload( - payloadFromStringWithContentType( - "b5293cb5-d306-4a17-9048-b263635abe42", - "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(deleteMessage, deleteMessageResponse); - - apiWhenExist.getMessageApiForQueue(queue).delete("eXJYhj5rDr9cAe"); - } - - - public HttpRequest changeMessageVisibility = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "ChangeMessageVisibility") - .addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe") - .addFormParam("Signature", "gvmSHleGLkmszYU6aURCBImuec2k0O3pg3tAYhDvkNs%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("VisibilityTimeout", "10") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testChangeMessageVisibilityWhenResponseIs2xx() throws Exception { - - HttpResponse changeMessageVisibilityResponse = HttpResponse.builder() - .statusCode(200) - .payload( - payloadFromStringWithContentType( - "b5293cb5-d306-4a17-9048-b263635abe42", - "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibility, changeMessageVisibilityResponse); - - apiWhenExist.getMessageApiForQueue(queue).changeVisibility("eXJYhj5rDr9cAe", 10); - } - - public HttpRequest getQueueAttribute = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "GetQueueAttributes") - .addFormParam("AttributeName.1", "VisibilityTimeout") - .addFormParam("Signature", "AfydayBBaIk4UGikHHY1CFNmOOAcTnogpFWydZyNass%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testGetQueueAttributeWhenResponseIs2xx() throws Exception { - - HttpResponse getQueueAttributeResponse = HttpResponse.builder() - .statusCode(200) - .payload( - payloadFromStringWithContentType( - "VisibilityTimeout30", - "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(getQueueAttribute, getQueueAttributeResponse); - - assertEquals(apiWhenExist.getQueueApi().getAttribute(queue, "VisibilityTimeout"), "30"); - } - - public HttpRequest getQueueAttributes = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "GetQueueAttributes") - .addFormParam("AttributeName.1", "All") - .addFormParam("Signature", "welFLn0TV6JlH6s6s60XZTJeJfFXGiXN4qNPrBx7aHc%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testGetQueueAttributesWhenResponseIs2xx() throws Exception { - - HttpResponse getQueueAttributesResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/attributes.xml", "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(getQueueAttributes, getQueueAttributesResponse); - - assertEquals(apiWhenExist.getQueueApi().getAttributes(queue).toString(), new MapToQueueAttributesTest() - .expected().toString()); - } - - public HttpRequest getQueueAttributesSubset = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "GetQueueAttributes") - .addFormParam("AttributeName.1", "VisibilityTimeout") - .addFormParam("AttributeName.2", "DelaySeconds") - .addFormParam("Signature", "9KaiOOWWyFPTVMOnyHA3ZoXbPBPSD4AZ4q460UNMfDs%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testGetQueueAttributesSubsetWhenResponseIs2xx() throws Exception { - - HttpResponse getQueueAttributesSubsetResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/attributes.xml", "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(getQueueAttributesSubset, getQueueAttributesSubsetResponse); - - assertEquals(apiWhenExist.getQueueApi() - .getAttributes(queue, ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(), - new GetQueueAttributesResponseTest().expected().toString()); - } - - public HttpRequest setQueueAttribute = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "SetQueueAttributes") - .addFormParam("Attribute.Name", "MaximumMessageSize") - .addFormParam("Attribute.Value", "1") - .addFormParam("Signature", "ktBkQ3c%2FrwGcBSec0fkckfo73xmcoTuub5fxudM1qh0%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testSetQueueAttributeWhenResponseIs2xx() throws Exception { - - HttpResponse setQueueAttributeResponse = HttpResponse.builder() - .statusCode(200) - .payload( - payloadFromStringWithContentType( - "b5293cb5-d306-4a17-9048-b263635abe42", - "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(setQueueAttribute, setQueueAttributeResponse); - - apiWhenExist.getQueueApi().setAttribute(queue, "MaximumMessageSize", "1"); - } - - public HttpRequest addPermission = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "AddPermission") - .addFormParam("ActionName.1", "ReceiveMessage") - .addFormParam("AWSAccountId.1", "125074342641") - .addFormParam("Label", "testLabel") - .addFormParam("Signature", "J9sV4q1rJ7dWYJDQp9JxsfEKNXQhpQBYIwBYi1IeXV0%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testAddPermissionWhenResponseIs2xx() throws Exception { - - HttpResponse addPermissionResponse = HttpResponse.builder() - .statusCode(200) - .payload( - payloadFromStringWithContentType( - "b5293cb5-d306-4a17-9048-b263635abe42", - "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(addPermission, addPermissionResponse); - - apiWhenExist.getPermissionApiForQueue(queue).addPermissionToAccount("testLabel", Action.RECEIVE_MESSAGE, "125074342641"); - } - - public HttpRequest removePermission = HttpRequest.builder() - .method("POST") - .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") - .addHeader("Host", "sqs.us-east-1.amazonaws.com") - .addFormParam("Action", "RemovePermission") - .addFormParam("Label", "testLabel") - .addFormParam("Signature", "VOA0L1uRVKQDQL1Klt0cYUajGoxN4Ur%2B7ISQ2I4RpRs%3D") - .addFormParam("SignatureMethod", "HmacSHA256") - .addFormParam("SignatureVersion", "2") - .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") - .addFormParam("Version", "2011-10-01") - .addFormParam("AWSAccessKeyId", "identity").build(); - - public void testRemovePermissionWhenResponseIs2xx() throws Exception { - - HttpResponse removePermissionResponse = HttpResponse.builder() - .statusCode(200) - .payload( - payloadFromStringWithContentType( - "b5293cb5-d306-4a17-9048-b263635abe42", - "text/xml")).build(); - - SQSApi apiWhenExist = requestSendsResponse(removePermission, removePermissionResponse); - - apiWhenExist.getPermissionApiForQueue(queue).remove("testLabel"); - } -} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java deleted file mode 100644 index 200c89b0d2..0000000000 --- a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiLiveTest.java +++ /dev/null @@ -1,229 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.sqs; - -import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.getLast; -import static org.jclouds.concurrent.MoreExecutors.sameThreadExecutor; -import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint; -import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; -import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; -import static org.jclouds.sqs.reference.SQSParameters.ACTION; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import java.net.URI; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.jclouds.ContextBuilder; -import org.jclouds.concurrent.Timeout; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.rest.annotations.FormParams; -import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.sqs.domain.Action; -import org.jclouds.sqs.domain.QueueAttributes; -import org.jclouds.sqs.internal.BaseSQSApiLiveTest; -import org.jclouds.sqs.xml.ValueHandler; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import com.google.common.base.Charsets; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import com.google.common.hash.HashCode; -import com.google.common.hash.Hashing; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.inject.Module; - -/** - * Tests behavior of {@code SQSApi} - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true, testName = "SQSApiLiveTest") -public class SQSApiLiveTest extends BaseSQSApiLiveTest { - - private Set queues = Sets.newHashSet(); - - @Test - protected void testListQueues() throws InterruptedException { - listQueuesInRegion(null); - } - - protected void listQueuesInRegion(String region) throws InterruptedException { - Set allResults = api().getQueueApiForRegion(region).list(); - assertNotNull(allResults); - if (allResults.size() >= 1) { - URI queue = getLast(allResults); - assertQueueInList(region, queue); - } - } - - public static final String PREFIX = System.getProperty("user.name") + "-sqs"; - - @Test - protected void testCanRecreateQueueGracefully() throws InterruptedException { - recreateQueueInRegion(PREFIX + "1", null); - recreateQueueInRegion(PREFIX + "1", null); - } - - public String recreateQueueInRegion(String queueName, String region) throws InterruptedException { - QueueApi api = api().getQueueApiForRegion(region); - Set result = api.list(queuePrefix(queueName)); - if (result.size() >= 1) { - api.delete(getLast(result)); - } - URI queue = api.create(queueName); - assertQueueInList(region, queue); - queues.add(queue); - return queueName; - } - - @Test(dependsOnMethods = "testCanRecreateQueueGracefully") - protected void testGetQueueAttributes() { - for (URI queue : queues) { - Map attributes = api().getQueueApi().getAttributes(queue, ImmutableSet.of("All")); - assertEquals(api().getQueueApi().getAttributes(queue, attributes.keySet()), attributes); - } - } - - String message = "hardyharhar"; - HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); - - @Timeout(duration = 5, timeUnit = TimeUnit.SECONDS) - static interface AnonymousAttributesApi { - String getQueueArn(); - } - - static interface AnonymousAttributesAsyncApi { - @POST - @Path("/") - @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "QueueArn" }) - @XMLResponseParser(ValueHandler.class) - ListenableFuture getQueueArn(); - } - - @Test(dependsOnMethods = "testGetQueueAttributes") - protected void testAddAnonymousPermission() throws InterruptedException { - for (URI queue : queues) { - QueueAttributes attributes = api().getQueueApi().getAttributes(queue); - assertNoPermissions(queue); - - String accountToAuthorize = getAccountToAuthorize(queue); - api().getPermissionApiForQueue(queue).addPermissionToAccount("fubar", Action.GET_QUEUE_ATTRIBUTES, - accountToAuthorize); - - String policyForAuthorizationByAccount = assertPolicyPresent(queue); - - String policyForAnonymous = policyForAuthorizationByAccount.replace("\"" + accountToAuthorize + "\"", "\"*\""); - api().getQueueApi().setAttribute(queue, "Policy", policyForAnonymous); - - assertEquals(getAnonymousAttributesApi(queue).getQueueArn(), attributes.getQueueArn()); - } - } - - protected String getAccountToAuthorize(URI queue) { - return get(Splitter.on('/').split(queue.getPath()), 1); - } - - @Test(dependsOnMethods = "testAddAnonymousPermission") - protected void testRemovePermission() throws InterruptedException { - for (URI queue : queues) { - api().getPermissionApiForQueue(queue).remove("fubar"); - assertNoPermissions(queue); - } - } - - @Test(dependsOnMethods = "testGetQueueAttributes") - protected void testSetQueueAttribute() { - for (URI queue : queues) { - api().getQueueApi().setAttribute(queue, "MaximumMessageSize", "1024"); - assertEquals(api().getQueueApi().getAttributes(queue).getMaximumMessageSize(), 1024); - } - } - - @Test(dependsOnMethods = "testGetQueueAttributes") - protected void testSendMessage() { - for (URI queue : queues) { - assertEquals(api().getMessageApiForQueue(queue).send(message).getMD5(), md5); - } - } - - @Test(dependsOnMethods = "testSendMessage") - protected void testReceiveMessageWithoutHidingMessage() { - for (URI queue : queues) { - assertEquals(api().getMessageApiForQueue(queue).receive(attribute("All").visibilityTimeout(0)).getMD5(), md5); - } - } - - String receiptHandle; - - @Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage") - protected void testChangeMessageVisibility() { - for (URI queue : queues) { - MessageApi api = api().getMessageApiForQueue(queue); - // start hiding it at 5 seconds - receiptHandle = api.receive(attribute("None").visibilityTimeout(5)).getReceiptHandle(); - // hidden message, so we can't see it - assertNull(api.receive()); - // this should unhide it - api.changeVisibility(receiptHandle, 0); - // so we can see it again - assertEquals(api.receive(attribute("All").visibilityTimeout(0)).getMD5(), md5); - } - } - - @Test(dependsOnMethods = "testChangeMessageVisibility") - protected void testDeleteMessage() throws InterruptedException { - for (URI queue : queues) { - api().getMessageApiForQueue(queue).delete(receiptHandle); - assertNoMessages(queue); - } - } - - @Override - @AfterClass(groups = "live") - protected void tearDownContext() { - for (URI queue : queues) { - api().getQueueApi().delete(queue); - } - super.tearDownContext(); - } - - protected SQSApi api() { - return context.getApi(); - } - - private AnonymousAttributesApi getAnonymousAttributesApi(URI queue) { - return ContextBuilder - .newBuilder( - forClientMappedToAsyncClientOnEndpoint(AnonymousAttributesApi.class, - AnonymousAttributesAsyncApi.class, queue.toASCIIString())) - .modules(ImmutableSet. of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) - .buildInjector().getInstance(AnonymousAttributesApi.class); - } - -} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java new file mode 100644 index 0000000000..7bb8376b7e --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java @@ -0,0 +1,130 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; +import java.util.Map.Entry; +import java.util.Set; + +import org.jclouds.sqs.domain.BatchResult; +import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.internal.BaseSQSApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.testng.internal.annotations.Sets; + +import com.google.common.base.Charsets; +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.Iterables; +import com.google.common.hash.Hashing; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "BulkMessageApiLiveTest") +public class BulkMessageApiLiveTest extends BaseSQSApiLiveTest { + + private ImmutableMap idPayload; + + public BulkMessageApiLiveTest() { + prefix = prefix + "-bulk"; + + Builder builder = ImmutableMap. builder(); + for (int i = 0; i < 10; i++) { + String message = "hardyharhar" + i; + builder.put(i + "", message); + } + idPayload = builder.build(); + } + + @BeforeClass(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + recreateQueueInRegion(prefix, null); + } + + public void testSendMessages() { + for (URI queue : queues) { + BatchResult acks = api().getMessageApiForQueue(queue).send(idPayload); + + assertEquals(acks.size(), idPayload.size(), "error sending " + acks); + assertEquals(acks.keySet(), idPayload.keySet()); + + for (Entry entry : acks.entrySet()) { + assertEquals(entry.getValue().getMD5(), + Hashing.md5().hashString(idPayload.get(entry.getKey()), Charsets.UTF_8), "bad md5 for: " + entry); + } + } + } + + private Iterable receiptHandles; + + @Test(dependsOnMethods = "testSendMessages") + public void testChangeMessageVisibility() { + for (URI queue : queues) { + MessageApi api = api().getMessageApiForQueue(queue); + + Set messages = collectMessages(api); + + receiptHandles = Iterables.transform(messages, new Function() { + @Override + public String apply(Message in) { + return in.getReceiptHandle(); + } + }); + + // hidden message, so we can't see it + assertNull(api.receive()); + + // this should unhide it + BatchResult acks = api.changeVisibility(receiptHandles, 0); + assertEquals(acks.size(), messages.size(), "error changing visibility " + acks); + + // so we can see it again + assertEquals(collectMessages(api).size(), messages.size()); + } + } + + protected Set collectMessages(MessageApi api) { + // you are not guaranteed to get all messages in the same request + Set messages = Sets.newLinkedHashSet(); + while (messages.size() != idPayload.size()) + messages.addAll(api.receive(idPayload.size(), attribute("None").visibilityTimeout(5))); + return messages; + } + + @Test(dependsOnMethods = "testChangeMessageVisibility") + public void testDeleteMessage() throws InterruptedException { + for (URI queue : queues) { + BatchResult acks = api().getMessageApiForQueue(queue).delete(receiptHandles); + assertEquals(acks.size(), Iterables.size(receiptHandles), "error deleting messages " + acks); + assertNoMessages(queue); + } + } + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java new file mode 100644 index 0000000000..da2fa1b138 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java @@ -0,0 +1,542 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.sqs.SQSApi; +import org.jclouds.sqs.internal.BaseSQSApiExpectTest; +import org.jclouds.sqs.parse.ChangeMessageVisibilityBatchResponseTest; +import org.jclouds.sqs.parse.DeleteMessageBatchResponseTest; +import org.jclouds.sqs.parse.ReceiveMessageResponseTest; +import org.jclouds.sqs.parse.SendMessageBatchResponseTest; +import org.jclouds.sqs.parse.SendMessageResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "MessageApiExpectTest") +public class MessageApiExpectTest extends BaseSQSApiExpectTest { + + public HttpRequest sendMessage = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessage") + .addFormParam("MessageBody", "hardyharhar") + .addFormParam("Signature", "PVzszzgIcT1xt9%2BEzGzWB2Bt8zDadBc48HsgF89AoJE%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessage, sendMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).send("hardyharhar").toString(), + new SendMessageResponseTest().expected().toString()); + } + + public HttpRequest sendMessageIterable = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessageBatch") + .addFormParam("SendMessageBatchRequestEntry.1.Id", "1") + .addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1") + .addFormParam("SendMessageBatchRequestEntry.2.Id", "2") + .addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2") + .addFormParam("Signature", "2AYMDMLhoLncALJgBfHBGfOkaTB5ut3PeFRJeWffxdI%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageIterableWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessageIterable, sendMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).send(ImmutableSet.of("payload1", "payload2")) + .toString(), new SendMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest sendMessageMap = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessageBatch") + .addFormParam("SendMessageBatchRequestEntry.1.Id", "foo1") + .addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1") + .addFormParam("SendMessageBatchRequestEntry.2.Id", "foo2") + .addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2") + .addFormParam("Signature", "f9v8e%2FrPXTI3zhBYMhg7U8yCfvPqHjAV8bFjhGL6%2BXc%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageMapWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessageMap, sendMessageResponse); + + assertEquals( + apiWhenExist.getMessageApiForQueue(queue) + .send(ImmutableMap.of("foo1", "payload1", "foo2", "payload2")).toString(), + new SendMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest sendMessageWithDelayMap = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessageBatch") + .addFormParam("SendMessageBatchRequestEntry.1.DelaySeconds", "10") + .addFormParam("SendMessageBatchRequestEntry.1.Id", "foo1") + .addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1") + .addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10") + .addFormParam("SendMessageBatchRequestEntry.2.Id", "foo2") + .addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2") + .addFormParam("Signature", "COjjEaJ76EwziEFtkT2FuSRSbrCIu%2FhlJf1Zmu7cYoU%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageWithDelayMapWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessageWithDelayMap, sendMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).sendWithDelay(ImmutableMap.builder() + .put("foo1", "payload1") + .put("foo2", "payload2") + .build(), 10) + .toString(), new SendMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest sendMessageWithDelayIterable = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessageBatch") + .addFormParam("SendMessageBatchRequestEntry.1.DelaySeconds", "10") + .addFormParam("SendMessageBatchRequestEntry.1.Id", "1") + .addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1") + .addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10") + .addFormParam("SendMessageBatchRequestEntry.2.Id", "2") + .addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2") + .addFormParam("Signature", "8AVNvSVXPSnoXjJAc6h1rysMBBZPnSycbnmD2%2FqpdV8%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageWithDelayIterableWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessageWithDelayIterable, sendMessageResponse); + + assertEquals( + apiWhenExist.getMessageApiForQueue(queue).sendWithDelay(ImmutableSet.of("payload1", "payload2"), 10) + .toString(), new SendMessageBatchResponseTest().expected().toString()); + } + public HttpRequest sendMessageWithDelaysTable = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessageBatch") + .addFormParam("SendMessageBatchRequestEntry.1.DelaySeconds", "1") + .addFormParam("SendMessageBatchRequestEntry.1.Id", "foo1") + .addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1") + .addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10") + .addFormParam("SendMessageBatchRequestEntry.2.Id", "foo2") + .addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2") + .addFormParam("Signature", "M2X8Al%2BbyyDM%2B9kdN28rMn1yJWl78hJ5i4GnaMZ1sYg%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageWithDelaysTableWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessageWithDelaysTable, sendMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).sendWithDelays(ImmutableTable.builder() + .put("foo1", "payload1", 1) + .put("foo2", "payload2", 10) + .build()) + .toString(), new SendMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest sendMessageWithDelaysMap = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SendMessageBatch") + .addFormParam("SendMessageBatchRequestEntry.1.DelaySeconds", "1") + .addFormParam("SendMessageBatchRequestEntry.1.Id", "1") + .addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1") + .addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10") + .addFormParam("SendMessageBatchRequestEntry.2.Id", "2") + .addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2") + .addFormParam("Signature", "nbA4UnKDAuQCiCcvQHH%2F1UjMMeo2s3d94A27Q3t9SlI%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSendMessageWithDelaysMapWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/send_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(sendMessageWithDelaysMap, sendMessageResponse); + + assertEquals( + apiWhenExist.getMessageApiForQueue(queue).sendWithDelays(ImmutableMap.of("payload1", 1, "payload2", 10)) + .toString(), new SendMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest receiveMessage = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ReceiveMessage") + .addFormParam("Signature", "UURXsAjggoaz5P1h2EFswRd8Ji9euHmXhHvrAmIqM1E%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testReceiveMessageWhenResponseIs2xx() throws Exception { + + HttpResponse receiveMessageResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/messages.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(receiveMessage, receiveMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive().toString(), + Iterables.get(new ReceiveMessageResponseTest().expected(), 0).toString()); + } + + + public HttpRequest receiveMessages = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ReceiveMessage") + .addFormParam("MaxNumberOfMessages", "10") + .addFormParam("Signature", "pZ9B4%2BTBvQA4n0joP4t8ue5x0xmKMd9prpVLVoT%2F7qU%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testReceiveMessagesWhenResponseIs2xx() throws Exception { + + HttpResponse receiveMessagesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/messages.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(receiveMessages, receiveMessagesResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).receive(10).toString(), new ReceiveMessageResponseTest() + .expected().toString()); + } + + public HttpRequest deleteMessage = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "DeleteMessage") + .addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe") + .addFormParam("Signature", "9%2FkuCc2i78gMsmul%2BRsOPcdQ1OLUKrItqgGIRRBJb8M%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testDeleteMessageWhenResponseIs2xx() throws Exception { + + HttpResponse deleteMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(deleteMessage, deleteMessageResponse); + + apiWhenExist.getMessageApiForQueue(queue).delete("eXJYhj5rDr9cAe"); + } + + public HttpRequest deleteMessageIterable = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "DeleteMessageBatch") + .addFormParam("DeleteMessageBatchRequestEntry.1.Id", "1") + .addFormParam("DeleteMessageBatchRequestEntry.1.ReceiptHandle", "eXJYhj5rDr9cAe") + .addFormParam("DeleteMessageBatchRequestEntry.2.Id", "2") + .addFormParam("DeleteMessageBatchRequestEntry.2.ReceiptHandle", "fffeeerrr") + .addFormParam("Signature", "S4xIobjm3LOkJvibeI2X54nxKJw9r1a5zj%2FdvHlfDMY%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testDeleteMessageIterableWhenResponseIs2xx() throws Exception { + + HttpResponse deleteMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/delete_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(deleteMessageIterable, deleteMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).delete(ImmutableSet.of("eXJYhj5rDr9cAe", "fffeeerrr")) + .toString(), new DeleteMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest deleteMessageMap = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "DeleteMessageBatch") + .addFormParam("DeleteMessageBatchRequestEntry.1.Id", "foo1") + .addFormParam("DeleteMessageBatchRequestEntry.1.ReceiptHandle", "eXJYhj5rDr9cAe") + .addFormParam("DeleteMessageBatchRequestEntry.2.Id", "foo2") + .addFormParam("DeleteMessageBatchRequestEntry.2.ReceiptHandle", "fffeeerrr") + .addFormParam("Signature", "kwHC3F3ZoJvfibhZWVTeIwFHUzoaVMR4OViyJbsmuV0%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testDeleteMessageMapWhenResponseIs2xx() throws Exception { + + HttpResponse deleteMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/delete_message_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(deleteMessageMap, deleteMessageResponse); + + assertEquals( + apiWhenExist.getMessageApiForQueue(queue) + .delete(ImmutableMap.of("foo1", "eXJYhj5rDr9cAe", "foo2", "fffeeerrr")).toString(), + new DeleteMessageBatchResponseTest().expected().toString()); + } + + public HttpRequest changeMessageVisibility = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ChangeMessageVisibility") + .addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe") + .addFormParam("Signature", "gvmSHleGLkmszYU6aURCBImuec2k0O3pg3tAYhDvkNs%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("VisibilityTimeout", "10") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testChangeMessageVisibilityWhenResponseIs2xx() throws Exception { + + HttpResponse changeMessageVisibilityResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibility, changeMessageVisibilityResponse); + + apiWhenExist.getMessageApiForQueue(queue).changeVisibility("eXJYhj5rDr9cAe", 10); + } + + public HttpRequest changeMessageVisibilityTable = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ChangeMessageVisibilityBatch") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.Id", "foo1") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.ReceiptHandle", "aaaaaaaaa") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.VisibilityTimeout", "1") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.Id", "foo2") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.ReceiptHandle", "bbbbbbbbb") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.VisibilityTimeout", "10") + .addFormParam("Signature", "KjDusYiiC3hTdy3ZxLwBRHryrNoNaFb2AHJqUDu3mtQ%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testChangeMessageVisibilityTableWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/change_message_visibility_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibilityTable, sendMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).changeVisibility(ImmutableTable.builder() + .put("foo1", "aaaaaaaaa", 1) + .put("foo2", "bbbbbbbbb", 10) + .build()) + .toString(), new ChangeMessageVisibilityBatchResponseTest().expected().toString()); + } + + public HttpRequest changeMessageVisibilityMap = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ChangeMessageVisibilityBatch") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.Id", "1") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.ReceiptHandle", "aaaaaaaaa") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.VisibilityTimeout", "1") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.Id", "2") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.ReceiptHandle", "bbbbbbbbb") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.VisibilityTimeout", "10") + .addFormParam("Signature", "zj2cftkpHtiYb9iOjPR3AhcVhoobi0JvOy22PvQJtho%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testChangeMessageVisibilityMapWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/change_message_visibility_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibilityMap, sendMessageResponse); + + assertEquals( + apiWhenExist.getMessageApiForQueue(queue).changeVisibility(ImmutableMap.of("aaaaaaaaa", 1, "bbbbbbbbb", 10)) + .toString(), new ChangeMessageVisibilityBatchResponseTest().expected().toString()); + } + + public HttpRequest changeMessageVisibilityMapInt = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ChangeMessageVisibilityBatch") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.Id", "foo1") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.ReceiptHandle", "aaaaaaaaa") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.VisibilityTimeout", "10") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.Id", "foo2") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.ReceiptHandle", "bbbbbbbbb") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.VisibilityTimeout", "10") + .addFormParam("Signature", "y%2FgaaxoE5wrG2P7NIAyfDo7DTgRx2PLJUi9%2FzNnWQ6A%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testChangeMessageVisibilityMapIntWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/change_message_visibility_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibilityMapInt, sendMessageResponse); + + assertEquals(apiWhenExist.getMessageApiForQueue(queue).changeVisibility(ImmutableMap.builder() + .put("foo1", "aaaaaaaaa") + .put("foo2", "bbbbbbbbb") + .build(), 10) + .toString(), new ChangeMessageVisibilityBatchResponseTest().expected().toString()); + } + + public HttpRequest changeMessageVisibilityIterableInt = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "ChangeMessageVisibilityBatch") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.Id", "1") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.ReceiptHandle", "aaaaaaaaa") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.1.VisibilityTimeout", "10") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.Id", "2") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.ReceiptHandle", "bbbbbbbbb") + .addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.VisibilityTimeout", "10") + .addFormParam("Signature", "f5aq7zdKFErM3%2BIdtDX5NOzPO7mqCRzPGj2wUUEWjgE%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testChangeMessageVisibilityIterableIntWhenResponseIs2xx() throws Exception { + + HttpResponse sendMessageResponse = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResourceWithContentType("/change_message_visibility_batch.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(changeMessageVisibilityIterableInt, sendMessageResponse); + + assertEquals( + apiWhenExist.getMessageApiForQueue(queue).changeVisibility(ImmutableSet.of("aaaaaaaaa", "bbbbbbbbb"), 10) + .toString(), new ChangeMessageVisibilityBatchResponseTest().expected().toString()); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java new file mode 100644 index 0000000000..0e2a3ea77c --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java @@ -0,0 +1,94 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static org.jclouds.sqs.options.ReceiveMessageOptions.Builder.attribute; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; + +import org.jclouds.sqs.internal.BaseSQSApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Charsets; +import com.google.common.hash.HashCode; +import com.google.common.hash.Hashing; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "MessageApiLiveTest") +public class MessageApiLiveTest extends BaseSQSApiLiveTest { + + public MessageApiLiveTest() { + prefix = prefix + "-message"; + } + + @BeforeClass(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + recreateQueueInRegion(prefix, null); + } + + String message = "hardyharhar"; + HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8); + + public void testSendMessage() { + for (URI queue : queues) { + assertEquals(api().getMessageApiForQueue(queue).send(message).getMD5(), md5); + } + } + + @Test(dependsOnMethods = "testSendMessage") + public void testReceiveMessageWithoutHidingMessage() { + for (URI queue : queues) { + assertEquals(api().getMessageApiForQueue(queue).receive(attribute("All").visibilityTimeout(0)).getMD5(), md5); + } + } + + String receiptHandle; + + @Test(dependsOnMethods = "testReceiveMessageWithoutHidingMessage") + public void testChangeMessageVisibility() { + for (URI queue : queues) { + MessageApi api = api().getMessageApiForQueue(queue); + // start hiding it at 5 seconds + receiptHandle = api.receive(attribute("None").visibilityTimeout(5)).getReceiptHandle(); + // hidden message, so we can't see it + assertNull(api.receive()); + // this should unhide it + api.changeVisibility(receiptHandle, 0); + // so we can see it again + assertEquals(api.receive(attribute("All").visibilityTimeout(0)).getMD5(), md5); + } + } + + @Test(dependsOnMethods = "testChangeMessageVisibility") + public void testDeleteMessage() throws InterruptedException { + for (URI queue : queues) { + api().getMessageApiForQueue(queue).delete(receiptHandle); + assertNoMessages(queue); + } + } + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java new file mode 100644 index 0000000000..037de11b3a --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java @@ -0,0 +1,89 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.sqs.SQSApi; +import org.jclouds.sqs.domain.Action; +import org.jclouds.sqs.internal.BaseSQSApiExpectTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "PermissionApiExpectTest") +public class PermissionApiExpectTest extends BaseSQSApiExpectTest { + + public HttpRequest addPermission = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "AddPermission") + .addFormParam("ActionName.1", "ReceiveMessage") + .addFormParam("AWSAccountId.1", "125074342641") + .addFormParam("Label", "testLabel") + .addFormParam("Signature", "J9sV4q1rJ7dWYJDQp9JxsfEKNXQhpQBYIwBYi1IeXV0%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testAddPermissionWhenResponseIs2xx() throws Exception { + + HttpResponse addPermissionResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(addPermission, addPermissionResponse); + + apiWhenExist.getPermissionApiForQueue(queue).addPermissionToAccount("testLabel", Action.RECEIVE_MESSAGE, "125074342641"); + } + + public HttpRequest removePermission = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "RemovePermission") + .addFormParam("Label", "testLabel") + .addFormParam("Signature", "VOA0L1uRVKQDQL1Klt0cYUajGoxN4Ur%2B7ISQ2I4RpRs%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testRemovePermissionWhenResponseIs2xx() throws Exception { + + HttpResponse removePermissionResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(removePermission, removePermissionResponse); + + apiWhenExist.getPermissionApiForQueue(queue).remove("testLabel"); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java new file mode 100644 index 0000000000..b1aa629840 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java @@ -0,0 +1,121 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static com.google.common.collect.Iterables.get; +import static org.jclouds.concurrent.MoreExecutors.sameThreadExecutor; +import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint; +import static org.jclouds.sqs.reference.SQSParameters.ACTION; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.ContextBuilder; +import org.jclouds.concurrent.Timeout; +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.sqs.domain.Action; +import org.jclouds.sqs.domain.QueueAttributes; +import org.jclouds.sqs.internal.BaseSQSApiLiveTest; +import org.jclouds.sqs.xml.ValueHandler; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.inject.Module; + +/** + * + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "PermissionApiLiveTest") +public class PermissionApiLiveTest extends BaseSQSApiLiveTest { + + public PermissionApiLiveTest() { + prefix = prefix + "-permission"; + } + + @BeforeClass(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + recreateQueueInRegion(prefix, null); + } + + @Timeout(duration = 5, timeUnit = TimeUnit.SECONDS) + static interface AnonymousAttributesApi { + String getQueueArn(); + } + + static interface AnonymousAttributesAsyncApi { + @POST + @Path("/") + @FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "QueueArn" }) + @XMLResponseParser(ValueHandler.class) + ListenableFuture getQueueArn(); + } + + public void testAddAnonymousPermission() throws InterruptedException { + for (URI queue : queues) { + QueueAttributes attributes = api().getQueueApi().getAttributes(queue); + assertNoPermissions(queue); + + String accountToAuthorize = getAccountToAuthorize(queue); + api().getPermissionApiForQueue(queue).addPermissionToAccount("fubar", Action.GET_QUEUE_ATTRIBUTES, + accountToAuthorize); + + String policyForAuthorizationByAccount = assertPolicyPresent(queue); + + String policyForAnonymous = policyForAuthorizationByAccount.replace("\"" + accountToAuthorize + "\"", "\"*\""); + api().getQueueApi().setAttribute(queue, "Policy", policyForAnonymous); + + assertEquals(getAnonymousAttributesApi(queue).getQueueArn(), attributes.getQueueArn()); + } + } + + protected String getAccountToAuthorize(URI queue) { + return get(Splitter.on('/').split(queue.getPath()), 1); + } + + @Test(dependsOnMethods = "testAddAnonymousPermission") + public void testRemovePermission() throws InterruptedException { + for (URI queue : queues) { + api().getPermissionApiForQueue(queue).remove("fubar"); + assertNoPermissions(queue); + } + } + + private AnonymousAttributesApi getAnonymousAttributesApi(URI queue) { + return ContextBuilder + .newBuilder( + forClientMappedToAsyncClientOnEndpoint(AnonymousAttributesApi.class, + AnonymousAttributesAsyncApi.class, queue.toASCIIString())) + .modules(ImmutableSet. of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) + .buildInjector().getInstance(AnonymousAttributesApi.class); + } + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java new file mode 100644 index 0000000000..a9b09a1c4f --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java @@ -0,0 +1,169 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.sqs.SQSApi; +import org.jclouds.sqs.functions.MapToQueueAttributesTest; +import org.jclouds.sqs.internal.BaseSQSApiExpectTest; +import org.jclouds.sqs.parse.CreateQueueResponseTest; +import org.jclouds.sqs.parse.GetQueueAttributesResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "QueueApiExpectTest") +public class QueueApiExpectTest extends BaseSQSApiExpectTest { + + public HttpRequest createQueue = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "CreateQueue") + .addFormParam("QueueName", "queueName") + .addFormParam("Signature", "I7tmwiCzJ9cvw79pmlz1rOILh2C2ZV6OpLk23JGx6AU%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testCreateQueueWhenResponseIs2xx() throws Exception { + + HttpResponse createQueueResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/create_queue.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(createQueue, createQueueResponse); + + assertEquals(apiWhenExist.getQueueApi().create("queueName").toString(), new CreateQueueResponseTest().expected() + .toString()); + } + + public HttpRequest getQueueAttribute = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "GetQueueAttributes") + .addFormParam("AttributeName.1", "VisibilityTimeout") + .addFormParam("Signature", "AfydayBBaIk4UGikHHY1CFNmOOAcTnogpFWydZyNass%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testGetQueueAttributeWhenResponseIs2xx() throws Exception { + + HttpResponse getQueueAttributeResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "VisibilityTimeout30", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(getQueueAttribute, getQueueAttributeResponse); + + assertEquals(apiWhenExist.getQueueApi().getAttribute(queue, "VisibilityTimeout"), "30"); + } + + public HttpRequest getQueueAttributes = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "GetQueueAttributes") + .addFormParam("AttributeName.1", "All") + .addFormParam("Signature", "welFLn0TV6JlH6s6s60XZTJeJfFXGiXN4qNPrBx7aHc%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testGetQueueAttributesWhenResponseIs2xx() throws Exception { + + HttpResponse getQueueAttributesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/attributes.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(getQueueAttributes, getQueueAttributesResponse); + + assertEquals(apiWhenExist.getQueueApi().getAttributes(queue).toString(), new MapToQueueAttributesTest() + .expected().toString()); + } + + public HttpRequest getQueueAttributesSubset = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "GetQueueAttributes") + .addFormParam("AttributeName.1", "VisibilityTimeout") + .addFormParam("AttributeName.2", "DelaySeconds") + .addFormParam("Signature", "9KaiOOWWyFPTVMOnyHA3ZoXbPBPSD4AZ4q460UNMfDs%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testGetQueueAttributesSubsetWhenResponseIs2xx() throws Exception { + + HttpResponse getQueueAttributesSubsetResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/attributes.xml", "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(getQueueAttributesSubset, getQueueAttributesSubsetResponse); + + assertEquals(apiWhenExist.getQueueApi() + .getAttributes(queue, ImmutableSet.of("VisibilityTimeout", "DelaySeconds")).toString(), + new GetQueueAttributesResponseTest().expected().toString()); + } + + public HttpRequest setQueueAttribute = HttpRequest.builder() + .method("POST") + .endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/") + .addHeader("Host", "sqs.us-east-1.amazonaws.com") + .addFormParam("Action", "SetQueueAttributes") + .addFormParam("Attribute.Name", "MaximumMessageSize") + .addFormParam("Attribute.Value", "1") + .addFormParam("Signature", "ktBkQ3c%2FrwGcBSec0fkckfo73xmcoTuub5fxudM1qh0%3D") + .addFormParam("SignatureMethod", "HmacSHA256") + .addFormParam("SignatureVersion", "2") + .addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z") + .addFormParam("Version", "2011-10-01") + .addFormParam("AWSAccessKeyId", "identity").build(); + + public void testSetQueueAttributeWhenResponseIs2xx() throws Exception { + + HttpResponse setQueueAttributeResponse = HttpResponse.builder() + .statusCode(200) + .payload( + payloadFromStringWithContentType( + "b5293cb5-d306-4a17-9048-b263635abe42", + "text/xml")).build(); + + SQSApi apiWhenExist = requestSendsResponse(setQueueAttribute, setQueueAttributeResponse); + + apiWhenExist.getQueueApi().setAttribute(queue, "MaximumMessageSize", "1"); + } + +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java new file mode 100644 index 0000000000..d6481ece9a --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java @@ -0,0 +1,80 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.features; + +import static com.google.common.collect.Iterables.getLast; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import org.jclouds.sqs.internal.BaseSQSApiLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "QueueApiLiveTest") +public class QueueApiLiveTest extends BaseSQSApiLiveTest { + + public QueueApiLiveTest() { + prefix = prefix + "-queue"; + } + + @Test + public void testListQueues() throws InterruptedException { + listQueuesInRegion(null); + } + + protected void listQueuesInRegion(String region) throws InterruptedException { + Set allResults = api().getQueueApiForRegion(region).list(); + assertNotNull(allResults); + if (allResults.size() >= 1) { + URI queue = getLast(allResults); + assertQueueInList(region, queue); + } + } + + @Test + public void testCanRecreateQueueGracefully() throws InterruptedException { + recreateQueueInRegion(prefix, null); + recreateQueueInRegion(prefix, null); + } + + @Test(dependsOnMethods = "testCanRecreateQueueGracefully") + public void testGetQueueAttributes() { + for (URI queue : queues) { + Map attributes = api().getQueueApi().getAttributes(queue, ImmutableSet.of("All")); + assertEquals(api().getQueueApi().getAttributes(queue, attributes.keySet()), attributes); + } + } + + @Test(dependsOnMethods = "testGetQueueAttributes") + public void testSetQueueAttribute() { + for (URI queue : queues) { + api().getQueueApi().setAttribute(queue, "MaximumMessageSize", "1024"); + assertEquals(api().getQueueApi().getAttributes(queue).getMaximumMessageSize(), 1024); + } + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index 7b60c8df48..35799ec397 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -18,12 +18,15 @@ */ package org.jclouds.sqs.internal; +import static com.google.common.collect.Iterables.getLast; +import static org.jclouds.sqs.options.ListQueuesOptions.Builder.queuePrefix; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jclouds.apis.BaseContextLiveTest; @@ -32,9 +35,13 @@ import org.jclouds.sqs.SQSApi; import org.jclouds.sqs.SQSApiMetadata; import org.jclouds.sqs.SQSAsyncApi; import org.jclouds.sqs.domain.Message; +import org.jclouds.sqs.features.QueueApi; +import org.testng.annotations.AfterClass; import org.testng.annotations.Test; +import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; +import com.google.common.util.concurrent.Uninterruptibles; /** * @@ -43,16 +50,32 @@ import com.google.common.reflect.TypeToken; @Test(groups = "live") public class BaseSQSApiLiveTest extends BaseContextLiveTest> { + protected String prefix = System.getProperty("user.name") + "-sqs"; + public BaseSQSApiLiveTest() { provider = "sqs"; } + protected Set queues = Sets.newHashSet(); + + protected String recreateQueueInRegion(String queueName, String region) { + QueueApi api = api().getQueueApiForRegion(region); + Set result = api.list(queuePrefix(queueName)); + if (result.size() >= 1) { + api.delete(getLast(result)); + } + URI queue = api.create(queueName); + assertQueueInList(region, queue); + queues.add(queue); + return queueName; + } + @Override protected TypeToken> contextType() { return SQSApiMetadata.CONTEXT_TOKEN; } - protected String assertPolicyPresent(final URI queue) throws InterruptedException { + protected String assertPolicyPresent(final URI queue) { final AtomicReference policy = new AtomicReference(); assertEventually(new Runnable() { public void run() { @@ -65,7 +88,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest extends BaseRestApiExpectTest { + protected URI queue = URI.create("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/"); public BaseSQSExpectTest() { provider = "sqs"; diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java new file mode 100644 index 0000000000..4e40613310 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.sqs.domain.BatchResult; +import org.jclouds.sqs.xml.ChangeMessageVisibilityBatchResponseHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "ChangeMessageVisibilityBatchResponseTest") +public class ChangeMessageVisibilityBatchResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/change_message_visibility_batch.xml"); + + BatchResult expected = expected(); + + ChangeMessageVisibilityBatchResponseHandler handler = injector.getInstance(ChangeMessageVisibilityBatchResponseHandler.class); + BatchResult result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public BatchResult expected() { + return BatchResult. builder() + .put("change_visibility_msg_2","change_visibility_msg_2") + .put("change_visibility_msg_3","change_visibility_msg_3") + .build(); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java new file mode 100644 index 0000000000..c7e4ce47c5 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.sqs.domain.BatchResult; +import org.jclouds.sqs.xml.DeleteMessageBatchResponseHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "DeleteMessageBatchResponseTest") +public class DeleteMessageBatchResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/delete_message_batch.xml"); + + BatchResult expected = expected(); + + DeleteMessageBatchResponseHandler handler = injector.getInstance(DeleteMessageBatchResponseHandler.class); + BatchResult result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public BatchResult expected() { + return BatchResult. builder() + .put("msg1","msg1") + .put("msg2","msg2") + .build(); + } +} diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java index d345656efd..77f50ee0b1 100644 --- a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java @@ -21,7 +21,7 @@ package org.jclouds.sqs.parse; import static org.testng.Assert.assertEquals; import java.io.InputStream; -import java.util.Set; +import java.util.List; import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.functions.BaseHandlerTest; @@ -29,7 +29,7 @@ import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableList; import com.google.common.hash.HashCodes; /** @@ -43,17 +43,17 @@ public class ReceiveMessageResponseTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/messages.xml"); - Set expected = expected(); + List expected = expected(); ReceiveMessageResponseHandler handler = injector.getInstance(ReceiveMessageResponseHandler.class); - Set result = factory.create(handler).parse(is); + List result = factory.create(handler).parse(is); assertEquals(result.toString(), expected.toString()); } - public Set expected() { - return ImmutableSet.of(Message + public List expected() { + return ImmutableList.of(Message .builder() .id("5fea7756-0ea4-451a-a703-a558b933e274") .receiptHandle( diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java b/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java new file mode 100644 index 0000000000..fcafc10c10 --- /dev/null +++ b/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.sqs.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.sqs.domain.BatchResult; +import org.jclouds.sqs.domain.MessageIdAndMD5; +import org.jclouds.sqs.xml.SendMessageBatchResponseHandler; +import org.testng.annotations.Test; + +import com.google.common.hash.HashCodes; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "SendMessageBatchResponseTest") +public class SendMessageBatchResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/send_message_batch.xml"); + + BatchResult expected = expected(); + + SendMessageBatchResponseHandler handler = injector.getInstance(SendMessageBatchResponseHandler.class); + BatchResult result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public BatchResult expected() { + return BatchResult + . builder() + .put("test_msg_001", + MessageIdAndMD5.builder().id("0a5231c7-8bff-4955-be2e-8dc7c50a25fa") + .md5(HashCodes.fromBytes(CryptoStreams.hex("0e024d309850c78cba5eabbeff7cae71"))).build()) + .put("test_msg_002", + MessageIdAndMD5.builder().id("15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9") + .md5(HashCodes.fromBytes(CryptoStreams.hex("7fb8146a82f95e0af155278f406862c2"))).build()) + .build(); + } +} diff --git a/labs/sqs/src/test/resources/change_message_visibility_batch.xml b/labs/sqs/src/test/resources/change_message_visibility_batch.xml new file mode 100644 index 0000000000..bfc4707d34 --- /dev/null +++ b/labs/sqs/src/test/resources/change_message_visibility_batch.xml @@ -0,0 +1,13 @@ + + + + change_visibility_msg_2 + + + change_visibility_msg_3 + + + + ca9668f7-ab1b-4f7a-8859-f15747ab17a7 + + \ No newline at end of file diff --git a/labs/sqs/src/test/resources/delete_message_batch.xml b/labs/sqs/src/test/resources/delete_message_batch.xml new file mode 100644 index 0000000000..aeaefa7f5e --- /dev/null +++ b/labs/sqs/src/test/resources/delete_message_batch.xml @@ -0,0 +1,13 @@ + + + + msg1 + + + msg2 + + + + d6f86b7a-74d1-4439-b43f-196a1e29cd85 + + \ No newline at end of file diff --git a/labs/sqs/src/test/resources/send_message_batch.xml b/labs/sqs/src/test/resources/send_message_batch.xml new file mode 100644 index 0000000000..5761d08ea9 --- /dev/null +++ b/labs/sqs/src/test/resources/send_message_batch.xml @@ -0,0 +1,17 @@ + + + + test_msg_001 + 0a5231c7-8bff-4955-be2e-8dc7c50a25fa + 0e024d309850c78cba5eabbeff7cae71 + + + test_msg_002 + 15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9 + 7fb8146a82f95e0af155278f406862c2 + + + + ca1ad5d0-8271-408b-8d0f-1351bf547e74 + + \ No newline at end of file From fec732f33bef3e026ae1e12cd5792f5118ac455b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 14 Sep 2012 17:59:53 -0700 Subject: [PATCH 22/60] added aws-sqs provider --- labs/aws-sqs/pom.xml | 114 ++++++++++++++++++ .../aws/sqs/AWSSQSProviderMetadata.java | 107 ++++++++++++++++ .../org.jclouds.providers.ProviderMetadata | 1 + .../jclouds/aws/sqs/AWSSQSProviderTest.java | 36 ++++++ .../sqs/features/AWSMessageApiLiveTest.java | 35 ++++++ .../features/AWSPermissionApiLiveTest.java | 35 ++++++ .../aws/sqs/features/AWSQueueApiLiveTest.java | 35 ++++++ labs/pom.xml | 1 + 8 files changed, 364 insertions(+) create mode 100644 labs/aws-sqs/pom.xml create mode 100644 labs/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java create mode 100644 labs/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java create mode 100644 labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java create mode 100644 labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java create mode 100644 labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java diff --git a/labs/aws-sqs/pom.xml b/labs/aws-sqs/pom.xml new file mode 100644 index 0000000000..9572ac5b42 --- /dev/null +++ b/labs/aws-sqs/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + aws-sqs + jclouds Amazon Simple Queue Service provider + Simple Queue Service implementation targeted to Amazon Web Services + bundle + + + https://sqs.us-east-1.amazonaws.com + 2011-10-01 + + ${test.aws.identity} + ${test.aws.credential} + + org.jclouds.aws.sqs*;version="${project.version}" + org.jclouds*;version="${project.version}",* + + + + + org.jclouds.labs + sqs + ${project.version} + jar + + + org.jclouds.labs + sqs + ${project.version} + test-jar + test + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + 1.0.0 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.aws-sqs.endpoint} + ${test.aws-sqs.api-version} + ${test.aws-sqs.build-version} + ${test.aws-sqs.identity} + ${test.aws-sqs.credential} + + + + + + + + + + + diff --git a/labs/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java b/labs/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java new file mode 100644 index 0000000000..5b85c987ea --- /dev/null +++ b/labs/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java @@ -0,0 +1,107 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.sqs; + +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; +import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; +import static org.jclouds.aws.domain.Region.EU_WEST_1; +import static org.jclouds.aws.domain.Region.SA_EAST_1; +import static org.jclouds.aws.domain.Region.US_EAST_1; +import static org.jclouds.aws.domain.Region.US_WEST_1; +import static org.jclouds.aws.domain.Region.US_WEST_2; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.aws.domain.Region; +import org.jclouds.sqs.SQSApiMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +/** + * Implementation of @ link org.jclouds.types.ProviderMetadata} for Amazon's Simple Queue Service + * provider. + * + * @author Adrian Cole + */ +public class AWSSQSProviderMetadata extends BaseProviderMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = 7750012233546655021L; + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromProviderMetadata(this)); + } + + public AWSSQSProviderMetadata() { + super(builder()); + } + + public AWSSQSProviderMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = new Properties(); + properties.putAll(Region.regionProperties()); + properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + ".endpoint", + "https://sqs.us-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + ".endpoint", + "https://sqs.us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_2 + ".endpoint", + "https://sqs.us-west-2.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + SA_EAST_1 + ".endpoint", + "https://sqs.sa-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + ".endpoint", + "https://sqs.eu-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + ".endpoint", + "https://sqs.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + ".endpoint", + "https://sqs.ap-northeast-1.amazonaws.com"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("aws-sqs") + .name("Amazon Simple Queue Service") + .endpoint("https://sqs.us-east-1.amazonaws.com") + .homepage(URI.create("http://aws.amazon.com/sqs")) + .console(URI.create("https://console.aws.amazon.com/ec2/home")) + .linkedServices("aws-ec2", "aws-rds", "aws-sqs", "aws-elb", "aws-iam","aws-cloudwatch", "aws-s3", "aws-simpledb") + .iso3166Codes("US-VA", "US-CA", "BR-SP", "US-OR", "IE", "SG", "JP-13") + .apiMetadata(new SQSApiMetadata()) + .defaultProperties(AWSSQSProviderMetadata.defaultProperties()); + } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } +} diff --git a/labs/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..6f797d6ddc --- /dev/null +++ b/labs/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.aws.sqs.AWSSQSProviderMetadata diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java new file mode 100644 index 0000000000..8b137f7ea6 --- /dev/null +++ b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.sqs; + +import org.jclouds.sqs.SQSApiMetadata; +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +/** + * The AWSSQSProviderTest tests the org.jclouds.providers.AWSSQSProvider class. + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "AWSSQSProviderTest") +public class AWSSQSProviderTest extends BaseProviderMetadataTest { + + public AWSSQSProviderTest() { + super(new AWSSQSProviderMetadata(), new SQSApiMetadata()); + } +} diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java new file mode 100644 index 0000000000..43d1c95584 --- /dev/null +++ b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.sqs.features; + +import org.jclouds.sqs.features.MessageApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "AWSMessageApiLiveTest") +public class AWSMessageApiLiveTest extends MessageApiLiveTest { + + public AWSMessageApiLiveTest() { + provider = "aws-sqs"; + } + +} diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java new file mode 100644 index 0000000000..14fa42384f --- /dev/null +++ b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.sqs.features; + +import org.jclouds.sqs.features.PermissionApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "AWSPermissionApiLiveTest") +public class AWSPermissionApiLiveTest extends PermissionApiLiveTest { + + public AWSPermissionApiLiveTest() { + provider = "aws-sqs"; + } + +} diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java new file mode 100644 index 0000000000..0065477e22 --- /dev/null +++ b/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.sqs.features; + +import org.jclouds.sqs.features.QueueApiLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "AWSQueueApiLiveTest") +public class AWSQueueApiLiveTest extends QueueApiLiveTest { + + public AWSQueueApiLiveTest() { + provider = "aws-sqs"; + } + +} diff --git a/labs/pom.xml b/labs/pom.xml index 5a445e29e9..c12e25c585 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -62,5 +62,6 @@ fgcp-au fgcp-de sqs + aws-sqs From c7cb9951a8d313d2a808e981b16a7e002baa7b6b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 14 Sep 2012 18:11:13 -0700 Subject: [PATCH 23/60] moved sqs/aws-sqs live --- README.txt | 136 ------------------ all/pom.xml | 5 + apis/pom.xml | 1 + {labs => apis}/sqs/pom.xml | 2 +- .../src/main/java/org/jclouds/sqs/SQSApi.java | 0 .../java/org/jclouds/sqs/SQSApiMetadata.java | 0 .../java/org/jclouds/sqs/SQSAsyncApi.java | 0 ...BindAttributeNamesToIndexedFormParams.java | 0 ...yBatchRequestEntryToIndexedFormParams.java | 0 ...eBatchRequestEntryToIndexedFormParams.java | 0 ...eBatchRequestEntryToIndexedFormParams.java | 0 ...estEntryWithDelaysToIndexedFormParams.java | 0 .../org/jclouds/sqs/config/SQSProperties.java | 0 .../sqs/config/SQSRestClientModule.java | 0 .../java/org/jclouds/sqs/domain/Action.java | 0 .../org/jclouds/sqs/domain/Attribute.java | 0 .../org/jclouds/sqs/domain/BatchError.java | 0 .../org/jclouds/sqs/domain/BatchResult.java | 0 .../java/org/jclouds/sqs/domain/Message.java | 0 .../jclouds/sqs/domain/MessageIdAndMD5.java | 0 .../jclouds/sqs/domain/QueueAttributes.java | 0 .../org/jclouds/sqs/features/MessageApi.java | 0 .../jclouds/sqs/features/MessageAsyncApi.java | 0 .../jclouds/sqs/features/PermissionApi.java | 0 .../sqs/features/PermissionAsyncApi.java | 0 .../org/jclouds/sqs/features/QueueApi.java | 0 .../jclouds/sqs/features/QueueAsyncApi.java | 0 .../sqs/functions/MapToQueueAttributes.java | 0 .../handlers/ParseSQSErrorFromXmlContent.java | 0 .../sqs/handlers/SQSErrorRetryHandler.java | 0 .../sqs/options/CreateQueueOptions.java | 0 .../sqs/options/ListQueuesOptions.java | 0 .../sqs/options/ReceiveMessageOptions.java | 0 .../sqs/options/SendMessageOptions.java | 0 .../java/org/jclouds/sqs/package-info.java | 0 .../jclouds/sqs/reference/SQSParameters.java | 0 .../jclouds/sqs/reference/package-info.java | 0 .../jclouds/sqs/xml/AttributesHandler.java | 0 .../jclouds/sqs/xml/BatchErrorHandler.java | 0 .../jclouds/sqs/xml/BatchResponseHandler.java | 0 ...MessageVisibilityBatchResponseHandler.java | 0 .../DeleteMessageBatchResponseHandler.java | 0 .../java/org/jclouds/sqs/xml/IdHandler.java | 0 .../org/jclouds/sqs/xml/MessageHandler.java | 0 .../xml/ReceiveMessageResponseHandler.java | 0 .../xml/RegexListQueuesResponseHandler.java | 0 .../sqs/xml/RegexMessageIdAndMD5Handler.java | 0 .../jclouds/sqs/xml/RegexQueueHandler.java | 0 .../xml/SendMessageBatchResponseHandler.java | 0 .../SendMessageBatchResultEntryHandler.java | 0 .../sqs/xml/TextFromSingleElementHandler.java | 0 .../org/jclouds/sqs/xml/ValueHandler.java | 0 .../xml/internal/BaseRegexQueueHandler.java | 0 .../services/org.jclouds.apis.ApiMetadata | 0 .../org/jclouds/sqs/SQSApiMetadataTest.java | 0 .../sqs/features/BulkMessageApiLiveTest.java | 0 .../sqs/features/MessageApiExpectTest.java | 0 .../sqs/features/MessageApiLiveTest.java | 0 .../sqs/features/PermissionApiExpectTest.java | 0 .../sqs/features/PermissionApiLiveTest.java | 0 .../sqs/features/QueueApiExpectTest.java | 0 .../sqs/features/QueueApiLiveTest.java | 0 .../functions/MapToQueueAttributesTest.java | 0 .../handlers/SQSErrorRetryHandlerTest.java | 0 .../sqs/internal/BaseSQSApiExpectTest.java | 0 .../sqs/internal/BaseSQSApiLiveTest.java | 0 .../sqs/internal/BaseSQSExpectTest.java | 0 .../sqs/options/CreateQueueOptionsTest.java | 0 .../sqs/options/ListQueuesOptionsTest.java | 0 .../options/ReceiveMessageOptionsTest.java | 0 .../sqs/options/SendMessageOptionsTest.java | 0 ...ngeMessageVisibilityBatchResponseTest.java | 0 .../sqs/parse/CreateQueueResponseTest.java | 0 .../parse/DeleteMessageBatchResponseTest.java | 0 .../parse/GetQueueAttributesResponseTest.java | 0 .../sqs/parse/ReceiveMessageResponseTest.java | 0 .../parse/SendMessageBatchResponseTest.java | 0 .../sqs/parse/SendMessageResponseTest.java | 0 .../sqs/src/test/resources/attributes.xml | 0 .../change_message_visibility_batch.xml | 0 .../sqs/src/test/resources/create_queue.xml | 0 .../test/resources/delete_message_batch.xml | 0 .../sqs/src/test/resources/list_queues.xml | 0 .../sqs/src/test/resources/log4j.xml | 0 .../sqs/src/test/resources/messages.xml | 0 .../sqs/src/test/resources/send_message.xml | 0 .../src/test/resources/send_message_batch.xml | 0 labs/pom.xml | 2 - {labs => providers}/aws-sqs/pom.xml | 6 +- .../aws/sqs/AWSSQSProviderMetadata.java | 0 .../org.jclouds.providers.ProviderMetadata | 0 .../jclouds/aws/sqs/AWSSQSProviderTest.java | 0 .../sqs/features/AWSMessageApiLiveTest.java | 0 .../features/AWSPermissionApiLiveTest.java | 0 .../aws/sqs/features/AWSQueueApiLiveTest.java | 0 providers/pom.xml | 1 + 96 files changed, 11 insertions(+), 142 deletions(-) delete mode 100644 README.txt rename {labs => apis}/sqs/pom.xml (99%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/SQSApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/Action.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/Message.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/handlers/ParseSQSErrorFromXmlContent.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/package-info.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java (100%) rename {labs => apis}/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java (100%) rename {labs => apis}/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java (100%) rename {labs => apis}/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java (100%) rename {labs => apis}/sqs/src/test/resources/attributes.xml (100%) rename {labs => apis}/sqs/src/test/resources/change_message_visibility_batch.xml (100%) rename {labs => apis}/sqs/src/test/resources/create_queue.xml (100%) rename {labs => apis}/sqs/src/test/resources/delete_message_batch.xml (100%) rename {labs => apis}/sqs/src/test/resources/list_queues.xml (100%) rename {labs => apis}/sqs/src/test/resources/log4j.xml (100%) rename {labs => apis}/sqs/src/test/resources/messages.xml (100%) rename {labs => apis}/sqs/src/test/resources/send_message.xml (100%) rename {labs => apis}/sqs/src/test/resources/send_message_batch.xml (100%) rename {labs => providers}/aws-sqs/pom.xml (97%) rename {labs => providers}/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java (100%) rename {labs => providers}/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata (100%) rename {labs => providers}/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java (100%) rename {labs => providers}/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java (100%) rename {labs => providers}/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java (100%) rename {labs => providers}/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java (100%) diff --git a/README.txt b/README.txt deleted file mode 100644 index c765ebaf56..0000000000 --- a/README.txt +++ /dev/null @@ -1,136 +0,0 @@ -Overview: - -jclouds allows provisioning and control of cloud resources, including blobstore -and compute, from Java and Clojure. Our API gives allows developers to use -both portable abstractions and cloud-specific features. We test support of 30 -cloud providers and cloud software stacks, including Amazon, Azure, GoGrid, -Ninefold, OpenStack, and vCloud. jclouds is licensed under the Apache License, -Version 2.0 - -our current version is 1.4.2 -our next maintenance version is 1.4.2-SNAPSHOT -our dev version is 1.5.0-SNAPSHOT - -check out our examples site! https://github.com/jclouds/jclouds-examples - -our compute api supports: aws-ec2, gogrid, cloudservers-us, stub (in-memory), deltacloud, - cloudservers-uk, vcloud (generic), ec2 (generic), byon, nova, - trmk-ecloud, trmk-vcloudexpress, eucalyptus (generic) - cloudsigma-zrh, elasticstack(generic), go2cloud-jhb1, cloudsigma-lvs, - bluelock-vcloud-zone01, stratogen-vcloud-mycloud, rimuhosting, - slicehost, eucalyptus-partnercloud-ec2, elastichosts-lon-p (Peer 1), - elastichosts-sat-p (Peer 1), elastichosts-lon-b (BlueSquare), - openhosting-east1, serverlove-z1-man, skalicloud-sdg-my, - greenhousedata-element-vcloud, softlayer, cloudsigma (generic), - cloudstack (generic), ninefold-compute, openstack-nov (keystone), - hpcloud-compute, trystack-nova, openstack-nova-ec2, - rackspace-cloudservers-us (next gen), rackspace-cloudservers-uk (next gen) - - * note * the pom dependency org.jclouds/jclouds-allcompute gives you access to - to all of these providers - -our blobstore api supports: aws-s3, cloudfiles-us, cloudfiles-uk, filesystem, - azureblob, atmos (generic), synaptic-storage, hpcloud-objectstorage, - cloudonestorage, walrus(generic), ninefold-storage, - eucalyptus-partnercloud-s3, swift (generic), transient (in-mem) - - * note * the pom dependency org.jclouds/jclouds-allblobstore gives you access to - to all of these providers - -our loadbalancer api supports: cloudloadbalancers-us - - * note * the pom dependency org.jclouds/jclouds-allloadbalancer gives you access to - to all of these providers - -we also have aws-cloudwatch support. - -we also have support for: ibmdev, mezeo, nirvanix, boxdotnet, openstack nova, scality ring, - hosteurope-storage, tiscali-storage, scaleup-storage, googlestorage, - azurequeue, simpledb, as well as a async-http-client - driver in the sandbox - - -If you want access to all jclouds components, include the maven dependency org.jclouds/jclouds-all - - -BlobStore Example (Java): - // init - context = new BlobStoreContextFactory().createContext( - "aws-s3", - accesskeyid, - secretaccesskey); - blobStore = context.getBlobStore(); - - // create container - blobStore.createContainerInLocation(null, "mycontainer"); - - // add blob - blob = blobStore.blobBuilder("test").payload("testdata").build(); - blobStore.putBlob("mycontainer", blob); - -BlobStore Example (Clojure): - (use 'org.jclouds.blobstore2) - - (def *blobstore* (blobstore "azureblob" account encodedkey)) - (create-container *blobstore* "mycontainer") - (put-blob *blobstore* "mycontainer" (blob "test" :payload "testdata")) - -Compute Example (Java): - // init - context = new ComputeServiceContextFactory().createContext( - "aws-ec2", - accesskeyid, - secretaccesskey, - ImmutableSet.of(new Log4JLoggingModule(), - new SshjSshClientModule())); - client = context.getComputeService(); - - // define the requirements of your node - template = client.templateBuilder().osFamily(UBUNTU).smallest().build(); - - // setup a boot user which is the same as your login - template.getOptions().runScript(AdminAccess.standard()); - - // these nodes will be accessible via ssh when the call returns - nodes = client.createNodesInGroup("mycluster", 2, template); - - // you can now run ad-hoc commands on the nodes based on predicates - responses = client.runScriptOnNodesMatching(inGroup("mycluster"), "uptime", - wrapInInitScript(false)); - -Compute Example (Clojure): - (use 'org.jclouds.compute2) - - ; create a compute service using sshj and log4j extensions - (def compute - (*compute* "trmk`-ecloud" "user" "password" :sshj :log4j)) - - ; launch a couple nodes with the default operating system, installing your user. - (create-nodes *compute* "mycluster" 2 - (TemplateOptions$Builder/runScript (AdminAccess/standard))) - - ; run a command on that group - (run-script-on-nodes-matching *compute* (in-group? "mycluster") "uptime" - (RunScriptOptions$Builder/wrapInInitScript false)) - -Downloads: - * release notes: http://www.jclouds.org/documentation/releasenotes/1.3 - * installation guide: http://www.jclouds.org/documentation/userguide/installation-guide - * maven repo: http://repo2.maven.org/maven2 (maven central - the default repository) - * snapshot repo: https://oss.sonatype.org/content/repositories/snapshots - -Links: - * project page: http://jclouds.org/ - * documentation: http://www.jclouds.org/documentation/index - * javadocs (1.1.0): http://jclouds.rimuhosting.com/apidocs/ - * javadocs (1.0-SNAPSHOT): http://jclouds.rimuhosting.com/apidocs-SNAPSHOT/ - * community: http://www.jclouds.org/documentation/reference/apps-that-use-jclouds - * user group: http://groups.google.com/group/jclouds - * dev group: http://groups.google.com/group/jclouds-dev - * twitter: http://twitter.com/jclouds - -## License - -Copyright (C) 2009-2012 jclouds, Inc. - -Licensed under the Apache License, Version 2.0 diff --git a/all/pom.xml b/all/pom.xml index c0ed79dfd8..cfd5ff314b 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -40,6 +40,11 @@ aws-cloudwatch ${project.version} + + org.jclouds.provider + aws-sqs + ${project.version} + ${project.groupId} jclouds-allloadbalancer diff --git a/apis/pom.xml b/apis/pom.xml index bde1678588..29c3c5a57a 100644 --- a/apis/pom.xml +++ b/apis/pom.xml @@ -54,5 +54,6 @@ cloudsigma cloudstack rackspace-cloudidentity + sqs diff --git a/labs/sqs/pom.xml b/apis/sqs/pom.xml similarity index 99% rename from labs/sqs/pom.xml rename to apis/sqs/pom.xml index 43f9c737c9..83f4cbf0e0 100644 --- a/labs/sqs/pom.xml +++ b/apis/sqs/pom.xml @@ -27,7 +27,7 @@ 1.5.0-SNAPSHOT ../../project/pom.xml - org.jclouds.labs + org.jclouds.api sqs jcloud sqs api jclouds components to access an implementation of Simple Queue Service diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/SQSApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/SQSApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/SQSApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java b/apis/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java rename to apis/sqs/src/main/java/org/jclouds/sqs/SQSApiMetadata.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/SQSAsyncApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java b/apis/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java rename to apis/sqs/src/main/java/org/jclouds/sqs/binders/BindAttributeNamesToIndexedFormParams.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java b/apis/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java rename to apis/sqs/src/main/java/org/jclouds/sqs/binders/BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java b/apis/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java rename to apis/sqs/src/main/java/org/jclouds/sqs/binders/BindDeleteMessageBatchRequestEntryToIndexedFormParams.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java b/apis/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java rename to apis/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryToIndexedFormParams.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java b/apis/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java rename to apis/sqs/src/main/java/org/jclouds/sqs/binders/BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java b/apis/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java rename to apis/sqs/src/main/java/org/jclouds/sqs/config/SQSProperties.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java b/apis/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java rename to apis/sqs/src/main/java/org/jclouds/sqs/config/SQSRestClientModule.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/Action.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/Action.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/Action.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/Action.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/Attribute.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/BatchError.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/BatchResult.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/Message.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/Message.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/Message.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/Message.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/MessageIdAndMD5.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java b/apis/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java rename to apis/sqs/src/main/java/org/jclouds/sqs/domain/QueueAttributes.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/features/PermissionApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/features/PermissionAsyncApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java rename to apis/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java b/apis/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java rename to apis/sqs/src/main/java/org/jclouds/sqs/functions/MapToQueueAttributes.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/handlers/ParseSQSErrorFromXmlContent.java b/apis/sqs/src/main/java/org/jclouds/sqs/handlers/ParseSQSErrorFromXmlContent.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/handlers/ParseSQSErrorFromXmlContent.java rename to apis/sqs/src/main/java/org/jclouds/sqs/handlers/ParseSQSErrorFromXmlContent.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/handlers/SQSErrorRetryHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java b/apis/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java rename to apis/sqs/src/main/java/org/jclouds/sqs/options/CreateQueueOptions.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java b/apis/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java rename to apis/sqs/src/main/java/org/jclouds/sqs/options/ListQueuesOptions.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java b/apis/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java rename to apis/sqs/src/main/java/org/jclouds/sqs/options/ReceiveMessageOptions.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java b/apis/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java rename to apis/sqs/src/main/java/org/jclouds/sqs/options/SendMessageOptions.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/package-info.java b/apis/sqs/src/main/java/org/jclouds/sqs/package-info.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/package-info.java rename to apis/sqs/src/main/java/org/jclouds/sqs/package-info.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java b/apis/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java rename to apis/sqs/src/main/java/org/jclouds/sqs/reference/SQSParameters.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java b/apis/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java rename to apis/sqs/src/main/java/org/jclouds/sqs/reference/package-info.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/AttributesHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/BatchErrorHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/BatchResponseHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/ChangeMessageVisibilityBatchResponseHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/DeleteMessageBatchResponseHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/IdHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/MessageHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexMessageIdAndMD5Handler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexQueueHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResponseHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/SendMessageBatchResultEntryHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/TextFromSingleElementHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/ValueHandler.java diff --git a/labs/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java similarity index 100% rename from labs/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java rename to apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java diff --git a/labs/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/apis/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata similarity index 100% rename from labs/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata rename to apis/sqs/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/SQSApiMetadataTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/MessageApiExpectTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/MessageApiLiveTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiExpectTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/PermissionApiLiveTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiExpectTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/functions/MapToQueueAttributesTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiExpectTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSExpectTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/options/CreateQueueOptionsTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/options/ListQueuesOptionsTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/options/ReceiveMessageOptionsTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/options/SendMessageOptionsTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/ChangeMessageVisibilityBatchResponseTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/CreateQueueResponseTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/DeleteMessageBatchResponseTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/GetQueueAttributesResponseTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageBatchResponseTest.java diff --git a/labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java similarity index 100% rename from labs/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java rename to apis/sqs/src/test/java/org/jclouds/sqs/parse/SendMessageResponseTest.java diff --git a/labs/sqs/src/test/resources/attributes.xml b/apis/sqs/src/test/resources/attributes.xml similarity index 100% rename from labs/sqs/src/test/resources/attributes.xml rename to apis/sqs/src/test/resources/attributes.xml diff --git a/labs/sqs/src/test/resources/change_message_visibility_batch.xml b/apis/sqs/src/test/resources/change_message_visibility_batch.xml similarity index 100% rename from labs/sqs/src/test/resources/change_message_visibility_batch.xml rename to apis/sqs/src/test/resources/change_message_visibility_batch.xml diff --git a/labs/sqs/src/test/resources/create_queue.xml b/apis/sqs/src/test/resources/create_queue.xml similarity index 100% rename from labs/sqs/src/test/resources/create_queue.xml rename to apis/sqs/src/test/resources/create_queue.xml diff --git a/labs/sqs/src/test/resources/delete_message_batch.xml b/apis/sqs/src/test/resources/delete_message_batch.xml similarity index 100% rename from labs/sqs/src/test/resources/delete_message_batch.xml rename to apis/sqs/src/test/resources/delete_message_batch.xml diff --git a/labs/sqs/src/test/resources/list_queues.xml b/apis/sqs/src/test/resources/list_queues.xml similarity index 100% rename from labs/sqs/src/test/resources/list_queues.xml rename to apis/sqs/src/test/resources/list_queues.xml diff --git a/labs/sqs/src/test/resources/log4j.xml b/apis/sqs/src/test/resources/log4j.xml similarity index 100% rename from labs/sqs/src/test/resources/log4j.xml rename to apis/sqs/src/test/resources/log4j.xml diff --git a/labs/sqs/src/test/resources/messages.xml b/apis/sqs/src/test/resources/messages.xml similarity index 100% rename from labs/sqs/src/test/resources/messages.xml rename to apis/sqs/src/test/resources/messages.xml diff --git a/labs/sqs/src/test/resources/send_message.xml b/apis/sqs/src/test/resources/send_message.xml similarity index 100% rename from labs/sqs/src/test/resources/send_message.xml rename to apis/sqs/src/test/resources/send_message.xml diff --git a/labs/sqs/src/test/resources/send_message_batch.xml b/apis/sqs/src/test/resources/send_message_batch.xml similarity index 100% rename from labs/sqs/src/test/resources/send_message_batch.xml rename to apis/sqs/src/test/resources/send_message_batch.xml diff --git a/labs/pom.xml b/labs/pom.xml index c12e25c585..0ddb6ed9e2 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -61,7 +61,5 @@ fgcp fgcp-au fgcp-de - sqs - aws-sqs diff --git a/labs/aws-sqs/pom.xml b/providers/aws-sqs/pom.xml similarity index 97% rename from labs/aws-sqs/pom.xml rename to providers/aws-sqs/pom.xml index 9572ac5b42..233f329590 100644 --- a/labs/aws-sqs/pom.xml +++ b/providers/aws-sqs/pom.xml @@ -27,7 +27,7 @@ 1.5.0-SNAPSHOT ../../project/pom.xml - org.jclouds.labs + org.jclouds.provider aws-sqs jclouds Amazon Simple Queue Service provider Simple Queue Service implementation targeted to Amazon Web Services @@ -46,13 +46,13 @@ - org.jclouds.labs + org.jclouds.api sqs ${project.version} jar - org.jclouds.labs + org.jclouds.api sqs ${project.version} test-jar diff --git a/labs/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java b/providers/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java similarity index 100% rename from labs/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java rename to providers/aws-sqs/src/main/java/org/jclouds/aws/sqs/AWSSQSProviderMetadata.java diff --git a/labs/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata similarity index 100% rename from labs/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata rename to providers/aws-sqs/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java b/providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java similarity index 100% rename from labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java rename to providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/AWSSQSProviderTest.java diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java b/providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java similarity index 100% rename from labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java rename to providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSMessageApiLiveTest.java diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java b/providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java similarity index 100% rename from labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java rename to providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSPermissionApiLiveTest.java diff --git a/labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java b/providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java similarity index 100% rename from labs/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java rename to providers/aws-sqs/src/test/java/org/jclouds/aws/sqs/features/AWSQueueApiLiveTest.java diff --git a/providers/pom.xml b/providers/pom.xml index 53ca4767bf..5b1537c1d0 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -73,5 +73,6 @@ trystack-nova rackspace-cloudservers-us rackspace-cloudservers-uk + aws-sqs From 7a3318d1caeb98ec8fa0a7104cac29accf2727a9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 14:04:46 -0700 Subject: [PATCH 24/60] wrong test name --- .../director/v1_5/features/admin/AdminCatalogApiExpectTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java index c6af0da41c..4032b3234c 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/admin/AdminCatalogApiExpectTest.java @@ -50,7 +50,7 @@ import com.google.common.net.HttpHeaders; * * @author grkvlt@apache.org, Adrian Cole */ -@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "CatalogApiExpectTest") +@Test(groups = { "unit", "admin" }, singleThreaded = true, testName = "AdminCatalogApiExpectTest") public class AdminCatalogApiExpectTest extends VCloudDirectorAdminApiExpectTest { static String catalog = "7212e451-76e1-4631-b2de-ba1dfd8080e4"; From 0b316222673c431eccf0c78a468d43aaa0d75852 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 14:05:13 -0700 Subject: [PATCH 25/60] cleaned ec2 instance type --- .../RunningInstanceToNodeMetadata.java | 2 +- .../org/jclouds/ec2/domain/Reservation.java | 197 +++++++++++++----- .../jclouds/ec2/domain/RunningInstance.java | 195 ++++------------- .../ec2/xml/BaseReservationHandler.java | 10 +- .../compute/EC2ComputeServiceLiveTest.java | 2 +- .../RunningInstanceToNodeMetadataTest.java | 4 +- .../DescribeInstancesResponseHandlerTest.java | 14 +- .../xml/RunInstancesResponseHandlerTest.java | 10 +- .../aws/ec2/domain/AWSRunningInstance.java | 82 +------- ...otInstanceRequestToAWSRunningInstance.java | 2 +- .../compute/AWSEC2ComputeServiceLiveTest.java | 2 +- ...cidentalResourcesGetCleanedUpLiveTest.java | 4 +- ...stanceRequestToAWSRunningInstanceTest.java | 2 +- .../parse/DescribeInstancesResponseTest.java | 114 ++++++++++ ...SDescribeInstancesResponseHandlerTest.java | 118 +---------- .../AWSRunInstancesResponseHandlerTest.java | 22 +- .../resources/describe_instances_pending.xml | 82 ++++++++ 17 files changed, 434 insertions(+), 428 deletions(-) create mode 100644 providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java create mode 100644 providers/aws-ec2/src/test/resources/describe_instances_pending.xml diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 731999357f..a134ec036e 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -196,7 +196,7 @@ public class RunningInstanceToNodeMetadata implements Function * @author Adrian Cole */ -public class Reservation extends LinkedHashSet implements Comparable>, - Set { +public class Reservation extends ForwardingSet implements Comparable>{ + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return Reservation. builder().fromReservation(this); + } + + public static class Builder { + private String region; + private String ownerId; + private String requesterId; + private String reservationId; + + private ImmutableSet.Builder instances = ImmutableSet. builder(); + private ImmutableSet.Builder groupNames = ImmutableSet. builder(); + + /** + * @see Reservation#getRegion() + */ + public Builder region(String region) { + this.region = region; + return this; + } + + /** + * @see Reservation#getOwnerId() + */ + public Builder ownerId(String ownerId) { + this.ownerId = ownerId; + return this; + } + + /** + * @see Reservation#getRequesterId() + */ + public Builder requesterId(String requesterId) { + this.requesterId = requesterId; + return this; + } + + /** + * @see Reservation#getReservationId() + */ + public Builder reservationId(String reservationId) { + this.reservationId = reservationId; + return this; + } + + /** + * @see Reservation#iterator + */ + public Builder instance(T instance) { + this.instances.add(checkNotNull(instance, "instance")); + return this; + } + + /** + * @see Reservation#iterator + */ + public Builder instances(Set instances) { + this.instances.addAll(checkNotNull(instances, "instances")); + return this; + } + + /** + * @see Reservation#getGroupNames() + */ + public Builder groupName(String groupName) { + this.groupNames.add(checkNotNull(groupName, "groupName")); + return this; + } + + /** + * @see Reservation#getGroupNames() + */ + public Builder groupNames(Iterable groupNames) { + this.groupNames = ImmutableSet. builder().addAll(checkNotNull(groupNames, "groupNames")); + return this; + } + + public Reservation build() { + return new Reservation(region, groupNames.build(), instances.build(), ownerId, requesterId, reservationId); + } + + public Builder fromReservation(Reservation in) { + return region(in.region).ownerId(in.ownerId).requesterId(in.requesterId).reservationId(in.reservationId) + .instances(in).groupNames(in.groupNames); + } + } - /** The serialVersionUID */ - private static final long serialVersionUID = -9051777593518861395L; private final String region; - private final Set groupIds = Sets.newLinkedHashSet(); + private final ImmutableSet groupNames; + private final ImmutableSet instances; @Nullable private final String ownerId; @Nullable @@ -48,16 +140,21 @@ public class Reservation extends LinkedHashSet imp @Nullable private final String reservationId; - public Reservation(String region, Iterable groupIds, Iterable instances, @Nullable String ownerId, + public Reservation(String region, Iterable groupNames, Iterable instances, @Nullable String ownerId, @Nullable String requesterId, @Nullable String reservationId) { this.region = checkNotNull(region, "region"); - Iterables.addAll(this.groupIds, checkNotNull(groupIds, "groupIds")); - Iterables.addAll(this, checkNotNull(instances, "instances")); + this.groupNames = ImmutableSet.copyOf(checkNotNull(groupNames, "groupNames")); + this.instances = ImmutableSet.copyOf(checkNotNull(instances, "instances")); this.ownerId = ownerId; this.requesterId = requesterId; this.reservationId = reservationId; } + @Override + protected Set delegate() { + return instances; + } + /** * Instances are tied to Availability Zones. However, the instance ID is tied to the Region. */ @@ -65,15 +162,19 @@ public class Reservation extends LinkedHashSet imp return region; } - public int compareTo(Reservation o) { - return (this == o) ? 0 : getReservationId().compareTo(o.getReservationId()); + /** + * @see #getGroupNames() + */ + @Deprecated + public Set getGroupIds() { + return groupNames; } - + /** * Names of the security groups. */ - public Set getGroupIds() { - return groupIds; + public Set getGroupNames() { + return groupNames; } /** @@ -84,7 +185,8 @@ public class Reservation extends LinkedHashSet imp } /** - * ID of the requester. + * The ID of the requester that launched the instances on your behalf (for example, AWS + * Management Console or Auto Scaling). */ public String getRequesterId() { return requesterId; @@ -99,51 +201,34 @@ public class Reservation extends LinkedHashSet imp @Override public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode()); - result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode()); - result = prime * result + ((region == null) ? 0 : region.hashCode()); - result = prime * result + ((requesterId == null) ? 0 : requesterId.hashCode()); - result = prime * result + ((reservationId == null) ? 0 : reservationId.hashCode()); - return result; + return Objects.hashCode(region, reservationId, super.hashCode()); } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) + if (obj == null || getClass() != obj.getClass()) return false; - if (getClass() != obj.getClass()) - return false; - Reservation other = (Reservation) obj; - if (groupIds == null) { - if (other.groupIds != null) - return false; - } else if (!groupIds.equals(other.groupIds)) - return false; - if (ownerId == null) { - if (other.ownerId != null) - return false; - } else if (!ownerId.equals(other.ownerId)) - return false; - if (region == null) { - if (other.region != null) - return false; - } else if (!region.equals(other.region)) - return false; - if (requesterId == null) { - if (other.requesterId != null) - return false; - } else if (!requesterId.equals(other.requesterId)) - return false; - if (reservationId == null) { - if (other.reservationId != null) - return false; - } else if (!reservationId.equals(other.reservationId)) - return false; - return true; + @SuppressWarnings("unchecked") + Reservation that = Reservation.class.cast(obj); + return super.equals(that) && Objects.equal(this.region, that.region) + && Objects.equal(this.reservationId, that.reservationId); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("region", region).add("reservationId", reservationId) + .add("requesterId", requesterId).add("instances", instances).add("groupNames", groupNames).toString(); + } + + @Override + public int compareTo(Reservation other) { + return ComparisonChain.start().compare(region, other.region) + .compare(reservationId, other.reservationId, Ordering.natural().nullsLast()).result(); } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java index 0a11cb68ba..a1573793f0 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java @@ -26,9 +26,13 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ComparisonChain; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.google.common.collect.Ordering; import com.google.common.collect.Sets; /** @@ -44,7 +48,7 @@ public class RunningInstance implements Comparable { public static class Builder { protected String region; - protected Set groupIds = Sets.newLinkedHashSet(); + protected Set groupNames = Sets.newLinkedHashSet(); protected String amiLaunchIndex; protected String dnsName; protected String imageId; @@ -72,14 +76,14 @@ public class RunningInstance implements Comparable { return this; } - public Builder groupIds(Iterable groupIds) { - this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds")); + public Builder groupNames(Iterable groupNames) { + this.groupNames = ImmutableSet.copyOf(checkNotNull(groupNames, "groupNames")); return this; } - public Builder groupId(String groupId) { - if (groupId != null) - this.groupIds.add(groupId); + public Builder groupName(String groupName) { + if (groupName != null) + this.groupNames.add(groupName); return this; } @@ -195,7 +199,7 @@ public class RunningInstance implements Comparable { } public RunningInstance build() { - return new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId, instanceId, instanceState, + return new RunningInstance(region, groupNames, amiLaunchIndex, dnsName, imageId, instanceId, instanceState, rawState, instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone, virtualizationType, platform, privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType, rootDeviceName, ebsBlockDevices); @@ -220,7 +224,7 @@ public class RunningInstance implements Comparable { } protected final String region; - protected final Set groupIds; + protected final Set groupNames; protected final String amiLaunchIndex; @Nullable protected final String dnsName; @@ -253,11 +257,7 @@ public class RunningInstance implements Comparable { protected final String rootDeviceName; protected final Map ebsBlockDevices; - public int compareTo(RunningInstance o) { - return (this == o) ? 0 : getId().compareTo(o.getId()); - } - - protected RunningInstance(String region, Iterable groupIds, @Nullable String amiLaunchIndex, + protected RunningInstance(String region, Iterable groupNames, @Nullable String amiLaunchIndex, @Nullable String dnsName, String imageId, String instanceId, InstanceState instanceState, String rawState, String instanceType, @Nullable String ipAddress, @Nullable String kernelId, @Nullable String keyName, Date launchTime, String availabilityZone, String virtualizationType, @Nullable String platform, @@ -286,7 +286,7 @@ public class RunningInstance implements Comparable { this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType for %s/%s", region, instanceId); this.rootDeviceName = rootDeviceName; this.ebsBlockDevices = ImmutableMap.copyOf(checkNotNull(ebsBlockDevices, "ebsBlockDevices for %s/%s", region, instanceId)); - this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds for %s/%s", region, instanceId)); + this.groupNames = ImmutableSet.copyOf(checkNotNull(groupNames, "groupNames for %s/%s", region, instanceId)); } /** @@ -443,160 +443,55 @@ public class RunningInstance implements Comparable { return ebsBlockDevices; } + /** + * @see #getGroupNames() + */ + @Deprecated + public Set getGroupIds() { + return getGroupNames(); + } + /** * Names of the security groups. */ - public Set getGroupIds() { - return groupIds; + public Set getGroupNames() { + return groupNames; } + @Override + public int compareTo(RunningInstance other) { + return ComparisonChain.start().compare(region, other.region).compare(instanceId, other.instanceId, Ordering.natural().nullsLast()).result(); + } + @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((amiLaunchIndex == null) ? 0 : amiLaunchIndex.hashCode()); - result = prime * result + ((availabilityZone == null) ? 0 : availabilityZone.hashCode()); - result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode()); - result = prime * result + ((ebsBlockDevices == null) ? 0 : ebsBlockDevices.hashCode()); - result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode()); - result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); - result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode()); - result = prime * result + ((instanceType == null) ? 0 : instanceType.hashCode()); - result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode()); - result = prime * result + ((kernelId == null) ? 0 : kernelId.hashCode()); - result = prime * result + ((keyName == null) ? 0 : keyName.hashCode()); - result = prime * result + ((launchTime == null) ? 0 : launchTime.hashCode()); - result = prime * result + ((platform == null) ? 0 : platform.hashCode()); - result = prime * result + ((privateDnsName == null) ? 0 : privateDnsName.hashCode()); - result = prime * result + ((privateIpAddress == null) ? 0 : privateIpAddress.hashCode()); - result = prime * result + ((ramdiskId == null) ? 0 : ramdiskId.hashCode()); - result = prime * result + ((region == null) ? 0 : region.hashCode()); - result = prime * result + ((rootDeviceName == null) ? 0 : rootDeviceName.hashCode()); - result = prime * result + ((rootDeviceType == null) ? 0 : rootDeviceType.hashCode()); - result = prime * result + ((virtualizationType == null) ? 0 : virtualizationType.hashCode()); - return result; + return Objects.hashCode(region, instanceId); } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null) + if (obj == null || getClass() != obj.getClass()) return false; - if (getClass() != obj.getClass()) - return false; - RunningInstance other = (RunningInstance) obj; - if (amiLaunchIndex == null) { - if (other.amiLaunchIndex != null) - return false; - } else if (!amiLaunchIndex.equals(other.amiLaunchIndex)) - return false; - if (availabilityZone == null) { - if (other.availabilityZone != null) - return false; - } else if (!availabilityZone.equals(other.availabilityZone)) - return false; - if (dnsName == null) { - if (other.dnsName != null) - return false; - } else if (!dnsName.equals(other.dnsName)) - return false; - if (ebsBlockDevices == null) { - if (other.ebsBlockDevices != null) - return false; - } else if (!ebsBlockDevices.equals(other.ebsBlockDevices)) - return false; - if (groupIds == null) { - if (other.groupIds != null) - return false; - } else if (!groupIds.equals(other.groupIds)) - return false; - if (imageId == null) { - if (other.imageId != null) - return false; - } else if (!imageId.equals(other.imageId)) - return false; - if (instanceId == null) { - if (other.instanceId != null) - return false; - } else if (!instanceId.equals(other.instanceId)) - return false; - if (instanceType == null) { - if (other.instanceType != null) - return false; - } else if (!instanceType.equals(other.instanceType)) - return false; - if (ipAddress == null) { - if (other.ipAddress != null) - return false; - } else if (!ipAddress.equals(other.ipAddress)) - return false; - if (kernelId == null) { - if (other.kernelId != null) - return false; - } else if (!kernelId.equals(other.kernelId)) - return false; - if (keyName == null) { - if (other.keyName != null) - return false; - } else if (!keyName.equals(other.keyName)) - return false; - if (launchTime == null) { - if (other.launchTime != null) - return false; - } else if (!launchTime.equals(other.launchTime)) - return false; - if (platform == null) { - if (other.platform != null) - return false; - } else if (!platform.equals(other.platform)) - return false; - if (privateDnsName == null) { - if (other.privateDnsName != null) - return false; - } else if (!privateDnsName.equals(other.privateDnsName)) - return false; - if (privateIpAddress == null) { - if (other.privateIpAddress != null) - return false; - } else if (!privateIpAddress.equals(other.privateIpAddress)) - return false; - if (ramdiskId == null) { - if (other.ramdiskId != null) - return false; - } else if (!ramdiskId.equals(other.ramdiskId)) - return false; - if (region == null) { - if (other.region != null) - return false; - } else if (!region.equals(other.region)) - return false; - if (rootDeviceName == null) { - if (other.rootDeviceName != null) - return false; - } else if (!rootDeviceName.equals(other.rootDeviceName)) - return false; - if (rootDeviceType == null) { - if (other.rootDeviceType != null) - return false; - } else if (!rootDeviceType.equals(other.rootDeviceType)) - return false; - if (virtualizationType == null) { - if (other.virtualizationType != null) - return false; - } else if (!virtualizationType.equals(other.virtualizationType)) - return false; - return true; + RunningInstance that = RunningInstance.class.cast(obj); + return Objects.equal(this.region, that.region) && Objects.equal(this.instanceId, that.instanceId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("region", region) + .add("availabilityZone", availabilityZone).add("id", instanceId).add("state", rawState) + .add("type", instanceType).add("virtualizationType", virtualizationType).add("imageId", imageId) + .add("ipAddress", ipAddress).add("dnsName", dnsName).add("privateIpAddress", privateIpAddress) + .add("privateDnsName", privateDnsName).add("keyName", keyName).add("groupNames", groupNames) + .add("platform", platform).add("launchTime", launchTime).add("rootDeviceName", rootDeviceName) + .add("rootDeviceType", rootDeviceType).add("ebsBlockDevices", ebsBlockDevices); } @Override public String toString() { - return "[region=" + region + ", availabilityZone=" + availabilityZone + ", instanceId=" + instanceId - + ", instanceState=" + rawState + ", instanceType=" + instanceType + ", virtualizationType=" - + virtualizationType + ", imageId=" + imageId + ", ipAddress=" + ipAddress + ", dnsName=" + dnsName - + ", privateIpAddress=" + privateIpAddress + ", privateDnsName=" + privateDnsName + ", keyName=" - + keyName + ", groupIds=" + groupIds + ", platform=" + platform + ", launchTime=" + launchTime + ", rootDeviceName=" - + rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", ebsBlockDevices=" + ebsBlockDevices + "]"; + return string().toString(); } + } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java index 33cb755acd..56ef8201a5 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java @@ -80,7 +80,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque private String deviceName; // reservation stuff - private Set groupIds = Sets.newLinkedHashSet(); + private Set groupNames = Sets.newLinkedHashSet(); private String ownerId; private String requesterId; private String reservationId; @@ -111,7 +111,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque } else if (equalsOrSuffix(qName, "groupSet")) { inGroupSet = false; } else if (equalsOrSuffix(qName, "groupId")) { - groupIds.add(currentOrNull(currentText)); + groupNames.add(currentOrNull(currentText)); } else if (equalsOrSuffix(qName, "ownerId")) { ownerId = currentOrNull(currentText); } else if (equalsOrSuffix(qName, "requesterId")) { @@ -210,7 +210,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque } builder.region((region == null) ? defaultRegion.get() : region); - builder.groupIds(groupIds); + builder.groupNames(groupNames); } protected Builder builder() { @@ -229,9 +229,9 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; if (region == null) region = defaultRegion.get(); - Reservation info = new Reservation(region, groupIds, instances, + Reservation info = new Reservation(region, groupNames, instances, ownerId, requesterId, reservationId); - this.groupIds = Sets.newLinkedHashSet(); + this.groupNames = Sets.newLinkedHashSet(); this.instances = Sets.newLinkedHashSet(); this.ownerId = null; this.requesterId = null; diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java index b204a073ef..f8ae751245 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java @@ -151,7 +151,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { assertEquals(instance.getKeyName(), group); // make sure we made our dummy group and also let in the user's group - assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet. of("jclouds#" + group + "#" + assertEquals(Sets.newTreeSet(instance.getGroupNames()), ImmutableSortedSet. of("jclouds#" + group + "#" + instance.getRegion(), group)); // make sure our dummy group has no rules diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index f677c320d6..75e5016c55 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -241,13 +241,13 @@ public class RunningInstanceToNodeMetadataTest { public void testGroupNameIsSetWhenCustomKeyNameIsSetAndSecurityGroupIsGenerated() { checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").keyName("custom-key") - .groupId("jclouds#groupname").build()); + .groupName("jclouds#groupname").build()); } @Test public void testGroupNameIsSetWhenCustomSecurityGroupIsSetAndKeyNameIsGenerated() { checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") - .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").groupId("custom-sec") + .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").groupName("custom-sec") .keyName("jclouds#groupname#23").build()); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java index ebdeba4a9f..24376d88cb 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java @@ -70,7 +70,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> contents = ImmutableSet.of(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of(new RunningInstance.Builder().region( - defaultRegion).groupId("adriancole.ec2ingress").amiLaunchIndex("0").dnsName( + defaultRegion).groupName("adriancole.ec2ingress").amiLaunchIndex("0").dnsName( "ec2-174-129-81-68.compute-1.amazonaws.com").imageId("ami-82e4b5c7").instanceId("i-0799056f") .instanceState(InstanceState.RUNNING).rawState("running").instanceType(InstanceType.M1_SMALL) .ipAddress("174.129.81.68").kernelId("aki-a71cf9ce").keyName("adriancole.ec21").launchTime( @@ -83,7 +83,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> result = parseRunningInstances("/describe_instances_running.xml"); - assertEquals(result, contents); + assertEquals(result.toString(), contents.toString()); assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING); assertEquals(get(get(result, 0), 0).getRawState(), "running"); @@ -91,7 +91,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { Set> contents = ImmutableSet.of(new Reservation(defaultRegion, - ImmutableSet.of("default"), ImmutableSet.of(new RunningInstance.Builder().region(defaultRegion).groupId( + ImmutableSet.of("default"), ImmutableSet.of(new RunningInstance.Builder().region(defaultRegion).groupName( "default").amiLaunchIndex("23").dnsName("ec2-72-44-33-4.compute-1.amazonaws.com").imageId( "ami-6ea54007").instanceId("i-28a64341").instanceState(InstanceState.RUNNING).rawState( "running").instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName( @@ -101,7 +101,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { "10-251-50-132.ec2.internal")// product codes // ImmutableSet.of("774F4FF8") .ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE).build(), - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("23") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("23") .dnsName("ec2-72-44-33-6.compute-1.amazonaws.com").imageId("ami-6ea54007").instanceId( "i-28a64435").instanceState(InstanceState.RUNNING).rawState("running") .instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName( @@ -116,7 +116,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> result = parseRunningInstances("/describe_instances.xml"); - assertEquals(result, contents); + assertEquals(result.toString(), contents.toString()); assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING); assertEquals(get(get(result, 0), 0).getRawState(), "running"); @@ -126,7 +126,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> contents = ImmutableSet.of(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), ImmutableSet.of(new RunningInstance.Builder().region( - defaultRegion).groupId("adriancole.ec2ebsingress").amiLaunchIndex("0").dnsName( + defaultRegion).groupName("adriancole.ec2ebsingress").amiLaunchIndex("0").dnsName( "ec2-75-101-203-146.compute-1.amazonaws.com").imageId("ami-849875ed").instanceId("i-e564438d") .instanceState(InstanceState.RUNNING).rawState("running").instanceType(InstanceType.M1_SMALL) .ipAddress("75.101.203.146").kernelId("aki-a71cf9ce") @@ -145,7 +145,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> result = parseRunningInstances("/describe_instances_ebs.xml"); - assertEquals(result, contents); + assertEquals(result.toString(), contents.toString()); assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING); assertEquals(get(get(result, 0), 0).getRawState(), "running"); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java index 0b23ebf203..1b37c5396e 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java @@ -65,19 +65,19 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { Reservation expected = new Reservation(defaultRegion, ImmutableSet .of("default"), ImmutableSet.of( - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("0") .imageId("ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, .availabilityZone("us-east-1b").build(), - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("1") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("1") .imageId("ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, .availabilityZone("us-east-1b").build(), - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("2") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("2") .imageId("ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, @@ -96,9 +96,9 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { InputStream is = getClass().getResourceAsStream("/run_instances_cloudbridge.xml"); Reservation expected = new Reservation(defaultRegion, ImmutableSet - .of("default"), ImmutableSet.of( + .of("jclouds#greenqloud-computeblock"), ImmutableSet.of( - new RunningInstance.Builder().region(defaultRegion).groupId("jclouds#greenqloud-computeblock").amiLaunchIndex("0") + new RunningInstance.Builder().region(defaultRegion).groupName("jclouds#greenqloud-computeblock").amiLaunchIndex("0") .imageId("qmi-9ac92558").instanceId("i-01b0dac3").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("jclouds#greenqloud-computeblock#35") .launchTime(dateService.iso8601DateParse("2012-06-15T19:06:35.000+00:00")) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java index 9cb43cb319..06605b208f 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java @@ -31,7 +31,7 @@ import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -241,13 +241,13 @@ public class AWSRunningInstance extends RunningInstance { } @Override - public Builder groupId(String groupId) { - return Builder.class.cast(super.groupId(groupId)); + public Builder groupName(String groupName) { + return Builder.class.cast(super.groupName(groupName)); } @Override - public Builder groupIds(Iterable groupIds) { - return Builder.class.cast(super.groupIds(groupIds)); + public Builder groupNames(Iterable groupNames) { + return Builder.class.cast(super.groupNames(groupNames)); } @Override @@ -364,74 +364,10 @@ public class AWSRunningInstance extends RunningInstance { } @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((placementGroup == null) ? 0 : placementGroup.hashCode()); - result = prime * result + ((productCodes == null) ? 0 : productCodes.hashCode()); - result = prime * result + ((spotInstanceRequestId == null) ? 0 : spotInstanceRequestId.hashCode()); - result = prime * result + ((subnetId == null) ? 0 : subnetId.hashCode()); - result = prime * result + ((vpcId == null) ? 0 : vpcId.hashCode()); - result = prime * result + ((hypervisor == null) ? 0 : hypervisor.hashCode()); - result = prime * result + ((tags == null) ? 0 : tags.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; - AWSRunningInstance other = (AWSRunningInstance) obj; - if (placementGroup == null) { - if (other.placementGroup != null) - return false; - } else if (!placementGroup.equals(other.placementGroup)) - return false; - if (productCodes == null) { - if (other.productCodes != null) - return false; - } else if (!productCodes.equals(other.productCodes)) - return false; - if (spotInstanceRequestId == null) { - if (other.spotInstanceRequestId != null) - return false; - } else if (!spotInstanceRequestId.equals(other.spotInstanceRequestId)) - return false; - if (subnetId == null) { - if (other.subnetId != null) - return false; - } else if (!subnetId.equals(other.subnetId)) - return false; - if (vpcId == null) { - if (other.vpcId != null) - return false; - } else if (!vpcId.equals(other.vpcId)) - return false; - if (tags == null) { - if (other.tags != null) - return false; - } else if (!tags.equals(other.tags)) - return false; - if (!Objects.equal(hypervisor, other.hypervisor)) - return false; - return true; - } - - @Override - public String toString() { - return "[region=" + region + ", availabilityZone=" + availabilityZone + ", instanceId=" + instanceId - + ", instanceState=" + rawState + ", instanceType=" + instanceType + ", virtualizationType=" - + virtualizationType + ", imageId=" + imageId + ", ipAddress=" + ipAddress + ", dnsName=" + dnsName - + ", privateIpAddress=" + privateIpAddress + ", privateDnsName=" + privateDnsName + ", keyName=" - + keyName + ", platform=" + platform + ", launchTime=" + launchTime + ", rootDeviceName=" - + rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", ebsBlockDevices=" + ebsBlockDevices - + ", monitoringState=" + monitoringState + ", placementGroup=" + placementGroup + ", productCodes=" - + productCodes + ", spotInstanceRequestId=" + spotInstanceRequestId + ", subnetId=" + subnetId - + ", hypervisor=" + hypervisor + ", vpcId=" + vpcId + ", tags=" + tags + "]"; + protected ToStringHelper string() { + return super.string().add("monitoringState", monitoringState).add("placementGroup", placementGroup) + .add("subnetId", subnetId).add("spotInstanceRequestId", spotInstanceRequestId).add("vpcId", vpcId) + .add("hypervisor", hypervisor).add("tags", tags); } } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java index 5c7fe7d352..854000b8d1 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java @@ -52,7 +52,7 @@ public class SpotInstanceRequestToAWSRunningInstance implements Function of("jclouds#" + group, group)); + assertEquals(newTreeSet(instance.getGroupNames()), ImmutableSortedSet. of("jclouds#" + group, group)); // make sure our dummy group has no rules SecurityGroup secgroup = getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(instance diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java index 9d52e60397..3a2fc7726c 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java @@ -117,8 +117,8 @@ public class IncidentalResourcesGetCleanedUpLiveTest extends BaseComputeServiceC assertNotNull(instance1.getKeyName()); assertEquals(instance1.getRegion(), instance2.getRegion(), "Nodes are not in the same region"); assertEquals(instance1.getKeyName(), instance2.getKeyName(), "Nodes do not have same key-pair name"); - assertEquals(instance1.getGroupIds(), instance2.getGroupIds(), "Nodes are not in the same group"); - assertEquals(instance1.getGroupIds(), ImmutableSet.of(expectedSecurityGroupName), "Nodes are not in the expected security group"); + assertEquals(instance1.getGroupNames(), instance2.getGroupNames(), "Nodes are not in the same group"); + assertEquals(instance1.getGroupNames(), ImmutableSet.of(expectedSecurityGroupName), "Nodes are not in the expected security group"); // Assert a single key-pair and security group has been created String expectedKeyPairName = instance1.getKeyName(); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java index 4324994036..76c1ce9df7 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java @@ -66,7 +66,7 @@ public class SpotInstanceRequestToAWSRunningInstanceTest { AWSRunningInstance.builder().region("us-east-1").instanceId("sir-228e6406") .spotInstanceRequestId("sir-228e6406").instanceState(InstanceState.PENDING) .rawState("open").imageId("ami-595a0a1c") - .groupId("default").instanceType("m1.large") + .groupName("default").instanceType("m1.large") .tag("foo", "bar") .tag("empty", "") .hypervisor(Hypervisor.XEN) diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java new file mode 100644 index 0000000000..646853fcfd --- /dev/null +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java @@ -0,0 +1,114 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.ec2.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Set; + +import org.jclouds.aws.ec2.domain.AWSRunningInstance; +import org.jclouds.aws.ec2.domain.MonitoringState; +import org.jclouds.aws.ec2.xml.AWSDescribeInstancesResponseHandler; +import org.jclouds.date.DateService; +import org.jclouds.ec2.domain.Attachment; +import org.jclouds.ec2.domain.BlockDevice; +import org.jclouds.ec2.domain.Hypervisor; +import org.jclouds.ec2.domain.InstanceState; +import org.jclouds.ec2.domain.Reservation; +import org.jclouds.ec2.domain.RootDeviceType; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.ec2.xml.BaseEC2HandlerTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code AWSDescribeInstancesResponseHandler} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "AWSDescribeInstancesResponseHandlerTest") +public class DescribeInstancesResponseTest extends BaseEC2HandlerTest { + + private DateService dateService; + + @BeforeTest + @Override + protected void setUpInjector() { + super.setUpInjector(); + dateService = injector.getInstance(DateService.class); + assert dateService != null; + } + + public void test() { + InputStream is = getClass().getResourceAsStream("/describe_instances_pending.xml"); + + Set> expected = expected(); + + AWSDescribeInstancesResponseHandler handler = injector.getInstance(AWSDescribeInstancesResponseHandler.class); + Set> result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public Set> expected() { + return ImmutableSet.of(Reservation.builder() + .region(defaultRegion) + .reservationId("r-3f056a58") + .ownerId("095072994936") +// sg-f788299f + .groupName("launchpad_sec_group") +// sg-7e512116 + .groupName("jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae") + .instance(AWSRunningInstance.builder() + .region(defaultRegion) + .instanceId("i-32451248") + .imageId("ami-bf8131d6") + .rawState("pending") + .instanceState(InstanceState.PENDING) + .privateDnsName("ip-10-194-149-220.ec2.internal") + .dnsName("ec2-23-20-17-42.compute-1.amazonaws.com") + .keyName("jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae#105") + .amiLaunchIndex("0") + .instanceType("c1.medium") + .launchTime(dateService.iso8601DateParse("2012-09-14T20:01:34.000Z")) + .availabilityZone("us-east-1d") +// .tenancy("default") + .kernelId("aki-825ea7eb") + .monitoringState(MonitoringState.DISABLED) + .privateIpAddress("10.194.149.220") + .ipAddress("23.20.17.42") + .securityGroupIdToName("sg-f788299f", "launchpad_sec_group") + .securityGroupIdToName("sg-7e512116", "jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae") +// .architecture("x86_64") + .rootDeviceType(RootDeviceType.EBS) + .rootDeviceName("/dev/sda1") + .device("/dev/sda1", new BlockDevice("vol-b2beb3c9", Attachment.Status.ATTACHING, dateService.iso8601DateParse("2012-09-14T20:01:37.000Z"), true)) + .virtualizationType("paravirtual") + .tag("Name", "4c858090-f66c-4225-aa57-6fcaa42198ae-32451248") + .hypervisor(Hypervisor.XEN) + .build()).build()); + } + +} diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java index 25aa26bc7c..c247bf23a0 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java @@ -31,7 +31,6 @@ import org.jclouds.ec2.domain.Attachment; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.Hypervisor; import org.jclouds.ec2.domain.InstanceState; -import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; @@ -71,44 +70,13 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest assert dateService != null; } - public void testWhenRunning() throws UnknownHostException { - - Set> contents = ImmutableSet.of( - new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of( - new AWSRunningInstance.Builder() - .region(defaultRegion) - .groupId("adriancole.ec2ingress") - .amiLaunchIndex("0") - .dnsName("ec2-174-129-81-68.compute-1.amazonaws.com") - .imageId("ami-82e4b5c7") - .instanceId("i-0799056f") - .instanceState(InstanceState.RUNNING) - .rawState("running") - .instanceType(InstanceType.M1_SMALL) - .ipAddress("174.129.81.68") - .kernelId("aki-a71cf9ce") - .keyName("adriancole.ec21") - .launchTime(dateService.iso8601DateParse("2009-11-09T03:00:34.000Z")) - .monitoringState(MonitoringState.DISABLED) - .availabilityZone("us-east-1c") - .virtualizationType("paravirtual") - .privateDnsName("ip-10-243-42-70.ec2.internal") - .privateIpAddress("10.243.42.70") - .ramdiskId("ari-a51cf9cc") - .rootDeviceType(RootDeviceType.INSTANCE_STORE) - .hypervisor(Hypervisor.XEN) - .build()), - "993194456877", null, "r-a3c508cb")); - - Set> result = parseAWSRunningInstances("/describe_instances_running.xml"); - - assertEquals(result.toString(), contents.toString()); - } public void testWhenRunningLatest() throws UnknownHostException { - Set> contents = ImmutableSet.of(new Reservation( - defaultRegion, ImmutableSet.of("jclouds#ec2-s#us-east-1"), ImmutableSet.of( - new AWSRunningInstance.Builder() + Set> contents = ImmutableSet.of(Reservation.builder() + .region(defaultRegion) + .reservationId("r-0f4c2160") + .groupName("jclouds#zkclustertest#us-east-1") + .instance(AWSRunningInstance.builder() .region(defaultRegion) .instanceId("i-911444f0") .imageId("ami-63be790a") @@ -135,8 +103,8 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest new BlockDevice("vol-5829fc32", Attachment.Status.ATTACHED, dateService .iso8601DateParse("2011-08-16T13:41:19.000Z"), true)) .hypervisor(Hypervisor.XEN) - .virtualizationType("paravirtual").build(),// - new AWSRunningInstance.Builder() + .virtualizationType("paravirtual").build()) + .instance(AWSRunningInstance.builder() .region(defaultRegion) .instanceId("i-931444f2") .imageId("ami-63be790a") @@ -162,7 +130,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest new BlockDevice("vol-5029fc3a", Attachment.Status.ATTACHED, dateService .iso8601DateParse("2011-08-16T13:41:19.000Z"), true)) .hypervisor(Hypervisor.XEN) - .virtualizationType("paravirtual").build()), defaultRegion, defaultRegion, defaultRegion)); + .virtualizationType("paravirtual").build()).build()); Set> result = parseAWSRunningInstances("/describe_instances_latest.xml"); @@ -175,76 +143,6 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest parseAWSRunningInstances("/describe_instances_3.xml"); } - public void testApplyInputStream() { - Set> contents = ImmutableSet.of(new Reservation( - defaultRegion, ImmutableSet.of("default"), ImmutableSet.of( - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("23") - .dnsName("ec2-72-44-33-4.compute-1.amazonaws.com").imageId("ami-6ea54007") - .instanceId("i-28a64341").instanceState(InstanceState.RUNNING).rawState("running") - .instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name") - .launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")) - .monitoringState(MonitoringState.DISABLED).availabilityZone("us-east-1b") - .virtualizationType("paravirtual").privateDnsName("10-251-50-132.ec2.internal") - .productCode("774F4FF8").ramdiskId("ari-badbad00") - .hypervisor(Hypervisor.XEN) - .rootDeviceType(RootDeviceType.INSTANCE_STORE).build(), - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("23") - .dnsName("ec2-72-44-33-6.compute-1.amazonaws.com").imageId("ami-6ea54007") - .instanceId("i-28a64435").instanceState(InstanceState.RUNNING).rawState("running") - .instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name") - .launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")) - .monitoringState(MonitoringState.DISABLED).availabilityZone("us-east-1b") - .virtualizationType("paravirtual").privateDnsName("10-251-50-134.ec2.internal") - .productCode("774F4FF8").ramdiskId("ari-badbad00") - .hypervisor(Hypervisor.XEN) - .rootDeviceType(RootDeviceType.INSTANCE_STORE).build()), "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", - null, "r-44a5402d")); - - Set> result = parseAWSRunningInstances("/describe_instances.xml"); - - assertEquals(result.toString(), contents.toString()); - } - - public void testEBS() throws UnknownHostException { - - Set> contents = ImmutableSet.of(new Reservation( - defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), ImmutableSet - .of(new AWSRunningInstance.Builder() - .region(defaultRegion) - .groupId("adriancole.ec2ebsingress") - .amiLaunchIndex("0") - .dnsName("ec2-75-101-203-146.compute-1.amazonaws.com") - .imageId("ami-849875ed") - .instanceId("i-e564438d") - .instanceState(InstanceState.RUNNING) - .rawState("running") - .instanceType(InstanceType.M1_SMALL) - .ipAddress("75.101.203.146") - .kernelId("aki-a71cf9ce") - .keyName("adriancole.ec2ebs1") - .launchTime(dateService.iso8601DateParse("2009-12-30T04:06:23.000Z")) - .monitoringState(MonitoringState.DISABLED) - .availabilityZone("us-east-1b") - .placementGroup("placement") - .virtualizationType("hvm") - .privateDnsName("domU-12-31-39-09-CE-53.compute-1.internal") - .privateIpAddress("10.210.209.157") - .ramdiskId("ari-a51cf9cc") - .hypervisor(Hypervisor.XEN) - .rootDeviceType(RootDeviceType.EBS) - .rootDeviceName("/dev/sda1") - .hypervisor(Hypervisor.XEN) - .device( - "/dev/sda1", - new BlockDevice("vol-dc6ca8b5", Attachment.Status.ATTACHED, dateService - .iso8601DateParse("2009-12-30T04:06:29.000Z"), true)).build()), "993194456877", - null, "r-596dd731")); - - Set> result = parseAWSRunningInstances("/describe_instances_ebs.xml"); - - assertEquals(result.toString(), contents.toString()); - } - static ParseSax>> createParser() { Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java index 09547f97e9..73d4a37eaa 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java @@ -44,7 +44,6 @@ 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.ImmutableSet; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.TypeLiteral; @@ -82,28 +81,25 @@ public class AWSRunInstancesResponseHandlerTest extends BaseEC2HandlerTest { InputStream is = getClass().getResourceAsStream("/run_instances.xml"); - Reservation expected = new Reservation(defaultRegion, - ImmutableSet.of("default"), ImmutableSet.of( - - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0").imageId( + Reservation expected = Reservation.builder() + .region(defaultRegion) + .instance(AWSRunningInstance.builder().region(defaultRegion).groupName("default").amiLaunchIndex("0").imageId( "ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).hypervisor(Hypervisor.XEN) - .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build(), - - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("1").imageId( + .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) + .instance(AWSRunningInstance.builder().region(defaultRegion).groupName("default").amiLaunchIndex("1").imageId( "ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).hypervisor(Hypervisor.XEN) - .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build(), - - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("2").imageId( + .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) + .instance(AWSRunningInstance.builder().region(defaultRegion).groupName("default").amiLaunchIndex("2").imageId( "ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).hypervisor(Hypervisor.XEN) .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) - - , "AIDADH4IGTRXXKCD", null, "r-47a5402e"); + .ownerId("AIDADH4IGTRXXKCD") + .reservationId("r-47a5402e").build(); AWSRunInstancesResponseHandler handler = injector.getInstance(AWSRunInstancesResponseHandler.class); addDefaultRegionToHandler(handler); diff --git a/providers/aws-ec2/src/test/resources/describe_instances_pending.xml b/providers/aws-ec2/src/test/resources/describe_instances_pending.xml new file mode 100644 index 0000000000..92f9f4ebe4 --- /dev/null +++ b/providers/aws-ec2/src/test/resources/describe_instances_pending.xml @@ -0,0 +1,82 @@ + + + dcd37ecf-e5b6-462b-99a8-112427b3e3a2 + + + r-3f056a58 + 095072994936 + + + sg-f788299f + launchpad_sec_group + + + sg-7e512116 + jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae + + + + + i-32451248 + ami-bf8131d6 + + 0 + pending + + ip-10-194-149-220.ec2.internal + ec2-23-20-17-42.compute-1.amazonaws.com + + jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae#105 + 0 + + c1.medium + 2012-09-14T20:01:34.000Z + + us-east-1d + + default + + aki-825ea7eb + + disabled + + 10.194.149.220 + 23.20.17.42 + + + sg-f788299f + launchpad_sec_group + + + sg-7e512116 + jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae + + + x86_64 + ebs + /dev/sda1 + + + /dev/sda1 + + vol-b2beb3c9 + attaching + 2012-09-14T20:01:37.000Z + true + + + + paravirtual + + + + Name + 4c858090-f66c-4225-aa57-6fcaa42198ae-32451248 + + + xen + + + + + \ No newline at end of file From 49877c8f06cbafa6d00e6525f089ca2e13bc26d4 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 23:43:50 -0700 Subject: [PATCH 26/60] helpers for empty collections --- .../jclouds/collect/IterableWithMarkers.java | 4 + .../org/jclouds/collect/PagedIterables.java | 11 +++ .../org/jclouds/json/config/GsonModule.java | 17 ++-- ...eNullFluentIterableTypeAdapterFactory.java | 78 +++++++++++++++++++ .../IgnoreNullIterableTypeAdapterFactory.java | 77 ++++++++++++++++++ ...urnEmptyFluentIterableOnNotFoundOr404.java | 59 ++++++++++++++ ...mptyIterableWithMarkerOnNotFoundOr404.java | 58 ++++++++++++++ .../ReturnEmptyListOnNotFoundOr404.java | 2 - .../ReturnEmptyMapOnNotFoundOr404.java | 2 - .../ReturnEmptyMultimapOnNotFoundOr404.java | 1 - ...turnEmptyPagedIterableOnNotFoundOr404.java | 58 ++++++++++++++ .../ReturnEmptySetOnNotFoundOr404.java | 2 - 12 files changed, 357 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java create mode 100644 core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java create mode 100644 core/src/main/java/org/jclouds/rest/functions/ReturnEmptyFluentIterableOnNotFoundOr404.java create mode 100644 core/src/main/java/org/jclouds/rest/functions/ReturnEmptyIterableWithMarkerOnNotFoundOr404.java create mode 100644 core/src/main/java/org/jclouds/rest/functions/ReturnEmptyPagedIterableOnNotFoundOr404.java diff --git a/core/src/main/java/org/jclouds/collect/IterableWithMarkers.java b/core/src/main/java/org/jclouds/collect/IterableWithMarkers.java index f84211281c..bcb1f5caeb 100644 --- a/core/src/main/java/org/jclouds/collect/IterableWithMarkers.java +++ b/core/src/main/java/org/jclouds/collect/IterableWithMarkers.java @@ -26,6 +26,7 @@ import org.jclouds.javax.annotation.Nullable; import com.google.common.annotations.Beta; import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; /** * Utilities for using {@link IterableWithMarker}s. @@ -34,6 +35,9 @@ import com.google.common.base.Optional; */ @Beta public class IterableWithMarkers { + + @SuppressWarnings("rawtypes") + public static final IterableWithMarker EMPTY = from(ImmutableSet.of()); /** * Returns a paginated iterable containing the given elements and null marker. diff --git a/core/src/main/java/org/jclouds/collect/PagedIterables.java b/core/src/main/java/org/jclouds/collect/PagedIterables.java index b98c03865d..87988bc7be 100644 --- a/core/src/main/java/org/jclouds/collect/PagedIterables.java +++ b/core/src/main/java/org/jclouds/collect/PagedIterables.java @@ -35,6 +35,17 @@ import com.google.common.collect.ImmutableSet; */ @Beta public class PagedIterables { + + @SuppressWarnings("rawtypes") + public static final PagedIterable EMPTY = new PagedIterable() { + + @Override + public Iterator iterator() { + return ImmutableSet.of(IterableWithMarkers.EMPTY).iterator(); + } + + }; + /** * @param only * the only page of data diff --git a/core/src/main/java/org/jclouds/json/config/GsonModule.java b/core/src/main/java/org/jclouds/json/config/GsonModule.java index 8d273c54ce..b0d1e35661 100644 --- a/core/src/main/java/org/jclouds/json/config/GsonModule.java +++ b/core/src/main/java/org/jclouds/json/config/GsonModule.java @@ -39,6 +39,8 @@ import org.jclouds.json.Json; import org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory; import org.jclouds.json.internal.EnumTypeAdapterThatReturnsFromValue; import org.jclouds.json.internal.GsonWrapper; +import org.jclouds.json.internal.IgnoreNullFluentIterableTypeAdapterFactory; +import org.jclouds.json.internal.IgnoreNullIterableTypeAdapterFactory; import org.jclouds.json.internal.IgnoreNullMapTypeAdapterFactory; import org.jclouds.json.internal.IgnoreNullMultimapTypeAdapterFactory; import org.jclouds.json.internal.IgnoreNullSetTypeAdapterFactory; @@ -81,7 +83,10 @@ public class GsonModule extends AbstractModule { @Provides @Singleton Gson provideGson(TypeAdapter jsonAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter, - ByteArrayAdapter byteArrayAdapter, PropertiesAdapter propertiesAdapter, JsonAdapterBindings bindings) + ByteArrayAdapter byteArrayAdapter, PropertiesAdapter propertiesAdapter, JsonAdapterBindings bindings, + OptionalTypeAdapterFactory optional, IgnoreNullSetTypeAdapterFactory set, + IgnoreNullMapTypeAdapterFactory map, IgnoreNullMultimapTypeAdapterFactory multimap, + IgnoreNullIterableTypeAdapterFactory iterable, IgnoreNullFluentIterableTypeAdapterFactory fluentIterable) throws Exception { FieldNamingStrategy serializationPolicy = new AnnotationOrNameFieldNamingStrategy(new ExtractSerializedName(), @@ -96,10 +101,12 @@ public class GsonModule extends AbstractModule { }.getType(), byteListAdapter.nullSafe()); builder.registerTypeAdapter(byte[].class, byteArrayAdapter.nullSafe()); builder.registerTypeAdapter(JsonBall.class, jsonAdapter.nullSafe()); - builder.registerTypeAdapterFactory(new OptionalTypeAdapterFactory()); - builder.registerTypeAdapterFactory(new IgnoreNullSetTypeAdapterFactory()); - builder.registerTypeAdapterFactory(new IgnoreNullMapTypeAdapterFactory()); - builder.registerTypeAdapterFactory(new IgnoreNullMultimapTypeAdapterFactory()); + builder.registerTypeAdapterFactory(optional); + builder.registerTypeAdapterFactory(set); + builder.registerTypeAdapterFactory(map); + builder.registerTypeAdapterFactory(multimap); + builder.registerTypeAdapterFactory(iterable); + builder.registerTypeAdapterFactory(fluentIterable); AnnotationConstructorNamingStrategy deserializationPolicy = new AnnotationConstructorNamingStrategy( diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java new file mode 100644 index 0000000000..ad5d9a15b1 --- /dev/null +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.json.internal; + +import java.io.IOException; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +/** + * Eliminates null values when deserializing FluentIterables + *

+ * Treats [null] as the empty set; [A, null] as [A]; etc. + * + * @author Adam Lowe + */ +public class IgnoreNullFluentIterableTypeAdapterFactory implements TypeAdapterFactory { + + @SuppressWarnings("unchecked") + public TypeAdapter create(Gson gson, TypeToken typeToken) { + Type type = typeToken.getType(); + if (typeToken.getRawType() != FluentIterable.class || !(type instanceof ParameterizedType)) { + return null; + } + + Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; + TypeAdapter elementAdapter = gson.getAdapter(TypeToken.get(elementType)); + return (TypeAdapter) newFluentIterableAdapter(elementAdapter); + } + + private TypeAdapter> newFluentIterableAdapter(final TypeAdapter elementAdapter) { + return new TypeAdapter>() { + public void write(JsonWriter out, FluentIterable value) throws IOException { + out.beginArray(); + for (E element : value) { + elementAdapter.write(out, element); + } + out.endArray(); + } + + public FluentIterable read(JsonReader in) throws IOException { + in.beginArray(); + Builder builder = ImmutableList.builder(); + while (in.hasNext()) { + E element = elementAdapter.read(in); + if (element != null) builder.add(element); + } + in.endArray(); + return FluentIterable.from(builder.build()); + } + }.nullSafe(); + } +} diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java new file mode 100644 index 0000000000..34ca42d2d3 --- /dev/null +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.json.internal; + +import java.io.IOException; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +/** + * Eliminates null values when deserializing Iterables + *

+ * Treats [null] as the empty set; [A, null] as [A]; etc. + * + * @author Adam Lowe + */ +public class IgnoreNullIterableTypeAdapterFactory implements TypeAdapterFactory { + + @SuppressWarnings("unchecked") + public TypeAdapter create(Gson gson, TypeToken typeToken) { + Type type = typeToken.getType(); + if (typeToken.getRawType() != Iterable.class || !(type instanceof ParameterizedType)) { + return null; + } + + Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; + TypeAdapter elementAdapter = gson.getAdapter(TypeToken.get(elementType)); + return (TypeAdapter) newIterableAdapter(elementAdapter); + } + + private TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { + return new TypeAdapter>() { + public void write(JsonWriter out, Iterable value) throws IOException { + out.beginArray(); + for (E element : value) { + elementAdapter.write(out, element); + } + out.endArray(); + } + + public Iterable read(JsonReader in) throws IOException { + in.beginArray(); + Builder builder = ImmutableList.builder(); + while (in.hasNext()) { + E element = elementAdapter.read(in); + if (element != null) builder.add(element); + } + in.endArray(); + return builder.build(); + } + }.nullSafe(); + } +} diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyFluentIterableOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyFluentIterableOnNotFoundOr404.java new file mode 100644 index 0000000000..b2711c5109 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyFluentIterableOnNotFoundOr404.java @@ -0,0 +1,59 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rest.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.functions.ReturnTrueOn404; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ReturnEmptyFluentIterableOnNotFoundOr404 implements Function { + private final ReturnTrueOn404 rto404; + + @Inject + private ReturnEmptyFluentIterableOnNotFoundOr404(ReturnTrueOn404 rto404) { + this.rto404 = checkNotNull(rto404, "rto404"); + } + + public Object apply(Exception from) { + Iterable throwables = Iterables.filter(Throwables.getCausalChain(from), + ResourceNotFoundException.class); + if (Iterables.size(throwables) >= 1) { + return FluentIterable.from(ImmutableSet.of()); + } else if (rto404.apply(from)) { + return FluentIterable.from(ImmutableSet.of()); + } + throw Throwables.propagate(from); + } + +} diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyIterableWithMarkerOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyIterableWithMarkerOnNotFoundOr404.java new file mode 100644 index 0000000000..ff5cbeafd6 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyIterableWithMarkerOnNotFoundOr404.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rest.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarkers; +import org.jclouds.http.functions.ReturnTrueOn404; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ReturnEmptyIterableWithMarkerOnNotFoundOr404 implements Function { + private final ReturnTrueOn404 rto404; + + @Inject + private ReturnEmptyIterableWithMarkerOnNotFoundOr404(ReturnTrueOn404 rto404) { + this.rto404 = checkNotNull(rto404, "rto404"); + } + + public Object apply(Exception from) { + Iterable throwables = Iterables.filter(Throwables.getCausalChain(from), + ResourceNotFoundException.class); + if (Iterables.size(throwables) >= 1) { + return IterableWithMarkers.EMPTY; + } else if (rto404.apply(from)) { + return IterableWithMarkers.EMPTY; + } + throw Throwables.propagate(from); + } + +} diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyListOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyListOnNotFoundOr404.java index e7ad30afcd..46ed693cb7 100644 --- a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyListOnNotFoundOr404.java +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyListOnNotFoundOr404.java @@ -20,8 +20,6 @@ package org.jclouds.rest.functions; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; - import javax.inject.Inject; import javax.inject.Singleton; diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMapOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMapOnNotFoundOr404.java index 156abab47f..50f37c9e8d 100644 --- a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMapOnNotFoundOr404.java +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMapOnNotFoundOr404.java @@ -20,8 +20,6 @@ package org.jclouds.rest.functions; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; - import javax.inject.Inject; import javax.inject.Singleton; diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMultimapOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMultimapOnNotFoundOr404.java index 763190cce4..9f365d1627 100644 --- a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMultimapOnNotFoundOr404.java +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyMultimapOnNotFoundOr404.java @@ -30,7 +30,6 @@ import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; /** * diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyPagedIterableOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyPagedIterableOnNotFoundOr404.java new file mode 100644 index 0000000000..48905ab413 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptyPagedIterableOnNotFoundOr404.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rest.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.PagedIterables; +import org.jclouds.http.functions.ReturnTrueOn404; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ReturnEmptyPagedIterableOnNotFoundOr404 implements Function { + private final ReturnTrueOn404 rto404; + + @Inject + private ReturnEmptyPagedIterableOnNotFoundOr404(ReturnTrueOn404 rto404) { + this.rto404 = checkNotNull(rto404, "rto404"); + } + + public Object apply(Exception from) { + Iterable throwables = Iterables.filter(Throwables.getCausalChain(from), + ResourceNotFoundException.class); + if (Iterables.size(throwables) >= 1) { + return PagedIterables.EMPTY; + } else if (rto404.apply(from)) { + return PagedIterables.EMPTY; + } + throw Throwables.propagate(from); + } + +} diff --git a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptySetOnNotFoundOr404.java b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptySetOnNotFoundOr404.java index cdd6615f17..b8be87efba 100644 --- a/core/src/main/java/org/jclouds/rest/functions/ReturnEmptySetOnNotFoundOr404.java +++ b/core/src/main/java/org/jclouds/rest/functions/ReturnEmptySetOnNotFoundOr404.java @@ -20,8 +20,6 @@ package org.jclouds.rest.functions; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Set; - import javax.inject.Inject; import javax.inject.Singleton; From 3b3efef104819ef3adb3c23fb67a10799b30e39a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 23:45:14 -0700 Subject: [PATCH 27/60] cleaned up fgcp --- .../fujitsu/fgcp/FGCPAUProviderMetadata.java | 77 +-- .../fujitsu/fgcp/FGCPAUProviderTest.java | 2 +- .../FGCPAUTemplateBuilderLiveTest.java | 16 +- .../config/FGCPAUComputeServiceLiveTest.java | 8 +- .../fujitsu/fgcp/FGCPDEProviderMetadata.java | 76 +-- .../fujitsu/fgcp/FGCPDEProviderTest.java | 2 +- .../FGCPDETemplateBuilderLiveTest.java | 16 +- .../config/FGCPDEComputeServiceLiveTest.java | 8 +- .../org/jclouds/fujitsu/fgcp/FGCPApi.java | 36 +- .../jclouds/fujitsu/fgcp/FGCPApiMetadata.java | 99 ++-- .../jclouds/fujitsu/fgcp/FGCPAsyncApi.java | 38 +- .../fujitsu/fgcp/FGCPProviderMetadata.java | 32 +- .../fgcp/binders/BindAlsoToSystemId.java | 48 +- .../fgcp/compute/FGCPRestClientModule.java | 520 +++++++++--------- .../FGCPComputeServiceContextModule.java | 144 ++--- .../compute/functions/CPUToProcessor.java | 17 +- .../compute/functions/DiskImageToImage.java | 56 +- .../functions/DiskImageToOperatingSystem.java | 54 +- .../fgcp/compute/functions/DiskToVolume.java | 29 +- .../functions/ResourceIdToFirewallId.java | 22 +- .../functions/ResourceIdToSystemId.java | 18 +- .../functions/ServerTypeToHardware.java | 44 +- .../SingleElementResponseToElement.java | 10 +- .../VServerMetadataToNodeMetadata.java | 312 +++++------ .../compute/predicates/ServerStopped.java | 34 +- .../predicates/SystemStatusNormal.java | 33 +- .../strategy/FGCPComputeServiceAdapter.java | 401 +++++++------- .../compute/strategy/VServerMetadata.java | 228 ++++---- .../fujitsu/fgcp/domain/AddressRange.java | 42 +- .../fujitsu/fgcp/domain/BuiltinServer.java | 64 +-- .../fgcp/domain/BuiltinServerBackup.java | 72 +-- .../domain/BuiltinServerConfiguration.java | 56 +- .../fgcp/domain/BuiltinServerStatus.java | 38 +- .../org/jclouds/fujitsu/fgcp/domain/CPU.java | 76 +-- .../jclouds/fujitsu/fgcp/domain/Cause.java | 112 ++-- .../fujitsu/fgcp/domain/Direction.java | 136 ++--- .../org/jclouds/fujitsu/fgcp/domain/Disk.java | 84 +-- .../fujitsu/fgcp/domain/DiskImage.java | 252 ++++----- .../fujitsu/fgcp/domain/ErrorStatistics.java | 30 +- .../jclouds/fujitsu/fgcp/domain/EventLog.java | 118 ++-- .../jclouds/fujitsu/fgcp/domain/Firewall.java | 170 +++--- .../jclouds/fujitsu/fgcp/domain/Group.java | 308 +++++------ .../jclouds/fujitsu/fgcp/domain/Image.java | 118 ++-- .../fujitsu/fgcp/domain/Information.java | 134 ++--- .../fgcp/domain/IntermediateCACert.java | 144 ++--- .../fujitsu/fgcp/domain/LoadStatistics.java | 56 +- .../jclouds/fujitsu/fgcp/domain/Memory.java | 58 +- .../org/jclouds/fujitsu/fgcp/domain/NAT.java | 56 +- .../fujitsu/fgcp/domain/PerformanceInfo.java | 206 +++---- .../jclouds/fujitsu/fgcp/domain/Period.java | 56 +- .../jclouds/fujitsu/fgcp/domain/Policy.java | 268 ++++----- .../jclouds/fujitsu/fgcp/domain/Product.java | 90 +-- .../jclouds/fujitsu/fgcp/domain/PublicIP.java | 92 ++-- .../fujitsu/fgcp/domain/PublicIPStatus.java | 38 +- .../org/jclouds/fujitsu/fgcp/domain/Rule.java | 88 +-- .../org/jclouds/fujitsu/fgcp/domain/SLB.java | 258 ++++----- .../fujitsu/fgcp/domain/ServerCert.java | 146 ++--- .../fujitsu/fgcp/domain/ServerType.java | 158 +++--- .../jclouds/fujitsu/fgcp/domain/Software.java | 112 ++-- .../jclouds/fujitsu/fgcp/domain/Target.java | 158 +++--- .../fujitsu/fgcp/domain/UsageInfo.java | 98 ++-- .../jclouds/fujitsu/fgcp/domain/VDisk.java | 88 +-- .../fujitsu/fgcp/domain/VDiskStatus.java | 38 +- .../org/jclouds/fujitsu/fgcp/domain/VNIC.java | 66 +-- .../org/jclouds/fujitsu/fgcp/domain/VNet.java | 48 +- .../jclouds/fujitsu/fgcp/domain/VServer.java | 88 +-- .../fujitsu/fgcp/domain/VServerStatus.java | 38 +- .../fgcp/domain/VServerWithDetails.java | 36 +- .../fujitsu/fgcp/domain/VServerWithVNICs.java | 26 +- .../jclouds/fujitsu/fgcp/domain/VSystem.java | 90 +-- .../fgcp/domain/VSystemDescriptor.java | 108 ++-- .../fujitsu/fgcp/domain/VSystemStatus.java | 38 +- .../fgcp/domain/VSystemWithDetails.java | 72 +-- .../fujitsu/fgcp/domain/package-info.java | 2 +- .../fgcp/filters/RequestAuthenticator.java | 285 +++++----- ...fNotProxyAuthenticationFailureHandler.java | 25 +- .../fgcp/http/SSLContextWithKeysSupplier.java | 40 +- ...emAndNetworkSegmentToLocationSupplier.java | 92 ++-- .../fgcp/reference/RequestParameters.java | 90 +-- .../fgcp/services/AdditionalDiskApi.java | 19 +- .../fgcp/services/AdditionalDiskAsyncApi.java | 91 ++- .../fgcp/services/BuiltinServerApi.java | 34 +- .../fgcp/services/BuiltinServerAsyncApi.java | 134 ++--- .../fujitsu/fgcp/services/DiskImageApi.java | 6 +- .../fgcp/services/DiskImageAsyncApi.java | 34 +- .../fujitsu/fgcp/services/FirewallApi.java | 4 +- .../fgcp/services/FirewallAsyncApi.java | 32 +- .../fgcp/services/LoadBalancerAsyncApi.java | 28 +- .../fgcp/services/PublicIPAddressApi.java | 10 +- .../services/PublicIPAddressAsyncApi.java | 53 +- .../fgcp/services/SystemTemplateApi.java | 8 +- .../fgcp/services/SystemTemplateAsyncApi.java | 46 +- .../fujitsu/fgcp/services/VirtualDCApi.java | 58 +- .../fgcp/services/VirtualDCAsyncApi.java | 214 +++---- .../fgcp/services/VirtualServerApi.java | 24 +- .../fgcp/services/VirtualServerAsyncApi.java | 150 ++--- .../fgcp/services/VirtualSystemApi.java | 36 +- .../fgcp/services/VirtualSystemAsyncApi.java | 192 +++---- .../fgcp/xml/BindParamsToXmlPayload.java | 111 ++-- .../fujitsu/fgcp/xml/FGCPJAXBParser.java | 72 +-- .../fgcp/xml/internal/CreateEFMResponse.java | 22 +- .../xml/internal/CreateVDiskResponse.java | 22 +- .../fgcp/xml/internal/CreateVSYSResponse.java | 22 +- .../xml/internal/CreateVServerResponse.java | 22 +- .../xml/internal/GetAddressRangeResponse.java | 18 +- .../GetDiskImageAttributesResponse.java | 26 +- .../internal/GetEFMAttributesResponse.java | 22 +- .../xml/internal/GetEFMStatusResponse.java | 22 +- .../xml/internal/GetEventLogResponse.java | 16 +- .../GetPerformanceInformationResponse.java | 18 +- .../GetPublicIPAttributesResponse.java | 25 +- .../internal/GetPublicIPStatusResponse.java | 22 +- .../internal/GetVDiskAttributesResponse.java | 22 +- .../internal/GetVSYSAttributesResponse.java | 22 +- .../GetVSYSConfigurationResponse.java | 22 +- ...etVSYSDescriptorConfigurationResponse.java | 22 +- .../xml/internal/GetVSYSStatusResponse.java | 22 +- .../GetVServerAttributesResponse.java | 22 +- .../GetVServerConfigurationResponse.java | 22 +- .../GetVServerInitialPasswordResponse.java | 14 +- .../internal/GetVServerStatusResponse.java | 22 +- .../xml/internal/ListDiskImageResponse.java | 16 +- .../xml/internal/ListEFMBackupResponse.java | 18 +- .../fgcp/xml/internal/ListEFMResponse.java | 16 +- .../xml/internal/ListPublicIPResponse.java | 48 +- .../xml/internal/ListServerTypeResponse.java | 16 +- .../fgcp/xml/internal/ListVDiskResponse.java | 16 +- .../fgcp/xml/internal/ListVSYSResponse.java | 16 +- .../xml/internal/ListVServerResponse.java | 16 +- .../xml/internal/MapWithStatusResponse.java | 42 +- .../xml/internal/PublicIPWithSystemId.java | 18 +- .../xml/internal/SetWithStatusResponse.java | 40 +- .../xml/internal/SingleElementResponse.java | 2 +- .../fgcp/xml/internal/StatusQuerable.java | 6 +- .../fgcp/xml/internal/StatusResponse.java | 49 +- .../fgcp/xml/internal/package-info.java | 2 +- .../FGCPBaseTemplateBuilderLiveTest.java | 112 ++-- .../compute/FGCPRestClientModuleTest.java | 93 ++-- .../FGCPBaseComputeServiceLiveTest.java | 316 +++++------ .../DiskImageToOperatingSystemTest.java | 221 ++++---- .../services/AdditionalDiskApiExpectTest.java | 200 +++---- .../fgcp/services/BaseFGCPApiLiveTest.java | 72 +-- .../services/BaseFGCPRestApiExpectTest.java | 86 +-- .../services/BuiltinServerApiExpectTest.java | 284 +++++----- .../fgcp/services/DiskImageApiExpectTest.java | 70 +-- .../PublicIPAddressApiExpectTest.java | 114 ++-- .../services/SystemTemplateApiExpectTest.java | 114 ++-- .../fgcp/services/VirtualDCApiExpectTest.java | 268 ++++----- .../fgcp/services/VirtualDCApiLiveTest.java | 58 +- .../services/VirtualServerApiExpectTest.java | 306 +++++------ .../services/VirtualSystemApiExpectTest.java | 376 ++++++------- .../http/internal/HttpInternalsLiveTest.java | 8 +- 152 files changed, 6173 insertions(+), 6191 deletions(-) diff --git a/labs/fgcp-au/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderMetadata.java b/labs/fgcp-au/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderMetadata.java index b17d6caf96..b3efbe729a 100644 --- a/labs/fgcp-au/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderMetadata.java +++ b/labs/fgcp-au/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderMetadata.java @@ -30,48 +30,51 @@ import org.jclouds.providers.internal.BaseProviderMetadata; */ public class FGCPAUProviderMetadata extends FGCPProviderMetadata { - public static Builder builder() { - return new Builder(); - } + /** The serialVersionUID */ + private static final long serialVersionUID = 1735901960026547803L; - public FGCPAUProviderMetadata() { - super(builder()); - } + public static Builder builder() { + return new Builder(); + } - public FGCPAUProviderMetadata(Builder builder) { - super(builder); - } + public FGCPAUProviderMetadata() { + super(builder()); + } - @Override - public Builder toBuilder() { - return builder().fromProviderMetadata(this); - } + public FGCPAUProviderMetadata(Builder builder) { + super(builder); + } - public static class Builder extends BaseProviderMetadata.Builder { + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } - protected Builder() { - id("fgcp-au") - .name("Fujitsu Global Cloud Platform (FGCP) - AU") - .apiMetadata(new FGCPApiMetadata()) - .homepage( - URI.create("http://www.fujitsu.com/global/solutions/cloud/solutions/global-cloud-platform/index.html")) - .console(URI.create("http://globalcloud.fujitsu.com.au")) - .defaultProperties(FGCPApiMetadata.defaultProperties()) - .iso3166Codes("AU-NSW") - .endpoint( - "https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint") - .defaultProperties(FGCPProviderMetadata.defaultProperties()); - } + public static class Builder extends BaseProviderMetadata.Builder { - @Override - public FGCPAUProviderMetadata build() { - return new FGCPAUProviderMetadata(this); - } + protected Builder() { + id("fgcp-au") + .name("Fujitsu Global Cloud Platform (FGCP) - AU") + .apiMetadata(new FGCPApiMetadata()) + .homepage( + URI.create("http://www.fujitsu.com/global/solutions/cloud/solutions/global-cloud-platform/index.html")) + .console(URI.create("http://globalcloud.fujitsu.com.au")) + .defaultProperties(FGCPApiMetadata.defaultProperties()) + .iso3166Codes("AU-NSW") + .endpoint( + "https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint") + .defaultProperties(FGCPProviderMetadata.defaultProperties()); + } - @Override - public Builder fromProviderMetadata(ProviderMetadata in) { - super.fromProviderMetadata(in); - return this; - } - } + @Override + public FGCPAUProviderMetadata build() { + return new FGCPAUProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata(ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } } \ No newline at end of file diff --git a/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderTest.java b/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderTest.java index 9a2ddbce86..fa37d4d2f2 100644 --- a/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderTest.java +++ b/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/FGCPAUProviderTest.java @@ -28,7 +28,7 @@ import org.testng.annotations.Test; public class FGCPAUProviderTest extends BaseProviderMetadataTest { public FGCPAUProviderTest() { - super(new FGCPAUProviderMetadata(), new FGCPApiMetadata()); + super(new FGCPAUProviderMetadata(), new FGCPApiMetadata()); } } diff --git a/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPAUTemplateBuilderLiveTest.java b/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPAUTemplateBuilderLiveTest.java index 30f12dea7e..b3881e66df 100644 --- a/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPAUTemplateBuilderLiveTest.java +++ b/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPAUTemplateBuilderLiveTest.java @@ -30,14 +30,14 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "FGCPAUTemplateBuilderLiveTest") public class FGCPAUTemplateBuilderLiveTest extends - FGCPBaseTemplateBuilderLiveTest { + FGCPBaseTemplateBuilderLiveTest { - public FGCPAUTemplateBuilderLiveTest() { - provider = "fgcp-au"; - } + public FGCPAUTemplateBuilderLiveTest() { + provider = "fgcp-au"; + } - @Override - protected Set getIso3166Codes() { - return ImmutableSet. of("AU-NSW"); - } + @Override + protected Set getIso3166Codes() { + return ImmutableSet. of("AU-NSW"); + } } diff --git a/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPAUComputeServiceLiveTest.java b/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPAUComputeServiceLiveTest.java index 49c23ffe47..15f8ab1c81 100644 --- a/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPAUComputeServiceLiveTest.java +++ b/labs/fgcp-au/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPAUComputeServiceLiveTest.java @@ -29,9 +29,9 @@ import org.testng.annotations.Test; @Test(groups = "live", enabled = true, singleThreaded = true, testName = "FGCPAUComputeServiceLiveTest") public class FGCPAUComputeServiceLiveTest extends FGCPBaseComputeServiceLiveTest { - @Override - public void setServiceDefaults() { - provider = "fgcp-au"; - } + @Override + public void setServiceDefaults() { + provider = "fgcp-au"; + } } diff --git a/labs/fgcp-de/src/main/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderMetadata.java b/labs/fgcp-de/src/main/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderMetadata.java index db087a580f..2868f3591b 100644 --- a/labs/fgcp-de/src/main/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderMetadata.java +++ b/labs/fgcp-de/src/main/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderMetadata.java @@ -30,50 +30,50 @@ import org.jclouds.providers.internal.BaseProviderMetadata; */ public class FGCPDEProviderMetadata extends FGCPProviderMetadata { - private static final long serialVersionUID = -8498457904032259345L; + private static final long serialVersionUID = -8498457904032259345L; - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public FGCPDEProviderMetadata() { - super(builder()); - } + public FGCPDEProviderMetadata() { + super(builder()); + } - public FGCPDEProviderMetadata(Builder builder) { - super(builder); - } + public FGCPDEProviderMetadata(Builder builder) { + super(builder); + } - @Override - public Builder toBuilder() { - return builder().fromProviderMetadata(this); - } + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } - public static class Builder extends BaseProviderMetadata.Builder { + public static class Builder extends BaseProviderMetadata.Builder { - protected Builder() { - id("fgcp-de") - .name("Fujitsu Global Cloud Platform (FGCP) - DE") - .apiMetadata(new FGCPApiMetadata()) - .homepage( - URI.create("http://www.fujitsu.com/global/solutions/cloud/solutions/global-cloud-platform/index.html")) - .console(URI.create("http://globalcloud.de.fujitsu.com")) - .defaultProperties(FGCPApiMetadata.defaultProperties()) - .iso3166Codes("DE-BY") - .endpoint( - "https://api.globalcloud.de.fujitsu.com/ovissapi/endpoint") - .defaultProperties(FGCPProviderMetadata.defaultProperties()); - } + protected Builder() { + id("fgcp-de") + .name("Fujitsu Global Cloud Platform (FGCP) - DE") + .apiMetadata(new FGCPApiMetadata()) + .homepage( + URI.create("http://www.fujitsu.com/global/solutions/cloud/solutions/global-cloud-platform/index.html")) + .console(URI.create("http://globalcloud.de.fujitsu.com")) + .defaultProperties(FGCPApiMetadata.defaultProperties()) + .iso3166Codes("DE-BY") + .endpoint( + "https://api.globalcloud.de.fujitsu.com/ovissapi/endpoint") + .defaultProperties(FGCPProviderMetadata.defaultProperties()); + } - @Override - public FGCPDEProviderMetadata build() { - return new FGCPDEProviderMetadata(this); - } + @Override + public FGCPDEProviderMetadata build() { + return new FGCPDEProviderMetadata(this); + } - @Override - public Builder fromProviderMetadata(ProviderMetadata in) { - super.fromProviderMetadata(in); - return this; - } - } + @Override + public Builder fromProviderMetadata(ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } } \ No newline at end of file diff --git a/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderTest.java b/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderTest.java index 99b37d255b..175cb3d2a4 100644 --- a/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderTest.java +++ b/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/FGCPDEProviderTest.java @@ -28,7 +28,7 @@ import org.testng.annotations.Test; public class FGCPDEProviderTest extends BaseProviderMetadataTest { public FGCPDEProviderTest() { - super(new FGCPDEProviderMetadata(), new FGCPApiMetadata()); + super(new FGCPDEProviderMetadata(), new FGCPApiMetadata()); } } diff --git a/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPDETemplateBuilderLiveTest.java b/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPDETemplateBuilderLiveTest.java index 0894978822..eaf6aeaf14 100644 --- a/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPDETemplateBuilderLiveTest.java +++ b/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPDETemplateBuilderLiveTest.java @@ -30,14 +30,14 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "live", enabled = true, singleThreaded = true, testName = "FGCPDETemplateBuilderLiveTest") public class FGCPDETemplateBuilderLiveTest extends - FGCPBaseTemplateBuilderLiveTest { + FGCPBaseTemplateBuilderLiveTest { - public FGCPDETemplateBuilderLiveTest() { - provider = "fgcp-de"; - } + public FGCPDETemplateBuilderLiveTest() { + provider = "fgcp-de"; + } - @Override - protected Set getIso3166Codes() { - return ImmutableSet. of("DE-BY"); - } + @Override + protected Set getIso3166Codes() { + return ImmutableSet. of("DE-BY"); + } } diff --git a/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPDEComputeServiceLiveTest.java b/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPDEComputeServiceLiveTest.java index f0de55992f..23f1cd72c7 100644 --- a/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPDEComputeServiceLiveTest.java +++ b/labs/fgcp-de/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPDEComputeServiceLiveTest.java @@ -29,9 +29,9 @@ import org.testng.annotations.Test; @Test(groups = "live", enabled = true, singleThreaded = true, testName = "FGCPDEComputeServiceLiveTest") public class FGCPDEComputeServiceLiveTest extends FGCPBaseComputeServiceLiveTest { - @Override - public void setServiceDefaults() { - provider = "fgcp-de"; - } + @Override + public void setServiceDefaults() { + provider = "fgcp-de"; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApi.java index 54561af058..c2175f9fef 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApi.java @@ -40,30 +40,30 @@ import org.jclouds.rest.annotations.Delegate; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface FGCPApi { - @Delegate - VirtualDCApi getVirtualDCApi(); + @Delegate + VirtualDCApi getVirtualDCApi(); - @Delegate - VirtualSystemApi getVirtualSystemApi(); + @Delegate + VirtualSystemApi getVirtualSystemApi(); - @Delegate - VirtualServerApi getVirtualServerApi(); + @Delegate + VirtualServerApi getVirtualServerApi(); - @Delegate - AdditionalDiskApi getAdditionalDiskApi(); + @Delegate + AdditionalDiskApi getAdditionalDiskApi(); - @Delegate - SystemTemplateApi getSystemTemplateApi(); + @Delegate + SystemTemplateApi getSystemTemplateApi(); - @Delegate - DiskImageApi getDiskImageApi(); + @Delegate + DiskImageApi getDiskImageApi(); - @Delegate - FirewallApi getFirewallApi(); + @Delegate + FirewallApi getFirewallApi(); - @Delegate - LoadBalancerApi getLoadBalancerApi(); + @Delegate + LoadBalancerApi getLoadBalancerApi(); - @Delegate - PublicIPAddressApi getPublicIPAddressApi(); + @Delegate + PublicIPAddressApi getPublicIPAddressApi(); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApiMetadata.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApiMetadata.java index 0f5e9fdb44..c187b7edee 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApiMetadata.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPApiMetadata.java @@ -40,60 +40,63 @@ import com.google.inject.Module; */ public class FGCPApiMetadata extends BaseRestApiMetadata { - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } + /** The serialVersionUID */ + private static final long serialVersionUID = -8430912756058292588L; - public FGCPApiMetadata() { - this(new Builder()); - } + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } - protected FGCPApiMetadata(Builder builder) { - super(builder); - } + public FGCPApiMetadata() { + this(new Builder()); + } - public static Properties defaultProperties() { - Properties properties = BaseRestApiMetadata.defaultProperties(); - // enables peer verification using the CAs bundled with the JRE (or - // value of javax.net.ssl.trustStore if set) - properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); - // properties.setProperty("jclouds.ssh.max-retries", "5"); - // properties.setProperty("jclouds.ssh.retry-auth", "true"); - return properties; - } + protected FGCPApiMetadata(Builder builder) { + super(builder); + } - public static class Builder extends BaseRestApiMetadata.Builder { + public static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.defaultProperties(); + // enables peer verification using the CAs bundled with the JRE (or + // value of javax.net.ssl.trustStore if set) + properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); + // properties.setProperty("jclouds.ssh.max-retries", "5"); + // properties.setProperty("jclouds.ssh.retry-auth", "true"); + return properties; + } - protected Builder() { - super(FGCPApi.class, FGCPAsyncApi.class); - id("fgcp") - .name("Fujitsu Global Cloud Platform (FGCP)") - .identityName("User certificate (PEM file)") - .credentialName("User certificate password") - .documentation( - URI.create("https://globalcloud.fujitsu.com.au/portala/ctrl/aboutSopManual")) - .version(FGCPAsyncApi.VERSION) - .defaultEndpoint( - "https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint") - .defaultProperties(FGCPApiMetadata.defaultProperties()) - .view(TypeToken.of(ComputeServiceContext.class)) - .defaultModules( - ImmutableSet.> of( - FGCPComputeServiceContextModule.class, - FGCPRestClientModule.class)); - } + public static class Builder extends BaseRestApiMetadata.Builder { - @Override - public FGCPApiMetadata build() { - return new FGCPApiMetadata(this); - } + protected Builder() { + super(FGCPApi.class, FGCPAsyncApi.class); + id("fgcp") + .name("Fujitsu Global Cloud Platform (FGCP)") + .identityName("User certificate (PEM file)") + .credentialName("User certificate password") + .documentation( + URI.create("https://globalcloud.fujitsu.com.au/portala/ctrl/aboutSopManual")) + .version(FGCPAsyncApi.VERSION) + .defaultEndpoint( + "https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint") + .defaultProperties(FGCPApiMetadata.defaultProperties()) + .view(TypeToken.of(ComputeServiceContext.class)) + .defaultModules( + ImmutableSet.> of( + FGCPComputeServiceContextModule.class, + FGCPRestClientModule.class)); + } - @Override - public Builder fromApiMetadata(ApiMetadata in) { - super.fromApiMetadata(in); - return this; - } + @Override + public FGCPApiMetadata build() { + return new FGCPApiMetadata(this); + } - } + @Override + public Builder fromApiMetadata(ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAsyncApi.java index 9eda1dde95..5a3d5e4ac5 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPAsyncApi.java @@ -35,32 +35,32 @@ import org.jclouds.rest.annotations.Delegate; * @author Dies Koper */ public interface FGCPAsyncApi { - public final static String VERSION = "2012-02-18"; + public final static String VERSION = "2012-02-18"; - @Delegate - VirtualDCAsyncApi getVirtualDCApi(); + @Delegate + VirtualDCAsyncApi getVirtualDCApi(); - @Delegate - VirtualSystemAsyncApi getVirtualSystemApi(); + @Delegate + VirtualSystemAsyncApi getVirtualSystemApi(); - @Delegate - VirtualServerAsyncApi getVirtualServerApi(); + @Delegate + VirtualServerAsyncApi getVirtualServerApi(); - @Delegate - AdditionalDiskAsyncApi getAdditionalDiskApi(); + @Delegate + AdditionalDiskAsyncApi getAdditionalDiskApi(); - @Delegate - SystemTemplateAsyncApi getSystemTemplateApi(); + @Delegate + SystemTemplateAsyncApi getSystemTemplateApi(); - @Delegate - DiskImageAsyncApi getDiskImageApi(); + @Delegate + DiskImageAsyncApi getDiskImageApi(); - @Delegate - FirewallAsyncApi getFirewallApi(); + @Delegate + FirewallAsyncApi getFirewallApi(); - @Delegate - LoadBalancerAsyncApi getLoadBalancerApi(); + @Delegate + LoadBalancerAsyncApi getLoadBalancerApi(); - @Delegate - PublicIPAddressAsyncApi getPublicIPAddressApi(); + @Delegate + PublicIPAddressAsyncApi getPublicIPAddressApi(); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPProviderMetadata.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPProviderMetadata.java index a7718d4c2e..7989cda470 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPProviderMetadata.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/FGCPProviderMetadata.java @@ -32,26 +32,26 @@ import org.jclouds.providers.internal.BaseProviderMetadata; */ public class FGCPProviderMetadata extends BaseProviderMetadata { - private static final long serialVersionUID = 7527265705102650456L; + private static final long serialVersionUID = 7527265705102650456L; - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public FGCPProviderMetadata() { - super(builder()); - } + public FGCPProviderMetadata() { + super(builder()); + } - public FGCPProviderMetadata(Builder builder) { - super(builder); - } + public FGCPProviderMetadata(Builder builder) { + super(builder); + } - public static Properties defaultProperties() { - Properties properties = new Properties(); + public static Properties defaultProperties() { + Properties properties = new Properties(); - properties.setProperty(TEMPLATE, - "osFamily=CENTOS,osVersionMatches=6.2,os64Bit=true"); + properties.setProperty(TEMPLATE, + "osFamily=CENTOS,osVersionMatches=6.2,os64Bit=true"); - return properties; - } + return properties; + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/binders/BindAlsoToSystemId.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/binders/BindAlsoToSystemId.java index 0986997dbf..887d52b4f4 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/binders/BindAlsoToSystemId.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/binders/BindAlsoToSystemId.java @@ -38,33 +38,33 @@ import org.jclouds.rest.Binder; @Singleton public class BindAlsoToSystemId implements Binder { - /** - * - * @param request - * request where the query params will be set - * @param input - * array of String params - */ - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object input) { + /** + * + * @param request + * request where the query params will be set + * @param input + * array of String params + */ + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { - checkNotNull(input); - checkArgument( - input instanceof String, - "this binder only applies to String arguments: " - + input.getClass()); + checkNotNull(input); + checkArgument( + input instanceof String, + "this binder only applies to String arguments: " + + input.getClass()); - Pattern pattern = Pattern.compile("^(\\w+-\\w+)\\b.*"); - Matcher matcher = pattern.matcher((String) input); + Pattern pattern = Pattern.compile("^(\\w+-\\w+)\\b.*"); + Matcher matcher = pattern.matcher((String) input); - checkArgument(matcher.find(), - "no valid resource id found to construct vsys id from: " - + input.toString()); + checkArgument(matcher.find(), + "no valid resource id found to construct vsys id from: " + + input.toString()); - Builder builder = request.toBuilder(); - builder.replaceQueryParam("vsysId", matcher.group(1)); + Builder builder = request.toBuilder(); + builder.replaceQueryParam("vsysId", matcher.group(1)); - return (R) builder.build(); - } + return (R) builder.build(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModule.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModule.java index c86abea2ea..357782a962 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModule.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModule.java @@ -92,284 +92,284 @@ import com.google.inject.TypeLiteral; */ @ConfiguresRestClient public class FGCPRestClientModule extends - RestClientModule { + RestClientModule { - @Resource - Logger logger = Logger.NULL; + @Resource + Logger logger = Logger.NULL; - public static final Map, Class> DELEGATE_MAP = ImmutableMap - ., Class> builder() - // - .put(VirtualDCApi.class, VirtualDCAsyncApi.class) - .put(VirtualSystemApi.class, VirtualSystemAsyncApi.class) - .put(VirtualServerApi.class, VirtualServerAsyncApi.class) - .put(AdditionalDiskApi.class, AdditionalDiskAsyncApi.class) - .put(SystemTemplateApi.class, SystemTemplateAsyncApi.class) - .put(DiskImageApi.class, DiskImageAsyncApi.class) - .put(BuiltinServerApi.class, BuiltinServerAsyncApi.class) - .put(FirewallApi.class, FirewallAsyncApi.class) - .put(LoadBalancerApi.class, LoadBalancerAsyncApi.class) - .put(PublicIPAddressApi.class, PublicIPAddressAsyncApi.class) - .build(); + public static final Map, Class> DELEGATE_MAP = ImmutableMap + ., Class> builder() + // + .put(VirtualDCApi.class, VirtualDCAsyncApi.class) + .put(VirtualSystemApi.class, VirtualSystemAsyncApi.class) + .put(VirtualServerApi.class, VirtualServerAsyncApi.class) + .put(AdditionalDiskApi.class, AdditionalDiskAsyncApi.class) + .put(SystemTemplateApi.class, SystemTemplateAsyncApi.class) + .put(DiskImageApi.class, DiskImageAsyncApi.class) + .put(BuiltinServerApi.class, BuiltinServerAsyncApi.class) + .put(FirewallApi.class, FirewallAsyncApi.class) + .put(LoadBalancerApi.class, LoadBalancerAsyncApi.class) + .put(PublicIPAddressApi.class, PublicIPAddressAsyncApi.class) + .build(); - public FGCPRestClientModule() { - super(DELEGATE_MAP); - } + public FGCPRestClientModule() { + super(DELEGATE_MAP); + } - @Override - protected void bindErrorHandlers() { - // bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAWSErrorFromXmlContent.class); - // bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAWSErrorFromXmlContent.class); - // bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAWSErrorFromXmlContent.class); - } + @Override + protected void bindErrorHandlers() { + // bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAWSErrorFromXmlContent.class); + // bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAWSErrorFromXmlContent.class); + // bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAWSErrorFromXmlContent.class); + } - @Override - protected void installLocations() { - super.installLocations(); - bind(ImplicitLocationSupplier.class).to(FirstNetwork.class).in( - Scopes.SINGLETON); - bind(LocationsSupplier.class).to( - SystemAndNetworkSegmentToLocationSupplier.class).in( - Scopes.SINGLETON); - } + @Override + protected void installLocations() { + super.installLocations(); + bind(ImplicitLocationSupplier.class).to(FirstNetwork.class).in( + Scopes.SINGLETON); + bind(LocationsSupplier.class).to( + SystemAndNetworkSegmentToLocationSupplier.class).in( + Scopes.SINGLETON); + } - @Override - protected void bindRetryHandlers() { - bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to( - FGCPRetryIfNotProxyAuthenticationFailureHandler.class); - } + @Override + protected void bindRetryHandlers() { + bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to( + FGCPRetryIfNotProxyAuthenticationFailureHandler.class); + } - @Override - protected void configure() { - super.configure(); - bind(XMLParser.class).to(FGCPJAXBParser.class); - bind(new TypeLiteral>() { - }).to(new TypeLiteral() { - }); - } + @Override + protected void configure() { + super.configure(); + bind(XMLParser.class).to(FGCPJAXBParser.class); + bind(new TypeLiteral>() { + }).to(new TypeLiteral() { + }); + } - @Provides - @TimeStamp - protected Calendar provideCalendar() { - return Calendar.getInstance(); - } + @Provides + @TimeStamp + protected Calendar provideCalendar() { + return Calendar.getInstance(); + } - /* - * - * @Provides - * - * @Singleton protected KeyStore - * provideKeyStore(@Named(Constants.PROPERTY_IDENTITY) String - * keyStoreFilename, @Named(Constants.PROPERTY_CREDENTIAL) String - * keyStorePassword) throws KeyStoreException { KeyStore keyStore = - * KeyStore.getInstance("pkcs12"); - * - * try { FileInputStream is = new - * FileInputStream(checkNotNull(keyStoreFilename, - * Constants.PROPERTY_IDENTITY)); keyStore.load(is, - * checkNotNull(keyStorePassword, - * Constants.PROPERTY_CREDENTIAL).toCharArray()); } catch (Exception e) { // - * expecting IOException, NoSuchAlgorithmException, CertificateException - * logger.error(e, "Keystore could not be opened: %s", keyStoreFilename); } - * return keyStore; } - * - * @Provides - * - * @Singleton protected PrivateKey provideKey(Provider - * keyStoreProvider, @Named(Constants.PROPERTY_CREDENTIAL) String - * keyPassword) throws KeyStoreException, NoSuchAlgorithmException, - * UnrecoverableKeyException { KeyStore keyStore = keyStoreProvider.get(); - * if (keyStore == null) return null; - * - * // retrieving 1st alias in keystore as expecting only one String alias = - * checkNotNull(keyStore.aliases().nextElement(), - * "first alias in keystore"); return (PrivateKey) keyStore.getKey(alias, - * checkNotNull(keyPassword, Constants.PROPERTY_CREDENTIAL).toCharArray()); - * } - */ - /* - * maybe we can provide two authentication methods: - * - * 1. same as DeltaCloud: User passes a folder name as identity and cert - * password as credential Note: pass relative path (e.g. cert's path: - * c:\jclouds\certs\dkoper\UserCert.p12: user passes 'dkoper': provider - * impl. finds it under e.g. $USER_DIR or $CURRENT_DIR or pass absolute path - * 2. no file access for GAE: User passes cert in PEM format (converted from - * UserCert.p12 using openssl?) as identity and cert password as credential - */ - @Provides - @Singleton - protected KeyStore provideKeyStore(Crypto crypto, @Identity String cert, - @Credential String keyStorePassword) { - KeyStore keyStore = null; - try { - keyStore = KeyStore.getInstance("PKCS12"); + /* + * + * @Provides + * + * @Singleton protected KeyStore + * provideKeyStore(@Named(Constants.PROPERTY_IDENTITY) String + * keyStoreFilename, @Named(Constants.PROPERTY_CREDENTIAL) String + * keyStorePassword) throws KeyStoreException { KeyStore keyStore = + * KeyStore.getInstance("pkcs12"); + * + * try { FileInputStream is = new + * FileInputStream(checkNotNull(keyStoreFilename, + * Constants.PROPERTY_IDENTITY)); keyStore.load(is, + * checkNotNull(keyStorePassword, + * Constants.PROPERTY_CREDENTIAL).toCharArray()); } catch (Exception e) { // + * expecting IOException, NoSuchAlgorithmException, CertificateException + * logger.error(e, "Keystore could not be opened: %s", keyStoreFilename); } + * return keyStore; } + * + * @Provides + * + * @Singleton protected PrivateKey provideKey(Provider + * keyStoreProvider, @Named(Constants.PROPERTY_CREDENTIAL) String + * keyPassword) throws KeyStoreException, NoSuchAlgorithmException, + * UnrecoverableKeyException { KeyStore keyStore = keyStoreProvider.get(); + * if (keyStore == null) return null; + * + * // retrieving 1st alias in keystore as expecting only one String alias = + * checkNotNull(keyStore.aliases().nextElement(), + * "first alias in keystore"); return (PrivateKey) keyStore.getKey(alias, + * checkNotNull(keyPassword, Constants.PROPERTY_CREDENTIAL).toCharArray()); + * } + */ + /* + * maybe we can provide two authentication methods: + * + * 1. same as DeltaCloud: User passes a folder name as identity and cert + * password as credential Note: pass relative path (e.g. cert's path: + * c:\jclouds\certs\dkoper\UserCert.p12: user passes 'dkoper': provider + * impl. finds it under e.g. $USER_DIR or $CURRENT_DIR or pass absolute path + * 2. no file access for GAE: User passes cert in PEM format (converted from + * UserCert.p12 using openssl?) as identity and cert password as credential + */ + @Provides + @Singleton + protected KeyStore provideKeyStore(Crypto crypto, @Identity String cert, + @Credential String keyStorePassword) { + KeyStore keyStore = null; + try { + keyStore = KeyStore.getInstance("PKCS12"); - // System.out.println("cert: " + cert); - // System.out.println("pwd : " + keyStorePassword); - File certFile = new File(checkNotNull(cert)); - if (certFile.isFile()) { // cert is path to pkcs12 file + // System.out.println("cert: " + cert); + // System.out.println("pwd : " + keyStorePassword); + File certFile = new File(checkNotNull(cert)); + if (certFile.isFile()) { // cert is path to pkcs12 file - keyStore.load(new FileInputStream(certFile), - keyStorePassword.toCharArray()); - } else { // cert is PEM encoded, containing private key and certs + keyStore.load(new FileInputStream(certFile), + keyStorePassword.toCharArray()); + } else { // cert is PEM encoded, containing private key and certs - // System.out.println("cert:\n" + cert); - // split in private key and certs - int privateKeyBeginIdx = cert.indexOf("-----BEGIN PRIVATE KEY"); - int privateKeyEndIdx = cert.indexOf("-----END PRIVATE KEY"); - String pemPrivateKey = cert.substring(privateKeyBeginIdx, - privateKeyEndIdx + 26); - // System.out.println("***************"); - // System.out.println("pemPrivateKey:\n" + pemPrivateKey); - // System.out.println("***************"); + // System.out.println("cert:\n" + cert); + // split in private key and certs + int privateKeyBeginIdx = cert.indexOf("-----BEGIN PRIVATE KEY"); + int privateKeyEndIdx = cert.indexOf("-----END PRIVATE KEY"); + String pemPrivateKey = cert.substring(privateKeyBeginIdx, + privateKeyEndIdx + 26); + // System.out.println("***************"); + // System.out.println("pemPrivateKey:\n" + pemPrivateKey); + // System.out.println("***************"); - String pemCerts = ""; - int certsBeginIdx = 0; + String pemCerts = ""; + int certsBeginIdx = 0; - do { - certsBeginIdx = cert.indexOf("-----BEGIN CERTIFICATE", - certsBeginIdx); - // System.out.println("begin:" + certsBeginIdx); + do { + certsBeginIdx = cert.indexOf("-----BEGIN CERTIFICATE", + certsBeginIdx); + // System.out.println("begin:" + certsBeginIdx); - if (certsBeginIdx >= 0) { - int certsEndIdx = cert.indexOf("-----END CERTIFICATE", - certsBeginIdx) + 26; - // System.out.println("end :" + certsEndIdx); - pemCerts += cert.substring(certsBeginIdx, certsEndIdx); - certsBeginIdx = certsEndIdx; - } - } while (certsBeginIdx != -1); - // System.out.println("***************"); - // System.out.println("pemCerts:\n" + pemCerts); - // System.out.println("***************"); + if (certsBeginIdx >= 0) { + int certsEndIdx = cert.indexOf("-----END CERTIFICATE", + certsBeginIdx) + 26; + // System.out.println("end :" + certsEndIdx); + pemCerts += cert.substring(certsBeginIdx, certsEndIdx); + certsBeginIdx = certsEndIdx; + } + } while (certsBeginIdx != -1); + // System.out.println("***************"); + // System.out.println("pemCerts:\n" + pemCerts); + // System.out.println("***************"); - /* - * String pemCerts = "-----BEGIN "; Splitter pemSplitter = - * Splitter.on("-----BEGIN "); - * - * for (String part : pemSplitter.split(cert)) { - * System.out.println("***************"); - * System.out.println("Part:\n" + part); - * System.out.println("***************"); - * - * if (part.startsWith("PRIVATE KEY") - */ - /* || part.startsWith("RSA PRIVATE KEY)" *//* - * ) { - * - * int certEndIdx = - * part.lastIndexOf - * ("-----END"); - * pemPrivateKey += - * part.substring(0, - * certEndIdx + 26); - * // take up to next - * "-----" (i.e. - * "-----END") // - * Splitter - * keySplitter = - * Splitter - * .on("-----"). - * omitEmptyStrings - * ().trimResults(); - * // - * Iterator - * iter = - * keySplitter. - * split(part - * ).iterator(); // - * String keyName = - * iter.next() + - * "-----\n"; // - * pemPrivateKey += - * keyName; //// - * System.out - * .println - * ("Skipping: '" + - * iter.next() + - * "'"); // - * pemPrivateKey += - * iter.next(); // - * pemPrivateKey += - * "\n-----END " + - * keyName; - * System.out.println - * ( - * "/////////////////" - * ); - * System.out.println - * ( - * "pemPrivateKey:\n" - * + pemPrivateKey); - * System - * .out.println( - * "/////////////////" - * ); } else if - * (part.startsWith - * ("CERTIFICATE")) { - * - * // take up to next - * "-----" (i.e. - * "-----END") // or - * take up to last - * END CERTIFICATE? - * int certEndIdx = - * part.lastIndexOf ( - * "----- END CERTIFICATE" - * ); // pemCerts += - * part. // Splitter - * keySplitter = - * Splitter - * .on("-----"). - * omitEmptyStrings - * (); // pemCerts += - * keySplitter - * .split(part) - * .iterator - * ().next(); // - * pemCerts += - * "-----BEGIN "; } - * else { // ignore - * the fluff in - * between (Bag - * Attributes, etc.) - * } } - */ - - // parse private key - KeySpec keySpec = Pems.privateKeySpec(InputSuppliers - .of(pemPrivateKey)); - PrivateKey privateKey = crypto.rsaKeyFactory().generatePrivate( - keySpec); - - // populate keystore with private key and certs - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - @SuppressWarnings("unchecked") - Collection certs = (Collection) cf - .generateCertificates(new ByteArrayInputStream(pemCerts - .getBytes("UTF-8"))); - keyStore.load(null); - keyStore.setKeyEntry("dummy", privateKey, - keyStorePassword.toCharArray(), - certs.toArray(new java.security.cert.Certificate[0])); - - // System.out.println("private key: " + privateKey.getFormat() + - // "; " - // + privateKey.getAlgorithm() + "; class: " + - // privateKey.getClass().getName());// + "; " + new - // String(privateKey.getEncoded())); - - } - } catch (Exception e) { /* - * KeyStoreException, IOException, NoSuchAlgorithmException, - * CertificateException, InvalidKeySpecException + * String pemCerts = "-----BEGIN "; Splitter pemSplitter = + * Splitter.on("-----BEGIN "); + * + * for (String part : pemSplitter.split(cert)) { + * System.out.println("***************"); + * System.out.println("Part:\n" + part); + * System.out.println("***************"); + * + * if (part.startsWith("PRIVATE KEY") */ - throw new AuthorizationException("Error loading certificate", e); - } + /* || part.startsWith("RSA PRIVATE KEY)" *//* + * ) { + * + * int certEndIdx = + * part.lastIndexOf + * ("-----END"); + * pemPrivateKey += + * part.substring(0, + * certEndIdx + 26); + * // take up to next + * "-----" (i.e. + * "-----END") // + * Splitter + * keySplitter = + * Splitter + * .on("-----"). + * omitEmptyStrings + * ().trimResults(); + * // + * Iterator + * iter = + * keySplitter. + * split(part + * ).iterator(); // + * String keyName = + * iter.next() + + * "-----\n"; // + * pemPrivateKey += + * keyName; //// + * System.out + * .println + * ("Skipping: '" + + * iter.next() + + * "'"); // + * pemPrivateKey += + * iter.next(); // + * pemPrivateKey += + * "\n-----END " + + * keyName; + * System.out.println + * ( + * "/////////////////" + * ); + * System.out.println + * ( + * "pemPrivateKey:\n" + * + pemPrivateKey); + * System + * .out.println( + * "/////////////////" + * ); } else if + * (part.startsWith + * ("CERTIFICATE")) { + * + * // take up to next + * "-----" (i.e. + * "-----END") // or + * take up to last + * END CERTIFICATE? + * int certEndIdx = + * part.lastIndexOf ( + * "----- END CERTIFICATE" + * ); // pemCerts += + * part. // Splitter + * keySplitter = + * Splitter + * .on("-----"). + * omitEmptyStrings + * (); // pemCerts += + * keySplitter + * .split(part) + * .iterator + * ().next(); // + * pemCerts += + * "-----BEGIN "; } + * else { // ignore + * the fluff in + * between (Bag + * Attributes, etc.) + * } } + */ - return keyStore; - } + // parse private key + KeySpec keySpec = Pems.privateKeySpec(InputSuppliers + .of(pemPrivateKey)); + PrivateKey privateKey = crypto.rsaKeyFactory().generatePrivate( + keySpec); + + // populate keystore with private key and certs + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + @SuppressWarnings("unchecked") + Collection certs = (Collection) cf + .generateCertificates(new ByteArrayInputStream(pemCerts + .getBytes("UTF-8"))); + keyStore.load(null); + keyStore.setKeyEntry("dummy", privateKey, + keyStorePassword.toCharArray(), + certs.toArray(new java.security.cert.Certificate[0])); + + // System.out.println("private key: " + privateKey.getFormat() + + // "; " + // + privateKey.getAlgorithm() + "; class: " + + // privateKey.getClass().getName());// + "; " + new + // String(privateKey.getEncoded())); + + } + } catch (Exception e) { + /* + * KeyStoreException, IOException, NoSuchAlgorithmException, + * CertificateException, InvalidKeySpecException + */ + throw new AuthorizationException("Error loading certificate", e); + } + + return keyStore; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPComputeServiceContextModule.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPComputeServiceContextModule.java index 46f3646e6e..1c6d29f744 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPComputeServiceContextModule.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPComputeServiceContextModule.java @@ -53,88 +53,88 @@ import com.google.inject.TypeLiteral; * @author Dies Koper */ public class FGCPComputeServiceContextModule - extends - ComputeServiceAdapterContextModule { + extends + ComputeServiceAdapterContextModule { - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - protected void configure() { - super.configure(); - // installDependencies(); + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void configure() { + super.configure(); + // installDependencies(); - bind( - new TypeLiteral>() { - }).to(FGCPComputeServiceAdapter.class); + bind( + new TypeLiteral>() { + }).to(FGCPComputeServiceAdapter.class); - // the following bind functions that map FGCP domain specific resources - // to jclouds' - bind(new TypeLiteral>() { - }).to(VServerMetadataToNodeMetadata.class); - bind(new TypeLiteral>() { - }).to(DiskImageToImage.class); - bind(new TypeLiteral>() { - }).to(DiskImageToOperatingSystem.class); - bind(new TypeLiteral>() { - }).to(ServerTypeToHardware.class); - bind(new TypeLiteral>() { - }).to(DiskToVolume.class); - bind(new TypeLiteral>() { - }).to(CPUToProcessor.class); + // the following bind functions that map FGCP domain specific resources + // to jclouds' + bind(new TypeLiteral>() { + }).to(VServerMetadataToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(DiskImageToImage.class); + bind(new TypeLiteral>() { + }).to(DiskImageToOperatingSystem.class); + bind(new TypeLiteral>() { + }).to(ServerTypeToHardware.class); + bind(new TypeLiteral>() { + }).to(DiskToVolume.class); + bind(new TypeLiteral>() { + }).to(CPUToProcessor.class); - // we aren't converting hardware from a provider-specific type - bind(new TypeLiteral>() { - }).to((Class) IdentityFunction.class); - bind(new TypeLiteral>() { - }).to((Class) IdentityFunction.class); + // we aren't converting hardware from a provider-specific type + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); - bind(TemplateOptions.class).to(FGCPTemplateOptions.class); + bind(TemplateOptions.class).to(FGCPTemplateOptions.class); - // bind(new TypeLiteral>() { - // }).to((Class) ServerStopped.class); + // bind(new TypeLiteral>() { + // }).to((Class) ServerStopped.class); - // need to look into the following later for to map (create) jclouds' - // location to FGCP. - // see LocationScope: - // PROVIDER: FGCP - // REGION: country?/country+state? - // ZONE: virtual DC: contractId - // NETWORK: VSYS? DMZ/SECURE1/SECURE2? - // RACK: N/A? - // HOST: N/A? - // there are no locations except the provider - // bind(new TypeLiteral>() { - // }).to(OnlyLocationOrFirstZone.class); + // need to look into the following later for to map (create) jclouds' + // location to FGCP. + // see LocationScope: + // PROVIDER: FGCP + // REGION: country?/country+state? + // ZONE: virtual DC: contractId + // NETWORK: VSYS? DMZ/SECURE1/SECURE2? + // RACK: N/A? + // HOST: N/A? + // there are no locations except the provider + // bind(new TypeLiteral>() { + // }).to(OnlyLocationOrFirstZone.class); - // install(new FGCPBindComputeStrategiesByClass()); - // install(new FGCPBindComputeSuppliersByClass()); - // bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class); - // bind(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class).to( - // CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class); - // bind(EC2HardwareSupplier.class).to(AWSEC2HardwareSupplier.class); - // bind(EC2TemplateBuilderImpl.class).to(AWSEC2TemplateBuilderImpl.class); - // bind(EC2GetNodeMetadataStrategy.class).to(AWSEC2GetNodeMetadataStrategy.class); - // bind(InstancePresent.class).to(AWSEC2InstancePresent.class); - // bind(EC2CreateNodesInGroupThenAddToSet.class).to(AWSEC2CreateNodesInGroupThenAddToSet.class); - // bind(RunningInstanceToNodeMetadata.class).to(AWSRunningInstanceToNodeMetadata.class); - } + // install(new FGCPBindComputeStrategiesByClass()); + // install(new FGCPBindComputeSuppliersByClass()); + // bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class); + // bind(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class).to( + // CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class); + // bind(EC2HardwareSupplier.class).to(AWSEC2HardwareSupplier.class); + // bind(EC2TemplateBuilderImpl.class).to(AWSEC2TemplateBuilderImpl.class); + // bind(EC2GetNodeMetadataStrategy.class).to(AWSEC2GetNodeMetadataStrategy.class); + // bind(InstancePresent.class).to(AWSEC2InstancePresent.class); + // bind(EC2CreateNodesInGroupThenAddToSet.class).to(AWSEC2CreateNodesInGroupThenAddToSet.class); + // bind(RunningInstanceToNodeMetadata.class).to(AWSRunningInstanceToNodeMetadata.class); + } - // @Provides - // @Singleton - // @Named("SECURITY") - // protected Predicate provideServerStopped(ServerStopped - // serverStopped, Timeouts timeouts) { - // return new RetryablePredicate(serverStopped, - // timeouts.nodeSuspended); - // } + // @Provides + // @Singleton + // @Named("SECURITY") + // protected Predicate provideServerStopped(ServerStopped + // serverStopped, Timeouts timeouts) { + // return new RetryablePredicate(serverStopped, + // timeouts.nodeSuspended); + // } - protected void installDependencies() { - // install(new FGCPComputeServiceDependenciesModule()); - } + protected void installDependencies() { + // install(new FGCPComputeServiceDependenciesModule()); + } - /* - * @Override protected TemplateBuilder provideTemplate(Injector injector, - * TemplateBuilder template) { return - * template.osFamily(CENTOS).os64Bit(true); } - */ + /* + * @Override protected TemplateBuilder provideTemplate(Injector injector, + * TemplateBuilder template) { return + * template.osFamily(CENTOS).os64Bit(true); } + */ } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/CPUToProcessor.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/CPUToProcessor.java index a26508e954..63079a76a0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/CPUToProcessor.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/CPUToProcessor.java @@ -20,11 +20,12 @@ package org.jclouds.fujitsu.fgcp.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Function; +import javax.inject.Singleton; + import org.jclouds.compute.domain.Processor; import org.jclouds.fujitsu.fgcp.domain.CPU; -import javax.inject.Singleton; +import com.google.common.base.Function; /** * Created by IntelliJ IDEA. @@ -34,11 +35,11 @@ import javax.inject.Singleton; @Singleton public class CPUToProcessor implements Function { - @Override - public Processor apply(CPU cpu) { - checkNotNull(cpu, "cpu"); + @Override + public Processor apply(CPU cpu) { + checkNotNull(cpu, "cpu"); - return new Processor(Double.valueOf(cpu.getCores()), Double.valueOf(cpu - .getSpeedPerCore())); - } + return new Processor(Double.valueOf(cpu.getCores()), Double.valueOf(cpu + .getSpeedPerCore())); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToImage.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToImage.java index e5200da051..8ea67fe8ba 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToImage.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToImage.java @@ -43,38 +43,38 @@ import com.google.common.collect.Iterables; @Singleton public class DiskImageToImage implements Function { - private final DiskImageToOperatingSystem diskImageToOperatingSystem; - private final RegionToProviderOrJustProvider regionSupplier; + private final DiskImageToOperatingSystem diskImageToOperatingSystem; + private final RegionToProviderOrJustProvider regionSupplier; - @Inject - public DiskImageToImage( - DiskImageToOperatingSystem diskImageToOperatingSystem, - RegionToProviderOrJustProvider locationSupplier) { - this.diskImageToOperatingSystem = checkNotNull( - diskImageToOperatingSystem, "diskImageToOperatingSystem"); - this.regionSupplier = checkNotNull(locationSupplier, "locationProvider"); - } + @Inject + public DiskImageToImage( + DiskImageToOperatingSystem diskImageToOperatingSystem, + RegionToProviderOrJustProvider locationSupplier) { + this.diskImageToOperatingSystem = checkNotNull( + diskImageToOperatingSystem, "diskImageToOperatingSystem"); + this.regionSupplier = checkNotNull(locationSupplier, "locationProvider"); + } - @Override - public Image apply(DiskImage from) { - checkNotNull(from, "disk image"); + @Override + public Image apply(DiskImage from) { + checkNotNull(from, "disk image"); - ImageBuilder builder = new ImageBuilder(); + ImageBuilder builder = new ImageBuilder(); - builder.ids(from.getId()); - builder.name(from.getName()); - builder.description(from.getDescription()); - builder.location(Iterables.getOnlyElement(regionSupplier.get())); - // in fgcp, if the image is listed it is available - builder.status(Status.AVAILABLE); + builder.ids(from.getId()); + builder.name(from.getName()); + builder.description(from.getDescription()); + builder.location(Iterables.getOnlyElement(regionSupplier.get())); + // in fgcp, if the image is listed it is available + builder.status(Status.AVAILABLE); - OperatingSystem os = diskImageToOperatingSystem.apply(from); - builder.operatingSystem(os); - String user = os.getFamily() == OsFamily.WINDOWS ? "Administrator" - : "root"; - builder.defaultCredentials(LoginCredentials.builder().identity(user) - .noPassword().build()); + OperatingSystem os = diskImageToOperatingSystem.apply(from); + builder.operatingSystem(os); + String user = os.getFamily() == OsFamily.WINDOWS ? "Administrator" + : "root"; + builder.defaultCredentials(LoginCredentials.builder().identity(user) + .noPassword().build()); - return builder.build(); - } + return builder.build(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystem.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystem.java index b1ce9a1aef..eeab199368 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystem.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystem.java @@ -38,36 +38,36 @@ import com.google.common.base.Function; */ @Singleton public class DiskImageToOperatingSystem implements - Function { + Function { - private static final Pattern OS_VERSION_PATTERN = Pattern - .compile("^.*?(\\d.*)\\s(32|64).*$"); + private static final Pattern OS_VERSION_PATTERN = Pattern + .compile("^.*?(\\d.*)\\s(32|64).*$"); - @Override - public OperatingSystem apply(DiskImage image) { - checkNotNull(image, "disk image"); + @Override + public OperatingSystem apply(DiskImage image) { + checkNotNull(image, "disk image"); - // convert to short name rhel to accommodate ComputeServiceUtils - // conventions - String shortOsName = image.getOsName().replace( - "Red Hat Enterprise Linux", "rhel"); - OsFamily osFamily = ComputeServiceUtils - .parseOsFamilyOrUnrecognized(shortOsName); - OperatingSystem.Builder builder = OperatingSystem.builder(); + // convert to short name rhel to accommodate ComputeServiceUtils + // conventions + String shortOsName = image.getOsName().replace( + "Red Hat Enterprise Linux", "rhel"); + OsFamily osFamily = ComputeServiceUtils + .parseOsFamilyOrUnrecognized(shortOsName); + OperatingSystem.Builder builder = OperatingSystem.builder(); - builder.name(image.getOsName()); - builder.family(osFamily); - builder.is64Bit(image.getOsName().contains("64bit") - || image.getOsName().contains("64 bit") - || image.getOsName().contains("x64")); - // OsType returns guest type (hvm, pv), which aws-ec2 is mapping to arch - builder.arch(image.getOsType()); - Matcher m = OS_VERSION_PATTERN.matcher(image.getOsName()); - if (m.matches()) { - builder.version(m.group(1)); - } - builder.description(image.getOsName()); + builder.name(image.getOsName()); + builder.family(osFamily); + builder.is64Bit(image.getOsName().contains("64bit") + || image.getOsName().contains("64 bit") + || image.getOsName().contains("x64")); + // OsType returns guest type (hvm, pv), which aws-ec2 is mapping to arch + builder.arch(image.getOsType()); + Matcher m = OS_VERSION_PATTERN.matcher(image.getOsName()); + if (m.matches()) { + builder.version(m.group(1)); + } + builder.description(image.getOsName()); - return builder.build(); - } + return builder.build(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskToVolume.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskToVolume.java index c9f4067632..e218cf0143 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskToVolume.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskToVolume.java @@ -20,12 +20,13 @@ package org.jclouds.fujitsu.fgcp.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Function; +import javax.inject.Singleton; + import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.VolumeBuilder; import org.jclouds.fujitsu.fgcp.domain.Disk; -import javax.inject.Singleton; +import com.google.common.base.Function; /** * Created by IntelliJ IDEA. @@ -35,19 +36,19 @@ import javax.inject.Singleton; @Singleton public class DiskToVolume implements Function { - @Override - public Volume apply(Disk disk) { - checkNotNull(disk, "disk"); + @Override + public Volume apply(Disk disk) { + checkNotNull(disk, "disk"); - VolumeBuilder builder = new VolumeBuilder(); + VolumeBuilder builder = new VolumeBuilder(); - builder.size(1000f * Float.valueOf(disk.getSize())); - // "Disk"'s are additional disks; they can't be booted disk(?) - builder.bootDevice(false); - builder.durable(true); - builder.type(Volume.Type.SAN); - builder.id("type: " + disk.getType() + " usage: " + disk.getUsage()); + builder.size(1000f * Float.valueOf(disk.getSize())); + // "Disk"'s are additional disks; they can't be booted disk(?) + builder.bootDevice(false); + builder.durable(true); + builder.type(Volume.Type.SAN); + builder.id("type: " + disk.getType() + " usage: " + disk.getUsage()); - return builder.build(); - } + return builder.build(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToFirewallId.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToFirewallId.java index 2e91f2bb4a..82beebbef8 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToFirewallId.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToFirewallId.java @@ -34,18 +34,18 @@ import com.google.common.base.Function; @Singleton public class ResourceIdToFirewallId implements Function { - private ResourceIdToSystemId toSystemId; + private ResourceIdToSystemId toSystemId; - @Inject - private ResourceIdToFirewallId(ResourceIdToSystemId resourceIdToSystemId) { - this.toSystemId = checkNotNull(resourceIdToSystemId, - "resourceIdToSystemId"); - } + @Inject + private ResourceIdToFirewallId(ResourceIdToSystemId resourceIdToSystemId) { + this.toSystemId = checkNotNull(resourceIdToSystemId, + "resourceIdToSystemId"); + } - @Override - public String apply(String id) { - checkNotNull(id, "resource id"); + @Override + public String apply(String id) { + checkNotNull(id, "resource id"); - return toSystemId.apply(id) + "-S-0001"; - } + return toSystemId.apply(id) + "-S-0001"; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToSystemId.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToSystemId.java index 01b1891cf7..229a236101 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToSystemId.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ResourceIdToSystemId.java @@ -37,16 +37,16 @@ import com.google.common.base.Function; @Singleton public class ResourceIdToSystemId implements Function { - @Override - public String apply(String id) { - checkNotNull(id, "resource id"); + @Override + public String apply(String id) { + checkNotNull(id, "resource id"); - Pattern pattern = Pattern.compile("^(\\w+-\\w+)\\b.*"); - Matcher matcher = pattern.matcher((String) id); + Pattern pattern = Pattern.compile("^(\\w+-\\w+)\\b.*"); + Matcher matcher = pattern.matcher((String) id); - checkArgument(matcher.find(), - "no valid resource id found: " + id.toString()); + checkArgument(matcher.find(), + "no valid resource id found: " + id.toString()); - return matcher.group(1); - } + return matcher.group(1); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ServerTypeToHardware.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ServerTypeToHardware.java index ec99cf56f4..fc0ed61e2c 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ServerTypeToHardware.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/ServerTypeToHardware.java @@ -39,30 +39,30 @@ import com.google.common.collect.Iterables; */ @Singleton public class ServerTypeToHardware implements Function { - private final CPUToProcessor cpuToProcessor; - private final DiskToVolume diskToVolume; + private final CPUToProcessor cpuToProcessor; + private final DiskToVolume diskToVolume; - @Inject - public ServerTypeToHardware(CPUToProcessor cpuToProcessor, - DiskToVolume diskToVolume) { - this.cpuToProcessor = checkNotNull(cpuToProcessor); - this.diskToVolume = checkNotNull(diskToVolume); - } + @Inject + public ServerTypeToHardware(CPUToProcessor cpuToProcessor, + DiskToVolume diskToVolume) { + this.cpuToProcessor = checkNotNull(cpuToProcessor); + this.diskToVolume = checkNotNull(diskToVolume); + } - @Override - public Hardware apply(ServerType from) { - checkNotNull(from, "ServerType"); - HardwareBuilder builder = new HardwareBuilder(); + @Override + public Hardware apply(ServerType from) { + checkNotNull(from, "ServerType"); + HardwareBuilder builder = new HardwareBuilder(); - builder.ids(from.getId()); - builder.name(from.getName()); - builder.ram((int) (1000d * Double.valueOf(from.getMemory().getSize()))); - builder.processor(cpuToProcessor.apply(from.getCpu())); - builder.supportsImage(Predicates. alwaysTrue()); - // all servers are 64bit. The OS however may be 32 bit. - builder.is64Bit(true); - builder.volumes(Iterables.transform(from.getDisks(), diskToVolume)); + builder.ids(from.getId()); + builder.name(from.getName()); + builder.ram((int) (1000d * Double.valueOf(from.getMemory().getSize()))); + builder.processor(cpuToProcessor.apply(from.getCpu())); + builder.supportsImage(Predicates. alwaysTrue()); + // all servers are 64bit. The OS however may be 32 bit. + builder.is64Bit(true); + builder.volumes(Iterables.transform(from.getDisks(), diskToVolume)); - return builder.build(); - } + return builder.build(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/SingleElementResponseToElement.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/SingleElementResponseToElement.java index b8677a4f96..3f672adcb8 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/SingleElementResponseToElement.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/SingleElementResponseToElement.java @@ -25,10 +25,10 @@ import org.jclouds.fujitsu.fgcp.xml.internal.SingleElementResponse; import com.google.common.base.Function; public class SingleElementResponseToElement implements - Function { + Function { - @Override - public Object apply(SingleElementResponse r) { - return checkNotNull(r, "response").getElement(); - } + @Override + public Object apply(SingleElementResponse r) { + return checkNotNull(r, "response").getElement(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/VServerMetadataToNodeMetadata.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/VServerMetadataToNodeMetadata.java index 66c390be0f..3da3d3e9dd 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/VServerMetadataToNodeMetadata.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/functions/VServerMetadataToNodeMetadata.java @@ -59,187 +59,187 @@ import com.google.common.collect.Iterables; */ @Singleton public class VServerMetadataToNodeMetadata implements - Function { + Function { - public static final Map vServerToStatus = ImmutableMap - . builder() - .put(VServerStatus.DEPLOYING, Status.PENDING) - .put(VServerStatus.RUNNING, Status.RUNNING) - .put(VServerStatus.STOPPING, Status.PENDING) - .put(VServerStatus.STOPPED, Status.SUSPENDED) - .put(VServerStatus.STARTING, Status.PENDING) - .put(VServerStatus.FAILOVER, Status.RUNNING) - .put(VServerStatus.UNEXPECTED_STOP, Status.SUSPENDED) - .put(VServerStatus.RESTORING, Status.PENDING) - .put(VServerStatus.BACKUP_ING, Status.PENDING) - .put(VServerStatus.ERROR, Status.ERROR) - .put(VServerStatus.START_ERROR, Status.ERROR) - .put(VServerStatus.STOP_ERROR, Status.ERROR) - .put(VServerStatus.CHANGE_TYPE, Status.PENDING) - .put(VServerStatus.REGISTERING, Status.PENDING) - .put(VServerStatus.UNRECOGNIZED, Status.UNRECOGNIZED).build(); + public static final Map vServerToStatus = ImmutableMap + . builder() + .put(VServerStatus.DEPLOYING, Status.PENDING) + .put(VServerStatus.RUNNING, Status.RUNNING) + .put(VServerStatus.STOPPING, Status.PENDING) + .put(VServerStatus.STOPPED, Status.SUSPENDED) + .put(VServerStatus.STARTING, Status.PENDING) + .put(VServerStatus.FAILOVER, Status.RUNNING) + .put(VServerStatus.UNEXPECTED_STOP, Status.SUSPENDED) + .put(VServerStatus.RESTORING, Status.PENDING) + .put(VServerStatus.BACKUP_ING, Status.PENDING) + .put(VServerStatus.ERROR, Status.ERROR) + .put(VServerStatus.START_ERROR, Status.ERROR) + .put(VServerStatus.STOP_ERROR, Status.ERROR) + .put(VServerStatus.CHANGE_TYPE, Status.PENDING) + .put(VServerStatus.REGISTERING, Status.PENDING) + .put(VServerStatus.UNRECOGNIZED, Status.UNRECOGNIZED).build(); - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; - protected final Supplier> locations; - protected final Supplier> images; - protected final Supplier> hardwares; - protected final GroupNamingConvention nodeNamingConvention; + protected final Supplier> locations; + protected final Supplier> images; + protected final Supplier> hardwares; + protected final GroupNamingConvention nodeNamingConvention; - private static class FindImageForVServer implements Predicate { - private final VServer server; + private static class FindImageForVServer implements Predicate { + private final VServer server; - private FindImageForVServer(VServer server) { - this.server = server; - } + private FindImageForVServer(VServer server) { + this.server = server; + } - @Override - public boolean apply(Image input) { - return input.getId().equals(server.getDiskimageId()); - } - } + @Override + public boolean apply(Image input) { + return input.getId().equals(server.getDiskimageId()); + } + } - protected Image parseImage(VServer from) { - try { - return Iterables.find(images.get(), new FindImageForVServer(from)); - } catch (NoSuchElementException e) { - logger.warn("could not find a matching image for server %s", from); - } - return null; - } + protected Image parseImage(VServer from) { + try { + return Iterables.find(images.get(), new FindImageForVServer(from)); + } catch (NoSuchElementException e) { + logger.warn("could not find a matching image for server %s", from); + } + return null; + } - private static class FindHardwareForServerType implements - Predicate { - private final String type; + private static class FindHardwareForServerType implements + Predicate { + private final String type; - private FindHardwareForServerType(String type) { - this.type = type; - } + private FindHardwareForServerType(String type) { + this.type = type; + } - @Override - public boolean apply(Hardware input) { - return input.getName().equals(type); - } - } + @Override + public boolean apply(Hardware input) { + return input.getName().equals(type); + } + } - protected Hardware parseHardware(String from) { - try { - return Iterables.find(hardwares.get(), - new FindHardwareForServerType(from)); - } catch (NoSuchElementException e) { - logger.warn( - "could not find a matching hardware for server type %s", - from); - } - return null; - } + protected Hardware parseHardware(String from) { + try { + return Iterables.find(hardwares.get(), + new FindHardwareForServerType(from)); + } catch (NoSuchElementException e) { + logger.warn( + "could not find a matching hardware for server type %s", + from); + } + return null; + } - private static class FindLocationForVServer implements Predicate { - private final VServerWithVNICs server; + private static class FindLocationForVServer implements Predicate { + private final VServerWithVNICs server; - private FindLocationForVServer(VServerWithVNICs server) { - this.server = server; - } + private FindLocationForVServer(VServerWithVNICs server) { + this.server = server; + } - @Override - public boolean apply(Location input) { - return input.getId().equals( - Iterables.getLast(server.getVnics()).getNetworkId()); - } - } + @Override + public boolean apply(Location input) { + return input.getId().equals( + Iterables.getLast(server.getVnics()).getNetworkId()); + } + } - protected Location parseLocation(VServerWithVNICs from) { - try { - return Iterables.find(locations.get(), new FindLocationForVServer( - from)); - } catch (NoSuchElementException e) { - logger.warn("could not find a matching realm for server %s", from); - } - return null; - } + protected Location parseLocation(VServerWithVNICs from) { + try { + return Iterables.find(locations.get(), new FindLocationForVServer( + from)); + } catch (NoSuchElementException e) { + logger.warn("could not find a matching realm for server %s", from); + } + return null; + } - @Inject - VServerMetadataToNodeMetadata( - @Memoized Supplier> locations, - @Memoized Supplier> images, - @Memoized Supplier> hardwares, - GroupNamingConvention.Factory namingConvention) { - this.images = checkNotNull(images, "images"); - this.locations = checkNotNull(locations, "locations"); - this.hardwares = checkNotNull(hardwares, "hardwares"); - this.nodeNamingConvention = checkNotNull(namingConvention, - "namingConvention").createWithoutPrefix(); - } + @Inject + VServerMetadataToNodeMetadata( + @Memoized Supplier> locations, + @Memoized Supplier> images, + @Memoized Supplier> hardwares, + GroupNamingConvention.Factory namingConvention) { + this.images = checkNotNull(images, "images"); + this.locations = checkNotNull(locations, "locations"); + this.hardwares = checkNotNull(hardwares, "hardwares"); + this.nodeNamingConvention = checkNotNull(namingConvention, + "namingConvention").createWithoutPrefix(); + } - @Override - public NodeMetadata apply(VServerMetadata from) { - NodeMetadataBuilder builder = new NodeMetadataBuilder(); + @Override + public NodeMetadata apply(VServerMetadata from) { + NodeMetadataBuilder builder = new NodeMetadataBuilder(); - builder.ids(from.getId()); - builder.name(from.getName()); - builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from - .getName())); - if (from.getStatus() == null) - System.out.println("status null for: " + from.getId() + ": " - + from.getName()); + builder.ids(from.getId()); + builder.name(from.getName()); + builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from + .getName())); + if (from.getStatus() == null) + System.out.println("status null for: " + from.getId() + ": " + + from.getName()); - builder.status(vServerToStatus.get(from.getStatus())); - builder.privateAddresses(ImmutableSet. of()); - builder.publicAddresses(ImmutableSet. of()); + builder.status(vServerToStatus.get(from.getStatus())); + builder.privateAddresses(ImmutableSet. of()); + builder.publicAddresses(ImmutableSet. of()); - // - // if (from.getIps() != null) { - // - // builder.publicAddresses(Collections2.transform(from.getIps(), - // new Function() { - // - // @Override - // public String apply(PublicIP input) { - // return input.getAddress(); - // } - // - // })); - // } + // + // if (from.getIps() != null) { + // + // builder.publicAddresses(Collections2.transform(from.getIps(), + // new Function() { + // + // @Override + // public String apply(PublicIP input) { + // return input.getAddress(); + // } + // + // })); + // } - if (from.getServer() != null) { + if (from.getServer() != null) { - builder.imageId(from.getServer().getDiskimageId()); - builder.hardware(parseHardware(from.getServer().getType())); + builder.imageId(from.getServer().getDiskimageId()); + builder.hardware(parseHardware(from.getServer().getType())); - LoginCredentials.Builder credentialsBuilder = LoginCredentials - .builder().password(from.getInitialPassword()); + LoginCredentials.Builder credentialsBuilder = LoginCredentials + .builder().password(from.getInitialPassword()); - Image image = parseImage(from.getServer()); - // image will not be found if server was created a while back and - // the image has since been destroyed or discontinued (like an old - // CentOS version) - if (image != null) { + Image image = parseImage(from.getServer()); + // image will not be found if server was created a while back and + // the image has since been destroyed or discontinued (like an old + // CentOS version) + if (image != null) { - builder.operatingSystem(image.getOperatingSystem()); - String user = image.getDefaultCredentials().getUser(); - credentialsBuilder.identity(user); + builder.operatingSystem(image.getOperatingSystem()); + String user = image.getDefaultCredentials().getUser(); + credentialsBuilder.identity(user); + } + + builder.credentials(credentialsBuilder.build()); + + if (from.getServer() instanceof VServerWithVNICs) { + + VServerWithVNICs server = (VServerWithVNICs) from.getServer(); + builder.location(parseLocation(server)); + List ips = new ArrayList(); + if (server.getVnics() != null && server.getVnics().iterator().next().getPrivateIp() != null) { + ips.add(server.getVnics().iterator().next().getPrivateIp()); } + builder.privateAddresses(ips); + } + } + if (from.getTemplate() != null) { + // when creating a new node + builder.location(from.getTemplate().getLocation()); + } - builder.credentials(credentialsBuilder.build()); - - if (from.getServer() instanceof VServerWithVNICs) { - - VServerWithVNICs server = (VServerWithVNICs) from.getServer(); - builder.location(parseLocation(server)); - List ips = new ArrayList(); - if (server.getVnics() != null && server.getVnics().iterator().next().getPrivateIp() != null) { - ips.add(server.getVnics().iterator().next().getPrivateIp()); - } - builder.privateAddresses(ips); - } - } - if (from.getTemplate() != null) { - // when creating a new node - builder.location(from.getTemplate().getLocation()); - } - - return builder.build(); - } + return builder.build(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/ServerStopped.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/ServerStopped.java index bda281ca71..4c9c96bc6a 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/ServerStopped.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/ServerStopped.java @@ -37,27 +37,27 @@ import com.google.common.base.Predicate; @Singleton public class ServerStopped implements Predicate { - private final FGCPApi api; + private final FGCPApi api; - @Resource - protected Logger logger = Logger.NULL; + @Resource + protected Logger logger = Logger.NULL; - @Inject - public ServerStopped(FGCPApi api) { - this.api = api; - } + @Inject + public ServerStopped(FGCPApi api) { + this.api = api; + } - public boolean apply(String serverId) { - logger.trace("looking for status on server %s", serverId); + public boolean apply(String serverId) { + logger.trace("looking for status on server %s", serverId); - VServerStatus status = api.getVirtualServerApi().getStatus(serverId); - logger.trace("looking for status on server %s: currently: %s", - serverId, status); + VServerStatus status = api.getVirtualServerApi().getStatus(serverId); + logger.trace("looking for status on server %s: currently: %s", + serverId, status); - if (status == VServerStatus.ERROR || status == VServerStatus.STOP_ERROR) - throw new IllegalStateException("server not around or in error: " - + status); - return status == VServerStatus.STOPPED; - } + if (status == VServerStatus.ERROR || status == VServerStatus.STOP_ERROR) + throw new IllegalStateException("server not around or in error: " + + status); + return status == VServerStatus.STOPPED; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/SystemStatusNormal.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/SystemStatusNormal.java index 881233560e..c11191edf7 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/SystemStatusNormal.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/predicates/SystemStatusNormal.java @@ -23,7 +23,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.fujitsu.fgcp.FGCPApi; -import org.jclouds.fujitsu.fgcp.domain.VServerStatus; import org.jclouds.fujitsu.fgcp.domain.VSystemStatus; import org.jclouds.logging.Logger; @@ -37,26 +36,26 @@ import com.google.common.base.Predicate; @Singleton public class SystemStatusNormal implements Predicate { - private final FGCPApi api; + private final FGCPApi api; - @Resource - protected Logger logger = Logger.NULL; + @Resource + protected Logger logger = Logger.NULL; - @Inject - public SystemStatusNormal(FGCPApi api) { - this.api = api; - } + @Inject + public SystemStatusNormal(FGCPApi api) { + this.api = api; + } - public boolean apply(String systemId) { - logger.trace("looking for status on system %s", systemId); + public boolean apply(String systemId) { + logger.trace("looking for status on system %s", systemId); - VSystemStatus status = api.getVirtualSystemApi().getStatus(systemId); - logger.trace("looking for status on system %s: currently: %s", - systemId, status); + VSystemStatus status = api.getVirtualSystemApi().getStatus(systemId); + logger.trace("looking for status on system %s: currently: %s", + systemId, status); - if (status == VSystemStatus.ERROR) - throw new IllegalStateException("system in error: " + status); - return status == VSystemStatus.NORMAL; - } + if (status == VSystemStatus.ERROR) + throw new IllegalStateException("system in error: " + status); + return status == VSystemStatus.NORMAL; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/FGCPComputeServiceAdapter.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/FGCPComputeServiceAdapter.java index 732a8a6d09..ef989c5254 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/FGCPComputeServiceAdapter.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/FGCPComputeServiceAdapter.java @@ -44,10 +44,8 @@ import org.jclouds.fujitsu.fgcp.compute.functions.ResourceIdToSystemId; import org.jclouds.fujitsu.fgcp.compute.predicates.ServerStopped; import org.jclouds.fujitsu.fgcp.compute.predicates.SystemStatusNormal; import org.jclouds.fujitsu.fgcp.compute.strategy.VServerMetadata.Builder; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerConfiguration; import org.jclouds.fujitsu.fgcp.domain.DiskImage; import org.jclouds.fujitsu.fgcp.domain.ServerType; -import org.jclouds.fujitsu.fgcp.domain.VServer; import org.jclouds.fujitsu.fgcp.domain.VServerStatus; import org.jclouds.fujitsu.fgcp.domain.VServerWithDetails; import org.jclouds.fujitsu.fgcp.domain.VServerWithVNICs; @@ -59,7 +57,6 @@ import org.jclouds.predicates.RetryablePredicate; import com.google.common.base.Predicate; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -72,223 +69,223 @@ import com.google.common.util.concurrent.ListenableFuture; */ @Singleton public class FGCPComputeServiceAdapter implements - ComputeServiceAdapter { + ComputeServiceAdapter { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; - private final FGCPApi api; - private final FGCPAsyncApi asyncApi; - protected Predicate serverStopped = null; - protected Predicate serverCreated = null; - protected Predicate systemNormal = null; - protected ResourceIdToFirewallId toFirewallId = null; - protected ResourceIdToSystemId toSystemId = null; + private final FGCPApi api; + private final FGCPAsyncApi asyncApi; + protected Predicate serverStopped = null; + protected Predicate serverCreated = null; + protected Predicate systemNormal = null; + protected ResourceIdToFirewallId toFirewallId = null; + protected ResourceIdToSystemId toSystemId = null; - @Inject - public FGCPComputeServiceAdapter(FGCPApi api, FGCPAsyncApi asyncApi, - ServerStopped serverStopped, SystemStatusNormal systemNormal, - Timeouts timeouts, ResourceIdToFirewallId toFirewallId, - ResourceIdToSystemId toSystemId) { - this.api = checkNotNull(api, "api"); - this.asyncApi = checkNotNull(asyncApi, "asyncApi"); - this.serverStopped = new RetryablePredicate( - checkNotNull(serverStopped), timeouts.nodeSuspended); - this.serverCreated = new RetryablePredicate( - checkNotNull(serverStopped), timeouts.nodeRunning); - this.systemNormal = new RetryablePredicate( - checkNotNull(systemNormal), timeouts.nodeTerminated); - this.toFirewallId = checkNotNull(toFirewallId, "ResourceIdToFirewallId"); - this.toSystemId = checkNotNull(toSystemId, "ResourceIdToSystemId"); - } + @Inject + public FGCPComputeServiceAdapter(FGCPApi api, FGCPAsyncApi asyncApi, + ServerStopped serverStopped, SystemStatusNormal systemNormal, + Timeouts timeouts, ResourceIdToFirewallId toFirewallId, + ResourceIdToSystemId toSystemId) { + this.api = checkNotNull(api, "api"); + this.asyncApi = checkNotNull(asyncApi, "asyncApi"); + this.serverStopped = new RetryablePredicate( + checkNotNull(serverStopped), timeouts.nodeSuspended); + this.serverCreated = new RetryablePredicate( + checkNotNull(serverStopped), timeouts.nodeRunning); + this.systemNormal = new RetryablePredicate( + checkNotNull(systemNormal), timeouts.nodeTerminated); + this.toFirewallId = checkNotNull(toFirewallId, "ResourceIdToFirewallId"); + this.toSystemId = checkNotNull(toSystemId, "ResourceIdToSystemId"); + } - /** - * {@inheritDoc} - */ - @Override - public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName( - String group, String name, Template template) { - // Find vsys (how? create new? default to first found?) - // Target network DMZ/SECURE1/SECURE2 (how? default to DMZ?) - // Determine remaining params: [vserverType,diskImageId,networkId] - // what if no vsys exists yet? Location.AU(.contractId) creates 3? tier - // skeleton vsys and DMZ is picked? - String id = api.getVirtualSystemApi().createServer(name, - template.getHardware().getName(), template.getImage().getId(), - template.getLocation().getId()); + /** + * {@inheritDoc} + */ + @Override + public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName( + String group, String name, Template template) { + // Find vsys (how? create new? default to first found?) + // Target network DMZ/SECURE1/SECURE2 (how? default to DMZ?) + // Determine remaining params: [vserverType,diskImageId,networkId] + // what if no vsys exists yet? Location.AU(.contractId) creates 3? tier + // skeleton vsys and DMZ is picked? + String id = api.getVirtualSystemApi().createServer(name, + template.getHardware().getName(), template.getImage().getId(), + template.getLocation().getId()); - // wait until fully created (i.e. transitions to stopped status) - serverCreated.apply(id); - resumeNode(id); - VServerMetadata server = getNode(id); + // wait until fully created (i.e. transitions to stopped status) + serverCreated.apply(id); + resumeNode(id); + VServerMetadata server = getNode(id); - //do we need this? - server.setTemplate(template); - String user = template.getImage().getOperatingSystem().getFamily() == OsFamily.WINDOWS ? "Administrator" - : "root"; + //do we need this? + server.setTemplate(template); + String user = template.getImage().getOperatingSystem().getFamily() == OsFamily.WINDOWS ? "Administrator" + : "root"; - return new NodeAndInitialCredentials(server, - id, LoginCredentials.builder().identity(user) - .password(server.getInitialPassword()).build()); - } + return new NodeAndInitialCredentials(server, + id, LoginCredentials.builder().identity(user) + .password(server.getInitialPassword()).build()); + } - /** - * {@inheritDoc} - */ - @Override - public Iterable listHardwareProfiles() { - return api.getVirtualDCApi().listServerTypes(); - } + /** + * {@inheritDoc} + */ + @Override + public Iterable listHardwareProfiles() { + return api.getVirtualDCApi().listServerTypes(); + } - /** - * {@inheritDoc} - */ - @Override - public Iterable listImages() { - return api.getVirtualDCApi().listDiskImages(); - } + /** + * {@inheritDoc} + */ + @Override + public Iterable listImages() { + return api.getVirtualDCApi().listDiskImages(); + } - /** - * {@inheritDoc} - */ - @Override - public DiskImage getImage(String id) { - return api.getDiskImageApi().get(id); - } + /** + * {@inheritDoc} + */ + @Override + public DiskImage getImage(String id) { + return api.getDiskImageApi().get(id); + } - /** - * {@inheritDoc} - */ - @Override - public Iterable listLocations() { - // Not using the adapter to determine locations - // see SystemAndNetworkSegmentToLocationSupplier - return ImmutableSet. of(); - } + /** + * {@inheritDoc} + */ + @Override + public Iterable listLocations() { + // Not using the adapter to determine locations + // see SystemAndNetworkSegmentToLocationSupplier + return ImmutableSet. of(); + } - /** - * {@inheritDoc} - */ - @Override - public VServerMetadata getNode(String id) { - Builder builder = VServerMetadata.builder(); - builder.id(id); + /** + * {@inheritDoc} + */ + @Override + public VServerMetadata getNode(String id) { + Builder builder = VServerMetadata.builder(); + builder.id(id); - List> futures = new ArrayList>(); + List> futures = new ArrayList>(); - futures.add(asyncApi.getVirtualServerApi().getDetails(id)); - futures.add(asyncApi.getVirtualServerApi().getStatus(id)); - futures.add(asyncApi.getVirtualServerApi().getInitialPassword(id)); - // mapped public ips? - String fwId = toFirewallId.apply(id); -// futures.add(asyncApi.getBuiltinServerApi().getConfiguration(fwId, -// BuiltinServerConfiguration.SLB_RULE)); - try { - List results = Futures.successfulAsList(futures).get(); - VServerWithDetails server = (VServerWithDetails) results.get(0); - VServerStatus status = (VServerStatus) results.get(1); - System.out.println("getNode(" + id + ")'s getDetails: " + status +" - " + server); - if (server == null) { - server = api.getVirtualServerApi().getDetails(id); - System.out.println("getNode(" + id + ")'s getDetails(2) returns: " + server); + futures.add(asyncApi.getVirtualServerApi().getDetails(id)); + futures.add(asyncApi.getVirtualServerApi().getStatus(id)); + futures.add(asyncApi.getVirtualServerApi().getInitialPassword(id)); + // mapped public ips? + String fwId = toFirewallId.apply(id); +// futures.add(asyncApi.getBuiltinServerApi().getConfiguration(fwId, +// BuiltinServerConfiguration.SLB_RULE)); + try { + List results = Futures.successfulAsList(futures).get(); + VServerWithDetails server = (VServerWithDetails) results.get(0); + VServerStatus status = (VServerStatus) results.get(1); + System.out.println("getNode(" + id + ")'s getDetails: " + status +" - " + server); + if (server == null) { + server = api.getVirtualServerApi().getDetails(id); + System.out.println("getNode(" + id + ")'s getDetails(2) returns: " + server); + } + builder.serverWithDetails(server); + builder.status(status == null ? VServerStatus.UNRECOGNIZED : status); +// System.out.println("status in adapter#getNode: " +// + (VServerStatus) results.get(1) +// +" for " +// + server.getId()); + builder.initialPassword((String) results.get(2)); +// SLB slb = ((BuiltinServer) results.get(4)).; +// slb. + } catch (InterruptedException e) { + throw Throwables.propagate(e); + } catch (ExecutionException e) { + throw Throwables.propagate(e); + } + return builder.build(); + } + + /** + * {@inheritDoc} + */ + @Override + public Iterable listNodes() { + ImmutableSet.Builder servers = ImmutableSet + . builder(); + + Set systems = api.getVirtualDCApi().listVirtualSystems(); + List> futures = new ArrayList>(); + for (VSystem system : systems) { + + futures.add(asyncApi.getVirtualSystemApi().getDetails( + system.getId())); + } + try { + for (VSystemWithDetails system : Futures.successfulAsList(futures) + .get()) { + + if (system != null) { + + for (VServerWithVNICs server : system.getServers()) { + + // skip FW (S-0001) and SLBs (>0 for SLB) + if (!server.getId().endsWith("-S-0001") && server.getVnics().iterator().next().getNicNo() == 0) { + + servers.add(getNode(server.getId())); +// Builder builder = VServerMetadata.builder(); +// builder.server(server); +// builder.status(VServerStatus.UNRECOGNIZED); +// servers.add(builder.build()); + } + } } - builder.serverWithDetails(server); - builder.status(status == null ? VServerStatus.UNRECOGNIZED : status); -// System.out.println("status in adapter#getNode: " -// + (VServerStatus) results.get(1) -// +" for " -// + server.getId()); - builder.initialPassword((String) results.get(2)); -// SLB slb = ((BuiltinServer) results.get(4)).; -// slb. - } catch (InterruptedException e) { - throw Throwables.propagate(e); - } catch (ExecutionException e) { - throw Throwables.propagate(e); - } - return builder.build(); - } + } + } catch (InterruptedException e) { + throw Throwables.propagate(e); + } catch (ExecutionException e) { + throw Throwables.propagate(e); + } - /** - * {@inheritDoc} - */ - @Override - public Iterable listNodes() { - ImmutableSet.Builder servers = ImmutableSet - . builder(); + return servers.build(); + } - Set systems = api.getVirtualDCApi().listVirtualSystems(); - List> futures = new ArrayList>(); - for (VSystem system : systems) { + /** + * {@inheritDoc} + */ + @Override + public void destroyNode(String id) { + api.getVirtualServerApi().destroy(id); + // wait until fully destroyed + String systemId = toSystemId.apply(id); + systemNormal.apply(systemId); + } - futures.add(asyncApi.getVirtualSystemApi().getDetails( - system.getId())); - } - try { - for (VSystemWithDetails system : Futures.successfulAsList(futures) - .get()) { + /** + * {@inheritDoc} + */ + @Override + public void rebootNode(String id) { + suspendNode(id); + // wait until fully stopped + serverStopped.apply(id); + resumeNode(id); + } - if (system != null) { + /** + * {@inheritDoc} + */ + @Override + public void resumeNode(String id) { + api.getVirtualServerApi().start(id); + } - for (VServerWithVNICs server : system.getServers()) { - - // skip FW (S-0001) and SLBs (>0 for SLB) - if (!server.getId().endsWith("-S-0001") && server.getVnics().iterator().next().getNicNo() == 0) { - - servers.add(getNode(server.getId())); -// Builder builder = VServerMetadata.builder(); -// builder.server(server); -// builder.status(VServerStatus.UNRECOGNIZED); -// servers.add(builder.build()); - } - } - } - } - } catch (InterruptedException e) { - throw Throwables.propagate(e); - } catch (ExecutionException e) { - throw Throwables.propagate(e); - } - - return servers.build(); - } - - /** - * {@inheritDoc} - */ - @Override - public void destroyNode(String id) { - api.getVirtualServerApi().destroy(id); - // wait until fully destroyed - String systemId = toSystemId.apply(id); - systemNormal.apply(systemId); - } - - /** - * {@inheritDoc} - */ - @Override - public void rebootNode(String id) { - suspendNode(id); - // wait until fully stopped - serverStopped.apply(id); - resumeNode(id); - } - - /** - * {@inheritDoc} - */ - @Override - public void resumeNode(String id) { - api.getVirtualServerApi().start(id); - } - - /** - * {@inheritDoc} - */ - @Override - public void suspendNode(String id) { - api.getVirtualServerApi().stop(id); - } + /** + * {@inheritDoc} + */ + @Override + public void suspendNode(String id) { + api.getVirtualServerApi().stop(id); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/VServerMetadata.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/VServerMetadata.java index e9835ac349..d0eb0a1680 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/VServerMetadata.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/compute/strategy/VServerMetadata.java @@ -39,140 +39,140 @@ import com.google.common.collect.ImmutableSet; */ public class VServerMetadata { - protected VServer server; - protected String id; - protected String name; - protected Template template; - protected String initialPassword; - protected VServerStatus status = VServerStatus.UNRECOGNIZED; - protected Set ips; - protected DiskImage image; + protected VServer server; + protected String id; + protected String name; + protected Template template; + protected String initialPassword; + protected VServerStatus status = VServerStatus.UNRECOGNIZED; + protected Set ips; + protected DiskImage image; - public VServerMetadata(VServer server, String initialPassword, - VServerStatus status, DiskImage image, Set publicIps) { - this.server = checkNotNull(server, "server"); - this.initialPassword = initialPassword; - this.status = status; - this.image = image; - this.ips = publicIps; - id = server.getId(); - name = server.getName(); - } + public VServerMetadata(VServer server, String initialPassword, + VServerStatus status, DiskImage image, Set publicIps) { + this.server = checkNotNull(server, "server"); + this.initialPassword = initialPassword; + this.status = status; + this.image = image; + this.ips = publicIps; + id = server.getId(); + name = server.getName(); + } - public VServerMetadata(String id, String name, Template template, - VServerStatus status) { - this.id = checkNotNull(id, "id"); - this.name = checkNotNull(name, "name"); - this.template = checkNotNull(template, "template"); - this.status = checkNotNull(status, "status"); - } + public VServerMetadata(String id, String name, Template template, + VServerStatus status) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.template = checkNotNull(template, "template"); + this.status = checkNotNull(status, "status"); + } - public VServer getServer() { - return server; - } + public VServer getServer() { + return server; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public Template getTemplate() { - return template; - } + public Template getTemplate() { + return template; + } - public void setTemplate(Template template) { - this.template = template; - } + public void setTemplate(Template template) { + this.template = template; + } - public String getInitialPassword() { - return initialPassword; - } + public String getInitialPassword() { + return initialPassword; + } - public VServerStatus getStatus() { - return status; - } + public VServerStatus getStatus() { + return status; + } - public Set getIps() { - return ips; - } + public Set getIps() { + return ips; + } - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public static class Builder { - private VServer server; - private VServerWithVNICs serverWithDetails; - private String id; - private String name; - private Template template; - private String initialPassword; - private VServerStatus status = VServerStatus.UNRECOGNIZED; - private Set publicIps = ImmutableSet.of(); - private DiskImage image; + public static class Builder { + private VServer server; + private VServerWithVNICs serverWithDetails; + private String id; + private String name; + private Template template; + private String initialPassword; + private VServerStatus status = VServerStatus.UNRECOGNIZED; + private Set publicIps = ImmutableSet.of(); + private DiskImage image; - public Builder id(String id) { - this.id = id; - return this; - } + public Builder id(String id) { + this.id = id; + return this; + } - public Builder name(String name) { - this.name = name; - return this; - } + public Builder name(String name) { + this.name = name; + return this; + } - public Builder template(Template template) { - this.template = template; - return this; - } + public Builder template(Template template) { + this.template = template; + return this; + } -// public Builder server(VServer server) { -// this.server = server; -// return this; -// } +// public Builder server(VServer server) { +// this.server = server; +// return this; +// } - public Builder serverWithDetails(VServerWithVNICs serverWithDetails) { - this.serverWithDetails = serverWithDetails; - return this; - } + public Builder serverWithDetails(VServerWithVNICs serverWithDetails) { + this.serverWithDetails = serverWithDetails; + return this; + } - public Builder initialPassword(String password) { - this.initialPassword = password; - return this; - } + public Builder initialPassword(String password) { + this.initialPassword = password; + return this; + } - public Builder status(VServerStatus status) { - this.status = status; - return this; - } + public Builder status(VServerStatus status) { + this.status = status; + return this; + } - public Builder image(DiskImage image) { - this.image = image; - return this; - } + public Builder image(DiskImage image) { + this.image = image; + return this; + } - public Builder publicIps(Set publicIps) { - this.publicIps = publicIps; - return this; - } + public Builder publicIps(Set publicIps) { + this.publicIps = publicIps; + return this; + } - public VServerMetadata build() { - if (initialPassword == null) initialPassword = ""; - if (server != null) { - return new VServerMetadata(server, initialPassword, status, - image, publicIps); - } else if (serverWithDetails != null) { - return new VServerMetadata(serverWithDetails, initialPassword, - status, image, publicIps); - } else { - // sometimes these fields are null because the server is returning a verify error - if (id == null) id = "dummy-id"; - if (name == null) name = "dummy-name"; - return new VServerMetadata(id, name, template, status); - } - } - } + public VServerMetadata build() { + if (initialPassword == null) initialPassword = ""; + if (server != null) { + return new VServerMetadata(server, initialPassword, status, + image, publicIps); + } else if (serverWithDetails != null) { + return new VServerMetadata(serverWithDetails, initialPassword, + status, image, publicIps); + } else { + // sometimes these fields are null because the server is returning a verify error + if (id == null) id = "dummy-id"; + if (name == null) name = "dummy-name"; + return new VServerMetadata(id, name, template, status); + } + } + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/AddressRange.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/AddressRange.java index 032a718e16..30755a9cc4 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/AddressRange.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/AddressRange.java @@ -28,30 +28,30 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "addressrange") public class AddressRange { - private String range; + private String range; - private String from; + private String from; - private String to; + private String to; - /** - * @return the range - */ - public String getRange() { - return range; - } + /** + * @return the range + */ + public String getRange() { + return range; + } - /** - * @return the from - */ - public String getFrom() { - return from; - } + /** + * @return the from + */ + public String getFrom() { + return from; + } - /** - * @return the to - */ - public String getTo() { - return to; - } + /** + * @return the to + */ + public String getTo() { + return to; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServer.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServer.java index 911b05c5f0..cd8325147a 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServer.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServer.java @@ -29,45 +29,45 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "efm") public class BuiltinServer { - @XmlElement(name = "efmId") - private String id; - @XmlElement(name = "efmType") - private BuiltinServerType builtinServerType; - @XmlElement(name = "efmName") - private String name; - private String creator; - private String slbVip; - private Firewall firewall; - private SLB loadbalancer; + @XmlElement(name = "efmId") + private String id; + @XmlElement(name = "efmType") + private BuiltinServerType builtinServerType; + @XmlElement(name = "efmName") + private String name; + private String creator; + private String slbVip; + private Firewall firewall; + private SLB loadbalancer; - public enum BuiltinServerType {FW, SLB} + public enum BuiltinServerType {FW, SLB} - public String getId() { - return id; - } + public String getId() { + return id; + } - public BuiltinServerType getType() { - return builtinServerType; - } + public BuiltinServerType getType() { + return builtinServerType; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getCreator() { - return creator; - } + public String getCreator() { + return creator; + } - public String getSlbVip() { - return slbVip; - } + public String getSlbVip() { + return slbVip; + } - public Firewall getFirewall() { - return firewall; - } + public Firewall getFirewall() { + return firewall; + } - public SLB getLoadbalancer() { - return loadbalancer; - } + public SLB getLoadbalancer() { + return loadbalancer; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerBackup.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerBackup.java index 79374f9356..8548758f12 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerBackup.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerBackup.java @@ -31,45 +31,45 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "backup") public class BuiltinServerBackup { - @XmlElement(name = "backupId") - private String id; - @XmlElement(name = "backupTime") - private String time; + @XmlElement(name = "backupId") + private String id; + @XmlElement(name = "backupTime") + private String time; - /** - * @return the id - */ - public String getId() { - return id; - } + /** + * @return the id + */ + public String getId() { + return id; + } - /** - * @return the time - */ - public String getTime() { - return time; - } + /** + * @return the time + */ + public String getTime() { + return time; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - BuiltinServerBackup that = BuiltinServerBackup.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BuiltinServerBackup that = BuiltinServerBackup.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("time", time).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("time", time).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerConfiguration.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerConfiguration.java index 5f7fa6ac23..1225446560 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerConfiguration.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerConfiguration.java @@ -33,36 +33,36 @@ import com.google.common.base.CaseFormat; * @author Dies Koper */ public enum BuiltinServerConfiguration { - FW_NAT_RULE, - FW_DNS, - FW_POLICY, - FW_LOG, - FW_LIMIT_POLICY, - SLB_RULE, - SLB_LOAD_STATISTICS, - SLB_ERROR_STATISTICS, - SLB_CERTIFICATE_LIST, - EFM_UPDATE, - SLB_CONNECTION, - UNRECOGNIZED; + FW_NAT_RULE, + FW_DNS, + FW_POLICY, + FW_LOG, + FW_LIMIT_POLICY, + SLB_RULE, + SLB_LOAD_STATISTICS, + SLB_ERROR_STATISTICS, + SLB_CERTIFICATE_LIST, + EFM_UPDATE, + SLB_CONNECTION, + UNRECOGNIZED; - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); - } + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } - @Override - public String toString() { - return value(); - } + @Override + public String toString() { + return value(); + } - public static BuiltinServerConfiguration fromValue(String configuration) { - try { - return valueOf(CaseFormat.UPPER_CAMEL - .to(CaseFormat.UPPER_UNDERSCORE, - checkNotNull(configuration, "configuration"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static BuiltinServerConfiguration fromValue(String configuration) { + try { + return valueOf(CaseFormat.UPPER_CAMEL + .to(CaseFormat.UPPER_UNDERSCORE, + checkNotNull(configuration, "configuration"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerStatus.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerStatus.java index 4ee7ba279d..9df85d32b2 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerStatus.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/BuiltinServerStatus.java @@ -18,12 +18,12 @@ */ package org.jclouds.fujitsu.fgcp.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.CaseFormat; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Possible statuses of a built-in server, also called extended function module * (EFM), such as a firewall or load balancer (SLB). @@ -36,25 +36,25 @@ import static com.google.common.base.Preconditions.checkNotNull; */ @XmlRootElement(name = "efmStatus") public enum BuiltinServerStatus { - DEPLOYING, RUNNING, STOPPING, STOPPED, STARTING, FAILOVER, UNEXPECTED_STOP, RESTORING, BACKUP_ING, ERROR, EXECUTE_NETWORK_SERVER, START_ERROR, STOP_ERROR, UPDATE, BACKOUT, UNRECOGNIZED; + DEPLOYING, RUNNING, STOPPING, STOPPED, STARTING, FAILOVER, UNEXPECTED_STOP, RESTORING, BACKUP_ING, ERROR, EXECUTE_NETWORK_SERVER, START_ERROR, STOP_ERROR, UPDATE, BACKOUT, UNRECOGNIZED; - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); - } + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } - @Override - public String toString() { - return value(); - } + @Override + public String toString() { + return value(); + } - public static BuiltinServerStatus fromValue(String status) { - try { - return valueOf(CaseFormat.UPPER_CAMEL - .to(CaseFormat.UPPER_UNDERSCORE, - checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static BuiltinServerStatus fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL + .to(CaseFormat.UPPER_UNDERSCORE, + checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/CPU.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/CPU.java index b49b9e8196..f7fa487569 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/CPU.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/CPU.java @@ -30,48 +30,48 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "cpu") public class CPU { - @XmlElement(name = "cpuArch") - private String arch; - @XmlElement(name = "cpuPerf") - private double speedPerCore; - @XmlElement(name = "numOfCpu") - private double cores; + @XmlElement(name = "cpuArch") + private String arch; + @XmlElement(name = "cpuPerf") + private double speedPerCore; + @XmlElement(name = "numOfCpu") + private double cores; - public String getArch() { - return arch; - } + public String getArch() { + return arch; + } - public double getSpeedPerCore() { - return speedPerCore; - } + public double getSpeedPerCore() { + return speedPerCore; + } - public double getCores() { - return cores; - } + public double getCores() { + return cores; + } - @Override - public int hashCode() { - return Objects.hashCode(cores, speedPerCore, arch); - } + @Override + public int hashCode() { + return Objects.hashCode(cores, speedPerCore, arch); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - CPU that = CPU.class.cast(obj); - return Objects.equal(this.cores, that.cores) - && Objects.equal(this.speedPerCore, that.speedPerCore) - && Objects.equal(this.arch, that.arch); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CPU that = CPU.class.cast(obj); + return Objects.equal(this.cores, that.cores) + && Objects.equal(this.speedPerCore, that.speedPerCore) + && Objects.equal(this.arch, that.arch); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("cores", cores).add("speedPerCore", speedPerCore) - .add("arch", arch).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("cores", cores).add("speedPerCore", speedPerCore) + .add("arch", arch).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Cause.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Cause.java index c2863db2b5..3e13e10804 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Cause.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Cause.java @@ -25,76 +25,76 @@ package org.jclouds.fujitsu.fgcp.domain; * @author Dies Koper */ public class Cause { - private String cat; + private String cat; - private String status; + private String status; - private String filePath; + private String filePath; - private String current; + private String current; - private String before; + private String before; - private String today; + private String today; - private String yesterday; + private String yesterday; - private String total; + private String total; - /** - * @return category - */ - public String getCat() { - return cat; - } + /** + * @return category + */ + public String getCat() { + return cat; + } - /** - * @return the status - */ - public String getStatus() { - return status; - } + /** + * @return the status + */ + public String getStatus() { + return status; + } - /** - * @return the filePath - */ - public String getFilePath() { - return filePath; - } + /** + * @return the filePath + */ + public String getFilePath() { + return filePath; + } - /** - * @return the current - */ - public String getCurrent() { - return current; - } + /** + * @return the current + */ + public String getCurrent() { + return current; + } - /** - * @return the before - */ - public String getBefore() { - return before; - } + /** + * @return the before + */ + public String getBefore() { + return before; + } - /** - * @return the today - */ - public String getToday() { - return today; - } + /** + * @return the today + */ + public String getToday() { + return today; + } - /** - * @return the yesterday - */ - public String getYesterday() { - return yesterday; - } + /** + * @return the yesterday + */ + public String getYesterday() { + return yesterday; + } - /** - * @return the total - */ - public String getTotal() { - return total; - } + /** + * @return the total + */ + public String getTotal() { + return total; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Direction.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Direction.java index b332fdcbb1..b76ad1db9f 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Direction.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Direction.java @@ -32,82 +32,82 @@ import com.google.common.collect.ImmutableSet; * @author Dies Koper */ public class Direction { - private String from; - private String to; - private Set policies = new LinkedHashSet(); - private Acceptable acceptable; - private Prefix prefix; - private int maxPolicyNum; + private String from; + private String to; + private Set policies = new LinkedHashSet(); + private Acceptable acceptable; + private Prefix prefix; + private int maxPolicyNum; - enum Acceptable {OK, NG} - enum Prefix {free, src, dst, proto, srcport, dstport, action, rule, tab} + enum Acceptable {OK, NG} + enum Prefix {free, src, dst, proto, srcport, dstport, action, rule, tab} - /** - * @return the from - */ - public String getFrom() { - return from; - } + /** + * @return the from + */ + public String getFrom() { + return from; + } - /** - * @return the to - */ - public String getTo() { - return to; - } + /** + * @return the to + */ + public String getTo() { + return to; + } - /** - * @return the policies - */ - public Set getPolicies() { - return policies == null ? ImmutableSet. of() : ImmutableSet - .copyOf(policies); - } + /** + * @return the policies + */ + public Set getPolicies() { + return policies == null ? ImmutableSet. of() : ImmutableSet + .copyOf(policies); + } - /** - * @return the acceptable - */ - public Acceptable getAcceptable() { - return acceptable; - } + /** + * @return the acceptable + */ + public Acceptable getAcceptable() { + return acceptable; + } - /** - * @return the prefix - */ - public Prefix getPrefix() { - return prefix; - } + /** + * @return the prefix + */ + public Prefix getPrefix() { + return prefix; + } - /** - * @return the maxPolicyNum - */ - public int getMaxPolicyNum() { - return maxPolicyNum; - } + /** + * @return the maxPolicyNum + */ + public int getMaxPolicyNum() { + return maxPolicyNum; + } - @Override - public int hashCode() { - return Objects.hashCode(from, to); - } + @Override + public int hashCode() { + return Objects.hashCode(from, to); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Direction that = Direction.class.cast(obj); - return Objects.equal(this.from, that.from) - && Objects.equal(this.to, that.to); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Direction that = Direction.class.cast(obj); + return Objects.equal(this.from, that.from) + && Objects.equal(this.to, that.to); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("from", from) - .add("to", to).add("prefix", prefix).add("policies", policies) - .add("maxPolicyNum", maxPolicyNum) - .add("acceptable", acceptable).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("from", from) + .add("to", to).add("prefix", prefix).add("policies", policies) + .add("maxPolicyNum", maxPolicyNum) + .add("acceptable", acceptable).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Disk.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Disk.java index dae088f095..cae3da8ba3 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Disk.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Disk.java @@ -29,57 +29,57 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement public class Disk { - @XmlElement(name = "diskSize") - private String size; + @XmlElement(name = "diskSize") + private String size; - @XmlElement(name = "diskUsage") - private String usage; + @XmlElement(name = "diskUsage") + private String usage; - @XmlElement(name = "diskType") - private String type; + @XmlElement(name = "diskType") + private String type; - public String getSize() { - return size; - } + public String getSize() { + return size; + } - public String getUsage() { - return usage; - } + public String getUsage() { + return usage; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof Disk)) - return false; + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof Disk)) + return false; - Disk disk = (Disk) o; + Disk disk = (Disk) o; - if (size != null ? !size.equals(disk.size) : disk.size != null) - return false; - if (type != null ? !type.equals(disk.type) : disk.type != null) - return false; - if (usage != null ? !usage.equals(disk.usage) : disk.usage != null) - return false; + if (size != null ? !size.equals(disk.size) : disk.size != null) + return false; + if (type != null ? !type.equals(disk.type) : disk.type != null) + return false; + if (usage != null ? !usage.equals(disk.usage) : disk.usage != null) + return false; - return true; - } + return true; + } - @Override - public int hashCode() { - int result = size != null ? size.hashCode() : 0; - result = 31 * result + (usage != null ? usage.hashCode() : 0); - result = 31 * result + (type != null ? type.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = size != null ? size.hashCode() : 0; + result = 31 * result + (usage != null ? usage.hashCode() : 0); + result = 31 * result + (type != null ? type.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Disk{" + "size='" + size + '\'' + ", usage='" + usage + '\'' - + ", type='" + type + '\'' + '}'; - } + @Override + public String toString() { + return "Disk{" + "size='" + size + '\'' + ", usage='" + usage + '\'' + + ", type='" + type + '\'' + '}'; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/DiskImage.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/DiskImage.java index 5e2d3e1daf..6540f357ff 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/DiskImage.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/DiskImage.java @@ -37,164 +37,164 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "diskimage") public class DiskImage { - @XmlElement(name = "diskimageId") - private String id; + @XmlElement(name = "diskimageId") + private String id; - @XmlElement(name = "diskimageName") - private String name; + @XmlElement(name = "diskimageName") + private String name; - private int size; + private int size; - private String osName; + private String osName; - private String osType; + private String osType; - private String creatorName; + private String creatorName; - private String registrant; + private String registrant; - private String licenseInfo; + private String licenseInfo; - private String description; + private String description; - @XmlElementWrapper(name = "softwares") - @XmlElement(name = "software") - private Set software = new LinkedHashSet(); + @XmlElementWrapper(name = "softwares") + @XmlElement(name = "software") + private Set software = new LinkedHashSet(); - public String getId() { - return id; - } + public String getId() { + return id; + } - public int getSize() { - return size; - } + public int getSize() { + return size; + } - public String getOsName() { - return osName; - } + public String getOsName() { + return osName; + } - public String getOsType() { - return osType; - } + public String getOsType() { + return osType; + } - public String getCreatorName() { - return creatorName; - } + public String getCreatorName() { + return creatorName; + } - public String getRegistrant() { - return registrant; - } + public String getRegistrant() { + return registrant; + } - public String getLicenseInfo() { - return licenseInfo; - } + public String getLicenseInfo() { + return licenseInfo; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public Set getSoftware() { - return software == null ? ImmutableSet. of() : ImmutableSet - .copyOf(software); - } + public Set getSoftware() { + return software == null ? ImmutableSet. of() : ImmutableSet + .copyOf(software); + } - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public static class Builder { - private String id; - private String name; - private int size; - private String osName; - private String osType; - private String creatorName; - private String registrant; - private String licenseInfo; - private String description; - private Set software; + public static class Builder { + private String id; + private String name; + private int size; + private String osName; + private String osType; + private String creatorName; + private String registrant; + private String licenseInfo; + private String description; + private Set software; - public Builder id(String id) { - this.id = id; - return this; - } + public Builder id(String id) { + this.id = id; + return this; + } - public Builder name(String name) { - this.name = name; - return this; - } + public Builder name(String name) { + this.name = name; + return this; + } - public Builder osName(String osName) { - this.osName = osName; - return this; - } + public Builder osName(String osName) { + this.osName = osName; + return this; + } - public Builder osType(String osType) { - this.osType = osType; - return this; - } + public Builder osType(String osType) { + this.osType = osType; + return this; + } - public Builder creatorName(String creatorName) { - this.creatorName = creatorName; - return this; - } + public Builder creatorName(String creatorName) { + this.creatorName = creatorName; + return this; + } - public Builder registrant(String registrant) { - this.registrant = registrant; - return this; - } + public Builder registrant(String registrant) { + this.registrant = registrant; + return this; + } - public Builder description(String description) { - this.description = description; - return this; - } + public Builder description(String description) { + this.description = description; + return this; + } - public DiskImage build() { - DiskImage image = new DiskImage(); + public DiskImage build() { + DiskImage image = new DiskImage(); - image.id = id; - image.name = name; - image.size = size; - image.osName = osName; - image.osType = osType; - image.creatorName = creatorName; - image.registrant = registrant; - image.licenseInfo = licenseInfo; - image.description = description; - image.software = software; + image.id = id; + image.name = name; + image.size = size; + image.osName = osName; + image.osType = osType; + image.creatorName = creatorName; + image.registrant = registrant; + image.licenseInfo = licenseInfo; + image.description = description; + image.software = software; - return image; - } - } + return image; + } + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - DiskImage that = DiskImage.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DiskImage that = DiskImage.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("osName", osName).add("osType", osType) - .add("size", size).add("creatorName", creatorName) - .add("description", description) - .add("licenseInfo", licenseInfo).add("registrant", registrant) - .add("software", software).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("osName", osName).add("osType", osType) + .add("size", size).add("creatorName", creatorName) + .add("description", description) + .add("licenseInfo", licenseInfo).add("registrant", registrant) + .add("software", software).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ErrorStatistics.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ErrorStatistics.java index 28cb1e764a..d5764097af 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ErrorStatistics.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ErrorStatistics.java @@ -32,22 +32,22 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "errorstatistics") public class ErrorStatistics { - private Period period; - private Set groups = new LinkedHashSet(); + private Period period; + private Set groups = new LinkedHashSet(); - /** - * @return the period - */ - public Period getPeriod() { - return period; - } + /** + * @return the period + */ + public Period getPeriod() { + return period; + } - /** - * @return the groups - */ - public Set getGroups() { - return groups == null ? ImmutableSet. of() : ImmutableSet - .copyOf(groups); - } + /** + * @return the groups + */ + public Set getGroups() { + return groups == null ? ImmutableSet. of() : ImmutableSet + .copyOf(groups); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/EventLog.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/EventLog.java index bda7e2303e..f9eef692e5 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/EventLog.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/EventLog.java @@ -29,71 +29,71 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "errorlog") public class EventLog { - private String title; - private String message; - private String startDate; - private String expiry; - private String entryDate; + private String title; + private String message; + private String startDate; + private String expiry; + private String entryDate; - /** - * @return the title - */ - public String getTitle() { - return title; - } + /** + * @return the title + */ + public String getTitle() { + return title; + } - /** - * @return the message - */ - public String getMessage() { - return message; - } + /** + * @return the message + */ + public String getMessage() { + return message; + } - /** - * @return the startDate - */ - public String getStartDate() { - return startDate; - } + /** + * @return the startDate + */ + public String getStartDate() { + return startDate; + } - /** - * @return the expiry - */ - public String getExpiry() { - return expiry; - } + /** + * @return the expiry + */ + public String getExpiry() { + return expiry; + } - /** - * @return the entryDate - */ - public String getEntryDate() { - return entryDate; - } + /** + * @return the entryDate + */ + public String getEntryDate() { + return entryDate; + } - @Override - public int hashCode() { - return Objects.hashCode(entryDate, message, title); - } + @Override + public int hashCode() { + return Objects.hashCode(entryDate, message, title); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - EventLog that = EventLog.class.cast(obj); - return Objects.equal(this.entryDate, that.entryDate) - && Objects.equal(this.message, that.message) - && Objects.equal(this.title, that.title); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + EventLog that = EventLog.class.cast(obj); + return Objects.equal(this.entryDate, that.entryDate) + && Objects.equal(this.message, that.message) + && Objects.equal(this.title, that.title); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("entryDate", entryDate).add("title", title) - .add("message", message).add("startDate", startDate) - .add("expiry", expiry).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("entryDate", entryDate).add("title", title) + .add("message", message).add("startDate", startDate) + .add("expiry", expiry).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Firewall.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Firewall.java index f466c054b1..26f1c7efd0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Firewall.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Firewall.java @@ -32,102 +32,102 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "fw") public class Firewall { - private NAT nat; - private Set directions = new LinkedHashSet(); - private String log; - private String status; - private String category; - private String latestVersion; - private String comment; - private boolean firmUpdateExist; - private boolean configUpdateExist; - private String backout; - private String updateDate; - private String currentVersion; + private NAT nat; + private Set directions = new LinkedHashSet(); + private String log; + private String status; + private String category; + private String latestVersion; + private String comment; + private boolean firmUpdateExist; + private boolean configUpdateExist; + private String backout; + private String updateDate; + private String currentVersion; - /** - * @return the nat - */ - public NAT getNat() { - return nat; - } + /** + * @return the nat + */ + public NAT getNat() { + return nat; + } - /** - * @return the directions - */ - public Set getDirections() { - return directions == null ? ImmutableSet. of() - : ImmutableSet.copyOf(directions); - } + /** + * @return the directions + */ + public Set getDirections() { + return directions == null ? ImmutableSet. of() + : ImmutableSet.copyOf(directions); + } - /** - * @return the log - */ - public String getLog() { - return log; - } + /** + * @return the log + */ + public String getLog() { + return log; + } - /** - * @return the status - */ - public String getStatus() { - return status; - } + /** + * @return the status + */ + public String getStatus() { + return status; + } - /** - * @return the category - */ - public String getCategory() { - return category; - } + /** + * @return the category + */ + public String getCategory() { + return category; + } - /** - * @return the latestVersion - */ - public String getLatestVersion() { - return latestVersion; - } + /** + * @return the latestVersion + */ + public String getLatestVersion() { + return latestVersion; + } - /** - * @return the comment - */ - public String getComment() { - return comment; - } + /** + * @return the comment + */ + public String getComment() { + return comment; + } - /** - * @return the firmUpdateExist - */ - public boolean getFirmUpdateExist() { - return firmUpdateExist; - } + /** + * @return the firmUpdateExist + */ + public boolean getFirmUpdateExist() { + return firmUpdateExist; + } - /** - * @return the configUpdateExist - */ - public boolean getConfigUpdateExist() { - return configUpdateExist; - } + /** + * @return the configUpdateExist + */ + public boolean getConfigUpdateExist() { + return configUpdateExist; + } - /** - * @return the backout - */ - public String getBackout() { - return backout; - } + /** + * @return the backout + */ + public String getBackout() { + return backout; + } - /** - * @return the updateDate - */ - public String getUpdateDate() { - return updateDate; - } + /** + * @return the updateDate + */ + public String getUpdateDate() { + return updateDate; + } - /** - * @return the currentVersion - */ - public String getCurrentVersion() { - return currentVersion; - } + /** + * @return the currentVersion + */ + public String getCurrentVersion() { + return currentVersion; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Group.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Group.java index 40c36a4bbe..38392855ac 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Group.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Group.java @@ -32,195 +32,195 @@ import com.google.common.collect.ImmutableSet; * @author Dies Koper */ public class Group { - private int id; + private int id; - private String protocol; + private String protocol; - private int port1; + private int port1; - private int port2; + private int port2; - private String balanceType; + private String balanceType; - private String uniqueType; + private String uniqueType; - private String monitorType; + private String monitorType; - private int maxConnection; + private int maxConnection; - private int uniqueRetention; + private int uniqueRetention; - private int interval; + private int interval; - private int timeout; + private int timeout; - private int retryCount; + private int retryCount; - private int certNum; + private int certNum; - private Set causes; + private Set causes; - private RecoveryAction recoveryAction; + private RecoveryAction recoveryAction; - private Set targets = new LinkedHashSet(); + private Set targets = new LinkedHashSet(); - private String validity; + private String validity; - enum RecoveryAction { - @XmlEnumValue("switch-back") - SWITCH_BACK, @XmlEnumValue("maintenance") - MAINTENANCE - } + enum RecoveryAction { + @XmlEnumValue("switch-back") + SWITCH_BACK, @XmlEnumValue("maintenance") + MAINTENANCE + } - /** - * @return the id - */ - public int getId() { - return id; - } + /** + * @return the id + */ + public int getId() { + return id; + } - /** - * @return the protocol - */ - public String getProtocol() { - return protocol; - } + /** + * @return the protocol + */ + public String getProtocol() { + return protocol; + } - /** - * @return the port1 - */ - public int getPort1() { - return port1; - } + /** + * @return the port1 + */ + public int getPort1() { + return port1; + } - /** - * @return the port2 - */ - public int getPort2() { - return port2; - } + /** + * @return the port2 + */ + public int getPort2() { + return port2; + } - /** - * @return the balanceType - */ - public String getBalanceType() { - return balanceType; - } + /** + * @return the balanceType + */ + public String getBalanceType() { + return balanceType; + } - /** - * @return the uniqueType - */ - public String getUniqueType() { - return uniqueType; - } + /** + * @return the uniqueType + */ + public String getUniqueType() { + return uniqueType; + } - /** - * @return the monitorType - */ - public String getMonitorType() { - return monitorType; - } + /** + * @return the monitorType + */ + public String getMonitorType() { + return monitorType; + } - /** - * @return the maxConnection - */ - public int getMaxConnection() { - return maxConnection; - } + /** + * @return the maxConnection + */ + public int getMaxConnection() { + return maxConnection; + } - /** - * @return the uniqueRetention - */ - public int getUniqueRetention() { - return uniqueRetention; - } + /** + * @return the uniqueRetention + */ + public int getUniqueRetention() { + return uniqueRetention; + } - /** - * @return the interval - */ - public int getInterval() { - return interval; - } + /** + * @return the interval + */ + public int getInterval() { + return interval; + } - /** - * @return the timeout - */ - public int getTimeout() { - return timeout; - } + /** + * @return the timeout + */ + public int getTimeout() { + return timeout; + } - /** - * @return the retryCount - */ - public int getRetryCount() { - return retryCount; - } + /** + * @return the retryCount + */ + public int getRetryCount() { + return retryCount; + } - /** - * @return the certNum - */ - public int getCertNum() { - return certNum; - } + /** + * @return the certNum + */ + public int getCertNum() { + return certNum; + } - /** - * @return the causes - */ - public Set getCauses() { - return causes == null ? ImmutableSet. of() : ImmutableSet - .copyOf(causes); - } + /** + * @return the causes + */ + public Set getCauses() { + return causes == null ? ImmutableSet. of() : ImmutableSet + .copyOf(causes); + } - /** - * @return the recoveryAction - */ - public RecoveryAction getRecoveryAction() { - return recoveryAction; - } + /** + * @return the recoveryAction + */ + public RecoveryAction getRecoveryAction() { + return recoveryAction; + } - /** - * @return the targets - */ - public Set getTargets() { - return targets == null ? ImmutableSet. of() : ImmutableSet - .copyOf(targets); - } + /** + * @return the targets + */ + public Set getTargets() { + return targets == null ? ImmutableSet. of() : ImmutableSet + .copyOf(targets); + } - /** - * @return the validity - */ - public String getValidity() { - return validity; - } + /** + * @return the validity + */ + public String getValidity() { + return validity; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Group that = Group.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Group that = Group.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("protocol", protocol).add("port1", port1) - .add("port2", port2).add("balanceType", balanceType) - .add("uniqueType", uniqueType).add("monitorType", monitorType) - .add("maxConnection", maxConnection) - .add("uniqueRetention", uniqueRetention) - .add("interval", interval).add("timeout", timeout) - .add("retryCount", retryCount).add("certNum", certNum) - .add("causes", causes).add("recoveryAction", recoveryAction) - .add("targets", targets).add("validity", validity).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("protocol", protocol).add("port1", port1) + .add("port2", port2).add("balanceType", balanceType) + .add("uniqueType", uniqueType).add("monitorType", monitorType) + .add("maxConnection", maxConnection) + .add("uniqueRetention", uniqueRetention) + .add("interval", interval).add("timeout", timeout) + .add("retryCount", retryCount).add("certNum", certNum) + .add("causes", causes).add("recoveryAction", recoveryAction) + .add("targets", targets).add("validity", validity).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Image.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Image.java index ed8fbacd31..2d3be5e4a8 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Image.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Image.java @@ -34,81 +34,81 @@ import com.google.common.collect.ImmutableSet; * @author Dies Koper */ public class Image { - private String id; + private String id; - private String serverCategory; + private String serverCategory; - private String serverApplication; + private String serverApplication; - private String cpuBit; + private String cpuBit; - private float sysvolSize; + private float sysvolSize; - private int numOfMaxDisk; + private int numOfMaxDisk; - private int numOfMaxNic; + private int numOfMaxNic; - @XmlElementWrapper(name = "softwares") - @XmlElement(name = "software") - private Set software = new LinkedHashSet(); + @XmlElementWrapper(name = "softwares") + @XmlElement(name = "software") + private Set software = new LinkedHashSet(); - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getServerCategory() { - return serverCategory; - } + public String getServerCategory() { + return serverCategory; + } - public String getServerApplication() { - return serverApplication; - } + public String getServerApplication() { + return serverApplication; + } - public String getCpuBit() { - return cpuBit; - } + public String getCpuBit() { + return cpuBit; + } - public float getSysvolSize() { - return sysvolSize; - } + public float getSysvolSize() { + return sysvolSize; + } - public int getNumOfMaxDisk() { - return numOfMaxDisk; - } + public int getNumOfMaxDisk() { + return numOfMaxDisk; + } - public int getNumOfMaxNic() { - return numOfMaxNic; - } + public int getNumOfMaxNic() { + return numOfMaxNic; + } - public Set getSoftware() { - return software == null ? ImmutableSet. of() : ImmutableSet - .copyOf(software); - } + public Set getSoftware() { + return software == null ? ImmutableSet. of() : ImmutableSet + .copyOf(software); + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Image that = Image.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Image that = Image.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("serverCategory", serverCategory) - .add("serverApplication", serverApplication) - .add("cpuBit", cpuBit).add("sysvolSize", sysvolSize) - .add("numOfMaxDisk", numOfMaxDisk) - .add("numOfMaxNic", numOfMaxNic).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("serverCategory", serverCategory) + .add("serverApplication", serverApplication) + .add("cpuBit", cpuBit).add("sysvolSize", sysvolSize) + .add("numOfMaxDisk", numOfMaxDisk) + .add("numOfMaxNic", numOfMaxNic).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Information.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Information.java index a8a822f859..21f292c4e2 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Information.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Information.java @@ -26,80 +26,80 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Information { - private int seqno; - private String title; - private String message; - private String startDate; - private String expiry; - private String entryDate; + private int seqno; + private String title; + private String message; + private String startDate; + private String expiry; + private String entryDate; - /** - * @return the seqno - */ - public int getSeqno() { - return seqno; - } + /** + * @return the seqno + */ + public int getSeqno() { + return seqno; + } - /** - * @return the title - */ - public String getTitle() { - return title; - } + /** + * @return the title + */ + public String getTitle() { + return title; + } - /** - * @return the message - */ - public String getMessage() { - return message; - } + /** + * @return the message + */ + public String getMessage() { + return message; + } - /** - * @return the startDate - */ - public String getStartDate() { - return startDate; - } + /** + * @return the startDate + */ + public String getStartDate() { + return startDate; + } - /** - * @return the expiry - */ - public String getExpiry() { - return expiry; - } + /** + * @return the expiry + */ + public String getExpiry() { + return expiry; + } - /** - * @return the entryDate - */ - public String getEntryDate() { - return entryDate; - } + /** + * @return the entryDate + */ + public String getEntryDate() { + return entryDate; + } - @Override - public int hashCode() { - return Objects.hashCode(seqno, entryDate, message, title); - } + @Override + public int hashCode() { + return Objects.hashCode(seqno, entryDate, message, title); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Information that = Information.class.cast(obj); - return Objects.equal(this.seqno, that.seqno) - && Objects.equal(this.entryDate, that.entryDate) - && Objects.equal(this.message, that.message) - && Objects.equal(this.title, that.title); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Information that = Information.class.cast(obj); + return Objects.equal(this.seqno, that.seqno) + && Objects.equal(this.entryDate, that.entryDate) + && Objects.equal(this.message, that.message) + && Objects.equal(this.title, that.title); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("seqno", seqno).add("entryDate", entryDate) - .add("title", title).add("message", message) - .add("startDate", startDate).add("expiry", expiry).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("seqno", seqno).add("entryDate", entryDate) + .add("title", title).add("message", message) + .add("startDate", startDate).add("expiry", expiry).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/IntermediateCACert.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/IntermediateCACert.java index 7acc3871a0..879171f8f8 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/IntermediateCACert.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/IntermediateCACert.java @@ -29,92 +29,92 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "ccacert") public class IntermediateCACert implements Comparable { - private int ccacertNum; + private int ccacertNum; - private String description; + private String description; - private String subject; + private String subject; - private String issuer; + private String issuer; - private String validity; + private String validity; - private String detail; + private String detail; - /** - * @return the ccacertNum - */ - public int getCcacertNum() { - return ccacertNum; - } + /** + * @return the ccacertNum + */ + public int getCcacertNum() { + return ccacertNum; + } - /** - * @return the description - */ - public String getDescription() { - return description; - } + /** + * @return the description + */ + public String getDescription() { + return description; + } - /** - * @return the subject - */ - public String getSubject() { - return subject; - } + /** + * @return the subject + */ + public String getSubject() { + return subject; + } - /** - * @return the issuer - */ - public String getIssuer() { - return issuer; - } + /** + * @return the issuer + */ + public String getIssuer() { + return issuer; + } - /** - * @return the validity - */ - public String getValidity() { - return validity; - } + /** + * @return the validity + */ + public String getValidity() { + return validity; + } - /** - * @return the detail - */ - public String getDetail() { - return detail; - } + /** + * @return the detail + */ + public String getDetail() { + return detail; + } - @Override - public int hashCode() { - return Objects.hashCode(ccacertNum, issuer, subject, validity); - } + @Override + public int hashCode() { + return Objects.hashCode(ccacertNum, issuer, subject, validity); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IntermediateCACert that = IntermediateCACert.class.cast(obj); - return Objects.equal(this.ccacertNum, that.ccacertNum) - && Objects.equal(this.issuer, that.issuer) - && Objects.equal(this.subject, that.subject) - && Objects.equal(this.validity, that.validity); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IntermediateCACert that = IntermediateCACert.class.cast(obj); + return Objects.equal(this.ccacertNum, that.ccacertNum) + && Objects.equal(this.issuer, that.issuer) + && Objects.equal(this.subject, that.subject) + && Objects.equal(this.validity, that.validity); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("ccacertNum", ccacertNum).add("issuer", issuer) - .add("subject", subject).add("validity", validity) - .add("description", description).add("detail", detail) - .toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("ccacertNum", ccacertNum).add("issuer", issuer) + .add("subject", subject).add("validity", validity) + .add("description", description).add("detail", detail) + .toString(); + } - @Override - public int compareTo(IntermediateCACert o) { - return ccacertNum - o.ccacertNum; - } + @Override + public int compareTo(IntermediateCACert o) { + return ccacertNum - o.ccacertNum; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/LoadStatistics.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/LoadStatistics.java index 654e4fca5c..9e166af3ba 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/LoadStatistics.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/LoadStatistics.java @@ -33,36 +33,36 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "loadstatistics") public class LoadStatistics { - private Set groups = new LinkedHashSet(); + private Set groups = new LinkedHashSet(); - /** - * @return the groups - */ - public Set getGroups() { - return groups == null ? ImmutableSet. of() : ImmutableSet - .copyOf(groups); - } + /** + * @return the groups + */ + public Set getGroups() { + return groups == null ? ImmutableSet. of() : ImmutableSet + .copyOf(groups); + } - @Override - public int hashCode() { - return Objects.hashCode(groups); - } + @Override + public int hashCode() { + return Objects.hashCode(groups); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LoadStatistics that = LoadStatistics.class.cast(obj); - return Objects.equal(this.groups, that.groups); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LoadStatistics that = LoadStatistics.class.cast(obj); + return Objects.equal(this.groups, that.groups); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("groups", groups).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("groups", groups).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Memory.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Memory.java index af3b0767b6..d4bd9df3aa 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Memory.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Memory.java @@ -28,39 +28,39 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Memory implements Comparable { - @XmlElement(name = "memorySize") - private double size; + @XmlElement(name = "memorySize") + private double size; - public double getSize() { - return size; - } + public double getSize() { + return size; + } - @Override - public int hashCode() { - return Objects.hashCode(size); - } + @Override + public int hashCode() { + return Objects.hashCode(size); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Memory that = Memory.class.cast(obj); - return Objects.equal(this.size, that.size); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Memory that = Memory.class.cast(obj); + return Objects.equal(this.size, that.size); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("size", size) - .toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("size", size) + .toString(); + } - @Override - public int compareTo(Memory o) { - return Double.compare(size, o.size); - } + @Override + public int compareTo(Memory o) { + return Double.compare(size, o.size); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/NAT.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/NAT.java index a753ed8395..d0fcbb2ddd 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/NAT.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/NAT.java @@ -30,36 +30,36 @@ import com.google.common.collect.ImmutableSet; * @author Dies Koper */ public class NAT { - private Set rules = new LinkedHashSet(); + private Set rules = new LinkedHashSet(); - /** - * @return the rules - */ - public Set getRules() { - return rules == null ? ImmutableSet. of() : ImmutableSet - .copyOf(rules); - } + /** + * @return the rules + */ + public Set getRules() { + return rules == null ? ImmutableSet. of() : ImmutableSet + .copyOf(rules); + } - @Override - public int hashCode() { - return Objects.hashCode(rules); - } + @Override + public int hashCode() { + return Objects.hashCode(rules); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - NAT that = NAT.class.cast(obj); - return Objects.equal(this.rules, that.rules); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NAT that = NAT.class.cast(obj); + return Objects.equal(this.rules, that.rules); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("rules", rules).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("rules", rules).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PerformanceInfo.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PerformanceInfo.java index e9d9856182..37a8b780ee 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PerformanceInfo.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PerformanceInfo.java @@ -29,121 +29,121 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "performanceinfo") public class PerformanceInfo implements Comparable { - private long recordTime; - private double cpuUtilization; - private long diskReadRequestCount; - private long diskWriteRequestCount; - private long diskReadSector; - private long diskWriteSector; - private long nicInputByte; - private long nicOutputByte; - private long nicInputPacket; - private long nicOutputPacket; + private long recordTime; + private double cpuUtilization; + private long diskReadRequestCount; + private long diskWriteRequestCount; + private long diskReadSector; + private long diskWriteSector; + private long nicInputByte; + private long nicOutputByte; + private long nicInputPacket; + private long nicOutputPacket; - /** - * @return the recordTime - */ - public long getRecordTime() { - return recordTime; - } + /** + * @return the recordTime + */ + public long getRecordTime() { + return recordTime; + } - /** - * @return the cpuUtilization - */ - public double getCpuUtilization() { - return cpuUtilization; - } + /** + * @return the cpuUtilization + */ + public double getCpuUtilization() { + return cpuUtilization; + } - /** - * @return the diskReadRequestCount - */ - public long getDiskReadRequestCount() { - return diskReadRequestCount; - } + /** + * @return the diskReadRequestCount + */ + public long getDiskReadRequestCount() { + return diskReadRequestCount; + } - /** - * @return the diskWriteRequestCount - */ - public long getDiskWriteRequestCount() { - return diskWriteRequestCount; - } + /** + * @return the diskWriteRequestCount + */ + public long getDiskWriteRequestCount() { + return diskWriteRequestCount; + } - /** - * @return the diskReadSector - */ - public long getDiskReadSector() { - return diskReadSector; - } + /** + * @return the diskReadSector + */ + public long getDiskReadSector() { + return diskReadSector; + } - /** - * @return the diskWriteSector - */ - public long getDiskWriteSector() { - return diskWriteSector; - } + /** + * @return the diskWriteSector + */ + public long getDiskWriteSector() { + return diskWriteSector; + } - /** - * @return the nicInputByte - */ - public long getNicInputByte() { - return nicInputByte; - } + /** + * @return the nicInputByte + */ + public long getNicInputByte() { + return nicInputByte; + } - /** - * @return the nicOutputByte - */ - public long getNicOutputByte() { - return nicOutputByte; - } + /** + * @return the nicOutputByte + */ + public long getNicOutputByte() { + return nicOutputByte; + } - /** - * @return the nicInputPacket - */ - public long getNicInputPacket() { - return nicInputPacket; - } + /** + * @return the nicInputPacket + */ + public long getNicInputPacket() { + return nicInputPacket; + } - /** - * @return the nicOutputPacket - */ - public long getNicOutputPacket() { - return nicOutputPacket; - } + /** + * @return the nicOutputPacket + */ + public long getNicOutputPacket() { + return nicOutputPacket; + } - @Override - public int hashCode() { - return Objects.hashCode(recordTime); - } + @Override + public int hashCode() { + return Objects.hashCode(recordTime); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - PerformanceInfo that = PerformanceInfo.class.cast(obj); - return Objects.equal(this.recordTime, that.recordTime); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PerformanceInfo that = PerformanceInfo.class.cast(obj); + return Objects.equal(this.recordTime, that.recordTime); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("recordTime", recordTime) - .add("cpuUtilization", cpuUtilization) - .add("diskReadRequestCount", diskReadRequestCount) - .add("diskWriteRequestCount", diskWriteRequestCount) - .add("diskReadSector", diskReadSector) - .add("diskWriteSector", diskWriteSector) - .add("nicInputByte", nicInputByte) - .add("nicOutputByte", nicOutputByte) - .add("nicInputPacket", nicInputPacket) - .add("nicOutputPacket", nicOutputPacket).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("recordTime", recordTime) + .add("cpuUtilization", cpuUtilization) + .add("diskReadRequestCount", diskReadRequestCount) + .add("diskWriteRequestCount", diskWriteRequestCount) + .add("diskReadSector", diskReadSector) + .add("diskWriteSector", diskWriteSector) + .add("nicInputByte", nicInputByte) + .add("nicOutputByte", nicOutputByte) + .add("nicInputPacket", nicInputPacket) + .add("nicOutputPacket", nicOutputPacket).toString(); + } - @Override - public int compareTo(PerformanceInfo o) { - return (int) (recordTime - o.recordTime); - } + @Override + public int compareTo(PerformanceInfo o) { + return (int) (recordTime - o.recordTime); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Period.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Period.java index b75173fe6c..718af01285 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Period.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Period.java @@ -25,37 +25,37 @@ package org.jclouds.fujitsu.fgcp.domain; * @author Dies Koper */ public class Period { - private String current; - private String before; - private String today; - private String yesterday; + private String current; + private String before; + private String today; + private String yesterday; - /** - * @return the current - */ - public String getCurrent() { - return current; - } + /** + * @return the current + */ + public String getCurrent() { + return current; + } - /** - * @return the before - */ - public String getBefore() { - return before; - } + /** + * @return the before + */ + public String getBefore() { + return before; + } - /** - * @return the today - */ - public String getToday() { - return today; - } + /** + * @return the today + */ + public String getToday() { + return today; + } - /** - * @return the yesterday - */ - public String getYesterday() { - return yesterday; - } + /** + * @return the yesterday + */ + public String getYesterday() { + return yesterday; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Policy.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Policy.java index e030c12793..4c7c1675dc 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Policy.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Policy.java @@ -28,168 +28,168 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Policy implements Comparable { - private int id; + private int id; - private String src; + private String src; - private PolicyType srcType; + private PolicyType srcType; - private String srcPort; + private String srcPort; - private Service dstService; + private Service dstService; - private String dst; + private String dst; - private PolicyType dstType; + private PolicyType dstType; - private String dstPort; + private String dstPort; - private Protocol protocol; + private Protocol protocol; - private Action action; + private Action action; - private Log log; + private Log log; - enum Service { - NONE, WSUS, DNS, NTP, @XmlEnumValue("yum") - YUM, KMS, @XmlEnumValue("Symantec") - SYMANTEC, RHUI - } + enum Service { + NONE, WSUS, DNS, NTP, @XmlEnumValue("yum") + YUM, KMS, @XmlEnumValue("Symantec") + SYMANTEC, RHUI + } - enum PolicyType {IP, FQDN, FQDNF} + enum PolicyType {IP, FQDN, FQDNF} - enum Protocol { - @XmlEnumValue("tcp") - TCP, @XmlEnumValue("udp") - UDP, @XmlEnumValue("tcp-udp") - TCP_UDP, @XmlEnumValue("icmp") - ICMP - } + enum Protocol { + @XmlEnumValue("tcp") + TCP, @XmlEnumValue("udp") + UDP, @XmlEnumValue("tcp-udp") + TCP_UDP, @XmlEnumValue("icmp") + ICMP + } - enum Action { - @XmlEnumValue("Accept") - ACCEPT, @XmlEnumValue("Deny") - DENY - } + enum Action { + @XmlEnumValue("Accept") + ACCEPT, @XmlEnumValue("Deny") + DENY + } - enum Log { - @XmlEnumValue("On") - ON, @XmlEnumValue("Off") - OFF - } + enum Log { + @XmlEnumValue("On") + ON, @XmlEnumValue("Off") + OFF + } - /** - * @return the id - */ - public int getId() { - return id; - } + /** + * @return the id + */ + public int getId() { + return id; + } - /** - * @return the src - */ - public String getSrc() { - return src; - } + /** + * @return the src + */ + public String getSrc() { + return src; + } - /** - * @return the srcType - */ - public PolicyType getSrcType() { - return srcType; - } + /** + * @return the srcType + */ + public PolicyType getSrcType() { + return srcType; + } - /** - * @return the srcPort - */ - public String getSrcPort() { - return srcPort; - } + /** + * @return the srcPort + */ + public String getSrcPort() { + return srcPort; + } - /** - * @return the dstService - */ - public Service getDstService() { - return dstService; - } + /** + * @return the dstService + */ + public Service getDstService() { + return dstService; + } - /** - * @return the dst - */ - public String getDst() { - return dst; - } + /** + * @return the dst + */ + public String getDst() { + return dst; + } - /** - * @return the dstType - */ - public PolicyType getDstType() { - return dstType; - } + /** + * @return the dstType + */ + public PolicyType getDstType() { + return dstType; + } - /** - * @return the dstPort - */ - public String getDstPort() { - return dstPort; - } + /** + * @return the dstPort + */ + public String getDstPort() { + return dstPort; + } - /** - * @return the protocol - */ - public Protocol getProtocol() { - return protocol; - } + /** + * @return the protocol + */ + public Protocol getProtocol() { + return protocol; + } - /** - * @return the action - */ - public Action getAction() { - return action; - } + /** + * @return the action + */ + public Action getAction() { + return action; + } - /** - * @return the log - */ - public Log getLog() { - return log; - } + /** + * @return the log + */ + public Log getLog() { + return log; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Policy that = Policy.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Policy that = Policy.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("id", id) - .add("src", src) - .add("srcType", srcType) - .add("srcPort", srcPort) - .add("dstService", dstService) - .add("dst", dst) - .add("dstType", dstType) - .add("dstPort", dstPort) - .add("protocol", protocol) - .add("action", action) - .add("log", log).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("id", id) + .add("src", src) + .add("srcType", srcType) + .add("srcPort", srcPort) + .add("dstService", dstService) + .add("dst", dst) + .add("dstType", dstType) + .add("dstPort", dstPort) + .add("protocol", protocol) + .add("action", action) + .add("log", log).toString(); + } - @Override - public int compareTo(Policy o) { - return id - o.id; - } + @Override + public int compareTo(Policy o) { + return id - o.id; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Product.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Product.java index 447f81ea04..c1765893c6 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Product.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Product.java @@ -28,57 +28,57 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Product { - @XmlElement(name = "productName") - private String name; + @XmlElement(name = "productName") + private String name; - private String unitName; + private String unitName; - private String usedPoints; + private String usedPoints; - /** - * @return the name - */ - public String getName() { - return name; - } + /** + * @return the name + */ + public String getName() { + return name; + } - /** - * @return the unitName - */ - public String getUnitName() { - return unitName; - } + /** + * @return the unitName + */ + public String getUnitName() { + return unitName; + } - /** - * @return the usedPoints - */ - public String getUsedPoints() { - return usedPoints; - } + /** + * @return the usedPoints + */ + public String getUsedPoints() { + return usedPoints; + } - @Override - public int hashCode() { - return Objects.hashCode(name, unitName, usedPoints); - } + @Override + public int hashCode() { + return Objects.hashCode(name, unitName, usedPoints); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Product that = Product.class.cast(obj); - return Objects.equal(this.name, that.name) - && Objects.equal(this.unitName, that.unitName) - && Objects.equal(this.usedPoints, that.usedPoints); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Product that = Product.class.cast(obj); + return Objects.equal(this.name, that.name) + && Objects.equal(this.unitName, that.unitName) + && Objects.equal(this.usedPoints, that.usedPoints); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("name", name) - .add("unitName", unitName).add("usedPoints", usedPoints) - .toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("name", name) + .add("unitName", unitName).add("usedPoints", usedPoints) + .toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIP.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIP.java index 698c462cee..c672815161 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIP.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIP.java @@ -36,59 +36,59 @@ import com.google.common.base.Objects; */ public class PublicIP { - public static enum Version { - IPv4, IPv6, UNRECOGNIZED; + public static enum Version { + IPv4, IPv6, UNRECOGNIZED; - @Override - public String toString() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, - name()); - } + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, + name()); + } - public static Version fromValue(String version) { - try { - return valueOf(CaseFormat.UPPER_CAMEL.to( - CaseFormat.UPPER_UNDERSCORE, - checkNotNull(version, "version"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static Version fromValue(String version) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to( + CaseFormat.UPPER_UNDERSCORE, + checkNotNull(version, "version"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } - } + } - protected String address; - @XmlElement(name = "v4v6Flag") - protected Version version; + protected String address; + @XmlElement(name = "v4v6Flag") + protected Version version; - public String getAddress() { - return address; - } + public String getAddress() { + return address; + } - public Version getVersion() { - return version; - } + public Version getVersion() { + return version; + } - @Override - public int hashCode() { - return Objects.hashCode(address); - } + @Override + public int hashCode() { + return Objects.hashCode(address); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - PublicIP that = PublicIP.class.cast(obj); - return Objects.equal(this.address, that.address); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PublicIP that = PublicIP.class.cast(obj); + return Objects.equal(this.address, that.address); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("address", address).add("version", version).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("address", address).add("version", version).toString(); + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIPStatus.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIPStatus.java index 3b10c95e35..aa93809998 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIPStatus.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/PublicIPStatus.java @@ -18,12 +18,12 @@ */ package org.jclouds.fujitsu.fgcp.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.CaseFormat; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Possible statuses of a public IP address. *

@@ -34,24 +34,24 @@ import static com.google.common.base.Preconditions.checkNotNull; */ @XmlRootElement(name = "publicipStatus") public enum PublicIPStatus { - ATTACHED, ATTACHING, DETACHING, DETACHED, UNRECOGNIZED; + ATTACHED, ATTACHING, DETACHING, DETACHED, UNRECOGNIZED; - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); - } + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } - @Override - public String toString() { - return value(); - } + @Override + public String toString() { + return value(); + } - public static PublicIPStatus fromValue(String status) { - try { - return valueOf(CaseFormat.UPPER_CAMEL - .to(CaseFormat.UPPER_UNDERSCORE, - checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static PublicIPStatus fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL + .to(CaseFormat.UPPER_UNDERSCORE, + checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Rule.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Rule.java index 6cd979822f..3dc45cad99 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Rule.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Rule.java @@ -31,54 +31,54 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Rule { - private String publicIp; - private String privateIp; - private boolean snapt; + private String publicIp; + private String privateIp; + private boolean snapt; - /** - * @return the publicIp - */ - public String getPublicIp() { - return publicIp; - } + /** + * @return the publicIp + */ + public String getPublicIp() { + return publicIp; + } - /** - * @return the privateIp - */ - public String getPrivateIp() { - return privateIp; - } + /** + * @return the privateIp + */ + public String getPrivateIp() { + return privateIp; + } - /** - * @return the snapt - */ - public boolean isSnapt() { - return snapt; - } + /** + * @return the snapt + */ + public boolean isSnapt() { + return snapt; + } - @Override - public int hashCode() { - return Objects.hashCode(privateIp, publicIp, snapt); - } + @Override + public int hashCode() { + return Objects.hashCode(privateIp, publicIp, snapt); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Rule that = Rule.class.cast(obj); - return Objects.equal(this.privateIp, that.privateIp) - && Objects.equal(this.publicIp, that.publicIp) - && Objects.equal(this.snapt, that.snapt); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Rule that = Rule.class.cast(obj); + return Objects.equal(this.privateIp, that.privateIp) + && Objects.equal(this.publicIp, that.publicIp) + && Objects.equal(this.snapt, that.snapt); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("privateIp", privateIp).add("publicIp", publicIp) - .add("snapt", snapt).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("privateIp", privateIp).add("publicIp", publicIp) + .add("snapt", snapt).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/SLB.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/SLB.java index 274c3b8caa..40a06958c1 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/SLB.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/SLB.java @@ -32,169 +32,169 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "slb") public class SLB extends BuiltinServer { - private String ipAddress; + private String ipAddress; - private Set ccacerts = new LinkedHashSet(); + private Set ccacerts = new LinkedHashSet(); - private Set servercerts = new LinkedHashSet(); + private Set servercerts = new LinkedHashSet(); - private Set groups; + private Set groups; - private String srcType; + private String srcType; - private String srcPort; + private String srcPort; - private String status; + private String status; - private ErrorStatistics errorStatistics; + private ErrorStatistics errorStatistics; - private LoadStatistics loadStatistics; + private LoadStatistics loadStatistics; - private String category; + private String category; - private String latestVersion; + private String latestVersion; - private String comment; + private String comment; - private boolean firmUpdateExist; + private boolean firmUpdateExist; - private boolean configUpdateExist; + private boolean configUpdateExist; - private boolean backout; + private boolean backout; - private String updateDate; + private String updateDate; - private String currentVersion; + private String currentVersion; - private String webAccelerator; + private String webAccelerator; - /** - * @return the ipAddress - */ - public String getIpAddress() { - return ipAddress; - } + /** + * @return the ipAddress + */ + public String getIpAddress() { + return ipAddress; + } - /** - * @return the ccacerts - */ - public Set getCcacerts() { - return ccacerts == null ? ImmutableSet. of() - : ImmutableSet.copyOf(ccacerts); - } + /** + * @return the ccacerts + */ + public Set getCcacerts() { + return ccacerts == null ? ImmutableSet. of() + : ImmutableSet.copyOf(ccacerts); + } - /** - * @return the servercerts - */ - public Set getServercerts() { - return servercerts == null ? ImmutableSet. of() - : ImmutableSet.copyOf(servercerts); - } + /** + * @return the servercerts + */ + public Set getServercerts() { + return servercerts == null ? ImmutableSet. of() + : ImmutableSet.copyOf(servercerts); + } - /** - * @return the groups - */ - public Set getGroups() { - return groups == null ? ImmutableSet. of() : ImmutableSet - .copyOf(groups); - } + /** + * @return the groups + */ + public Set getGroups() { + return groups == null ? ImmutableSet. of() : ImmutableSet + .copyOf(groups); + } - /** - * @return the srcType - */ - public String getSrcType() { - return srcType; - } + /** + * @return the srcType + */ + public String getSrcType() { + return srcType; + } - /** - * @return the srcPort - */ - public String getSrcPort() { - return srcPort; - } + /** + * @return the srcPort + */ + public String getSrcPort() { + return srcPort; + } - /** - * @return the status - */ - public String getStatus() { - return status; - } + /** + * @return the status + */ + public String getStatus() { + return status; + } - /** - * @return the errorStatistics - */ - public ErrorStatistics getErrorStatistics() { - return errorStatistics; - } + /** + * @return the errorStatistics + */ + public ErrorStatistics getErrorStatistics() { + return errorStatistics; + } - /** - * @return the loadStatistics - */ - public LoadStatistics getLoadStatistics() { - return loadStatistics; - } + /** + * @return the loadStatistics + */ + public LoadStatistics getLoadStatistics() { + return loadStatistics; + } - /** - * @return the category - */ - public String getCategory() { - return category; - } + /** + * @return the category + */ + public String getCategory() { + return category; + } - /** - * @return the latestVersion - */ - public String getLatestVersion() { - return latestVersion; - } + /** + * @return the latestVersion + */ + public String getLatestVersion() { + return latestVersion; + } - /** - * @return the comment - */ - public String getComment() { - return comment; - } + /** + * @return the comment + */ + public String getComment() { + return comment; + } - /** - * @return the firmUpdateExist - */ - public boolean getFirmUpdateExist() { - return firmUpdateExist; - } + /** + * @return the firmUpdateExist + */ + public boolean getFirmUpdateExist() { + return firmUpdateExist; + } - /** - * @return the configUpdateExist - */ - public boolean getConfigUpdateExist() { - return configUpdateExist; - } + /** + * @return the configUpdateExist + */ + public boolean getConfigUpdateExist() { + return configUpdateExist; + } - /** - * @return the backout - */ - public boolean getBackout() { - return backout; - } + /** + * @return the backout + */ + public boolean getBackout() { + return backout; + } - /** - * @return the updateDate - */ - public String getUpdateDate() { - return updateDate; - } + /** + * @return the updateDate + */ + public String getUpdateDate() { + return updateDate; + } - /** - * @return the currentVersion - */ - public String getCurrentVersion() { - return currentVersion; - } + /** + * @return the currentVersion + */ + public String getCurrentVersion() { + return currentVersion; + } - /** - * @return the webAccelerator - */ - public String getWebAccelerator() { - return webAccelerator; - } + /** + * @return the webAccelerator + */ + public String getWebAccelerator() { + return webAccelerator; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerCert.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerCert.java index d1dfc0698f..3df227fd3b 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerCert.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerCert.java @@ -29,93 +29,93 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "servercert") public class ServerCert implements Comparable { - private int certNum; + private int certNum; - private String subject; + private String subject; - private String issuer; + private String issuer; - private String validity; + private String validity; - private int groupId; + private int groupId; - private String detail; + private String detail; - /** - * @return the certNum - */ - public int getCertNum() { - return certNum; - } + /** + * @return the certNum + */ + public int getCertNum() { + return certNum; + } - /** - * @return the subject - */ - public String getSubject() { - return subject; - } + /** + * @return the subject + */ + public String getSubject() { + return subject; + } - /** - * @return the issuer - */ - public String getIssuer() { - return issuer; - } + /** + * @return the issuer + */ + public String getIssuer() { + return issuer; + } - /** - * @return the validity - */ - public String getValidity() { - return validity; - } + /** + * @return the validity + */ + public String getValidity() { + return validity; + } - /** - * @return the groupId - */ - public int getGroupId() { - return groupId; - } + /** + * @return the groupId + */ + public int getGroupId() { + return groupId; + } - /** - * @return the detail - */ - public String getDetail() { - return detail; - } + /** + * @return the detail + */ + public String getDetail() { + return detail; + } - @Override - public int hashCode() { - return Objects.hashCode(certNum, groupId, issuer, subject, validity); - } + @Override + public int hashCode() { + return Objects.hashCode(certNum, groupId, issuer, subject, validity); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ServerCert that = ServerCert.class.cast(obj); - return Objects.equal(this.certNum, that.certNum) - && Objects.equal(this.groupId, that.groupId) - && Objects.equal(this.issuer, that.issuer) - && Objects.equal(this.subject, that.subject) - && Objects.equal(this.validity, that.validity); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServerCert that = ServerCert.class.cast(obj); + return Objects.equal(this.certNum, that.certNum) + && Objects.equal(this.groupId, that.groupId) + && Objects.equal(this.issuer, that.issuer) + && Objects.equal(this.subject, that.subject) + && Objects.equal(this.validity, that.validity); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("certNum", certNum).add("issuer", issuer) - .add("subject", subject).add("validity", validity) - .add("groupId", groupId).add("detail", detail).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("certNum", certNum).add("issuer", issuer) + .add("subject", subject).add("validity", validity) + .add("groupId", groupId).add("detail", detail).toString(); + } - @Override - public int compareTo(ServerCert o) { - return (certNum - o.certNum) == 0 ? (groupId - o.groupId) - : (certNum - o.certNum); - } + @Override + public int compareTo(ServerCert o) { + return (certNum - o.certNum) == 0 ? (groupId - o.groupId) + : (certNum - o.certNum); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerType.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerType.java index b4a724809b..c5a8b36c13 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerType.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/ServerType.java @@ -35,111 +35,111 @@ import com.google.common.collect.Sets; */ @XmlRootElement(name = "servertype") public class ServerType implements Comparable { - private String id; + private String id; - private String name; + private String name; - private String label; + private String label; - private String comment; + private String comment; - private String productId; + private String productId; - private String productName; + private String productName; - private String price; + private String price; - private String chargeType; + private String chargeType; - private String expectedUsage; + private String expectedUsage; - private CPU cpu; + private CPU cpu; - private Memory memory; + private Memory memory; - @XmlElementWrapper(name = "disks") - @XmlElement(name = "disk") - private Set disks = Sets.newLinkedHashSet(); + @XmlElementWrapper(name = "disks") + @XmlElement(name = "disk") + private Set disks = Sets.newLinkedHashSet(); - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getLabel() { - return label; - } + public String getLabel() { + return label; + } - public String getComment() { - return comment; - } + public String getComment() { + return comment; + } - public String getProductId() { - return productId; - } + public String getProductId() { + return productId; + } - public String getProductName() { - return productName; - } + public String getProductName() { + return productName; + } - public String getPrice() { - return price; - } + public String getPrice() { + return price; + } - public String getChargeType() { - return chargeType; - } + public String getChargeType() { + return chargeType; + } - public String getExpectedUsage() { - return expectedUsage; - } + public String getExpectedUsage() { + return expectedUsage; + } - public CPU getCpu() { - return cpu; - } + public CPU getCpu() { + return cpu; + } - public Memory getMemory() { - return memory; - } + public Memory getMemory() { + return memory; + } - public Set getDisks() { - return disks == null ? ImmutableSet. of() : ImmutableSet - .copyOf(disks); - } + public Set getDisks() { + return disks == null ? ImmutableSet. of() : ImmutableSet + .copyOf(disks); + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ServerType that = ServerType.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServerType that = ServerType.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("label", label).add("comment", comment) - .add("productId", productId).add("productName", productName) - .add("price", price).add("chargeType", chargeType) - .add("expectedUsage", expectedUsage).add("cpu", cpu) - .add("memory", memory).add("disks", disks).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("label", label).add("comment", comment) + .add("productId", productId).add("productName", productName) + .add("price", price).add("chargeType", chargeType) + .add("expectedUsage", expectedUsage).add("cpu", cpu) + .add("memory", memory).add("disks", disks).toString(); + } - @Override - public int compareTo(ServerType o) { - return memory == null ? -1 : memory.compareTo(o.memory); - } + @Override + public int compareTo(ServerType o) { + return memory == null ? -1 : memory.compareTo(o.memory); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Software.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Software.java index cfff2a682e..0bf955a57c 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Software.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Software.java @@ -26,78 +26,78 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Software { - private String name; + private String name; - private String id; + private String id; - private String category; + private String category; - private String version; + private String version; - private String officialVersion; + private String officialVersion; - private String patch; + private String patch; - private String license; + private String license; - private String support; + private String support; - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getCategory() { - return category; - } + public String getCategory() { + return category; + } - public String getVersion() { - return version; - } + public String getVersion() { + return version; + } - public String getOfficialVersion() { - return officialVersion; - } + public String getOfficialVersion() { + return officialVersion; + } - public String getPatch() { - return patch; - } + public String getPatch() { + return patch; + } - public String getLicense() { - return license; - } + public String getLicense() { + return license; + } - public String getSupport() { - return support; - } + public String getSupport() { + return support; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Software that = Software.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Software that = Software.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("category", category) - .add("version", version) - .add("officialVersion", officialVersion) - .add("support", support).add("patch", patch) - .add("license", license).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("category", category) + .add("version", version) + .add("officialVersion", officialVersion) + .add("support", support).add("patch", patch) + .add("license", license).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Target.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Target.java index 44cd0fe727..aeb340f772 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Target.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/Target.java @@ -26,101 +26,101 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class Target { - private String serverId; + private String serverId; - private String serverName; + private String serverName; - private String ipAddress; + private String ipAddress; - private String port1; + private String port1; - private String port2; + private String port2; - private String status; + private String status; - private String now; + private String now; - private String peak; + private String peak; - /** - * @return the serverId - */ - public String getServerId() { - return serverId; - } + /** + * @return the serverId + */ + public String getServerId() { + return serverId; + } - /** - * @return the serverName - */ - public String getServerName() { - return serverName; - } + /** + * @return the serverName + */ + public String getServerName() { + return serverName; + } - /** - * @return the ipAddress - */ - public String getIpAddress() { - return ipAddress; - } + /** + * @return the ipAddress + */ + public String getIpAddress() { + return ipAddress; + } - /** - * @return the port1 - */ - public String getPort1() { - return port1; - } + /** + * @return the port1 + */ + public String getPort1() { + return port1; + } - /** - * @return the port2 - */ - public String getPort2() { - return port2; - } + /** + * @return the port2 + */ + public String getPort2() { + return port2; + } - /** - * @return the status - */ - public String getStatus() { - return status; - } + /** + * @return the status + */ + public String getStatus() { + return status; + } - /** - * @return the now - */ - public String getNow() { - return now; - } + /** + * @return the now + */ + public String getNow() { + return now; + } - /** - * @return the peak - */ - public String getPeak() { - return peak; - } + /** + * @return the peak + */ + public String getPeak() { + return peak; + } - @Override - public int hashCode() { - return Objects.hashCode(serverId); - } + @Override + public int hashCode() { + return Objects.hashCode(serverId); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Target that = Target.class.cast(obj); - return Objects.equal(this.serverId, that.serverId); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Target that = Target.class.cast(obj); + return Objects.equal(this.serverId, that.serverId); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("serverId", serverId).add("serverName", serverName) - .add("ipAddress", ipAddress).add("port1", port1) - .add("port2", port2).add("status", status).add("now", now) - .add("peak", peak).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("serverId", serverId).add("serverName", serverName) + .add("ipAddress", ipAddress).add("port1", port1) + .add("port2", port2).add("status", status).add("now", now) + .add("peak", peak).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/UsageInfo.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/UsageInfo.java index 48cffa4b05..61c4b368e7 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/UsageInfo.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/UsageInfo.java @@ -35,60 +35,60 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "usageinfo") public class UsageInfo { - @XmlElement(name = "vsysId") - private String systemId; - @XmlElement(name = "vsysName") - private String systemName; + @XmlElement(name = "vsysId") + private String systemId; + @XmlElement(name = "vsysName") + private String systemName; - @XmlElementWrapper(name = "products") - @XmlElement(name = "product") - private Set products = new LinkedHashSet(); + @XmlElementWrapper(name = "products") + @XmlElement(name = "product") + private Set products = new LinkedHashSet(); - /** - * @return the systemId - */ - public String getSystemId() { - return systemId; - } + /** + * @return the systemId + */ + public String getSystemId() { + return systemId; + } - /** - * @return the systemName - */ - public String getSystemName() { - return systemName; - } + /** + * @return the systemName + */ + public String getSystemName() { + return systemName; + } - /** - * @return the products - */ - public Set getProducts() { - return products == null ? ImmutableSet. of() : ImmutableSet - .copyOf(products); - } + /** + * @return the products + */ + public Set getProducts() { + return products == null ? ImmutableSet. of() : ImmutableSet + .copyOf(products); + } - @Override - public int hashCode() { - return Objects.hashCode(systemId, systemName, products); - } + @Override + public int hashCode() { + return Objects.hashCode(systemId, systemName, products); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - UsageInfo that = UsageInfo.class.cast(obj); - return Objects.equal(this.systemId, that.systemId) - && Objects.equal(this.systemName, that.systemName) - && Objects.equal(this.products, that.products); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UsageInfo that = UsageInfo.class.cast(obj); + return Objects.equal(this.systemId, that.systemId) + && Objects.equal(this.systemName, that.systemName) + && Objects.equal(this.products, that.products); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("systemId", systemId).add("systemName", systemName) - .add("products", products).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("systemId", systemId).add("systemName", systemName) + .add("products", products).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDisk.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDisk.java index e8784c4a98..e90815e3c4 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDisk.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDisk.java @@ -30,57 +30,57 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "vdisk") public class VDisk { - @XmlElement(name = "diskId") - private String id; - @XmlElement(name = "diskName") - private String name; - @XmlElement(name = "attachedTo") - private String attachedServer; - private String creator; - private double size; + @XmlElement(name = "diskId") + private String id; + @XmlElement(name = "diskName") + private String name; + @XmlElement(name = "attachedTo") + private String attachedServer; + private String creator; + private double size; - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getAttachedServer() { - return attachedServer; - } + public String getAttachedServer() { + return attachedServer; + } - public String getCreator() { - return creator; - } + public String getCreator() { + return creator; + } - public double getSize() { - return size; - } + public double getSize() { + return size; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VDisk that = VDisk.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VDisk that = VDisk.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("attachedServer", attachedServer) - .add("creator", creator).add("size", size).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("attachedServer", attachedServer) + .add("creator", creator).add("size", size).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDiskStatus.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDiskStatus.java index cc4459426c..c0ad812e05 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDiskStatus.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VDiskStatus.java @@ -18,12 +18,12 @@ */ package org.jclouds.fujitsu.fgcp.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.CaseFormat; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Possible statuses of an attachable virtual disk. * @@ -32,24 +32,24 @@ import static com.google.common.base.Preconditions.checkNotNull; @XmlRootElement(name = "vdiskStatus") public enum VDiskStatus { - NORMAL, BACKUP_ING, DEPLOYING, DETACHING, ATTACHING, RESTORING, ERROR, UNRECOGNIZED; + NORMAL, BACKUP_ING, DEPLOYING, DETACHING, ATTACHING, RESTORING, ERROR, UNRECOGNIZED; - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); - } + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } - @Override - public String toString() { - return value(); - } + @Override + public String toString() { + return value(); + } - public static VDiskStatus fromValue(String status) { - try { - return valueOf(CaseFormat.UPPER_CAMEL - .to(CaseFormat.UPPER_UNDERSCORE, - checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static VDiskStatus fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL + .to(CaseFormat.UPPER_UNDERSCORE, + checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNIC.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNIC.java index 6fbf0770c2..9091384fe1 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNIC.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNIC.java @@ -29,45 +29,45 @@ import com.google.common.base.Objects; */ @XmlRootElement(name = "vnic") public class VNIC { - private String networkId; + private String networkId; - private String privateIp; + private String privateIp; - private int nicNo; + private int nicNo; - public String getNetworkId() { - return networkId; - } + public String getNetworkId() { + return networkId; + } - public String getPrivateIp() { - return privateIp; - } + public String getPrivateIp() { + return privateIp; + } - public int getNicNo() { - return nicNo; - } + public int getNicNo() { + return nicNo; + } - @Override - public int hashCode() { - return Objects.hashCode(networkId); - } + @Override + public int hashCode() { + return Objects.hashCode(networkId); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VNIC that = VNIC.class.cast(obj); - return Objects.equal(this.networkId, that.networkId); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VNIC that = VNIC.class.cast(obj); + return Objects.equal(this.networkId, that.networkId); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("networkId", networkId).add("privateIp", privateIp) - .add("nicNo", nicNo).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues() + .add("networkId", networkId).add("privateIp", privateIp) + .add("nicNo", nicNo).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNet.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNet.java index 77210c146e..99de06cc47 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNet.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VNet.java @@ -30,32 +30,32 @@ import com.google.common.base.Objects; @XmlRootElement(name = "vnet") public class VNet { - private String networkId; + private String networkId; - public String getNetworkId() { - return networkId; - } + public String getNetworkId() { + return networkId; + } - @Override - public int hashCode() { - return Objects.hashCode(networkId); - } + @Override + public int hashCode() { + return Objects.hashCode(networkId); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VNet that = VNet.class.cast(obj); - return Objects.equal(this.networkId, that.networkId); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VNet that = VNet.class.cast(obj); + return Objects.equal(this.networkId, that.networkId); + } - @Override - public String toString() { - return Objects.toStringHelper(this).add("networkId", networkId) - .toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).add("networkId", networkId) + .toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServer.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServer.java index b3db2991cc..9db887a72c 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServer.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServer.java @@ -28,57 +28,57 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class VServer { - @XmlElement(name = "vserverId") - protected String id; - @XmlElement(name = "vserverName") - protected String name; - @XmlElement(name = "vserverType") - protected String type; - protected String diskimageId; - protected String creator; + @XmlElement(name = "vserverId") + protected String id; + @XmlElement(name = "vserverName") + protected String name; + @XmlElement(name = "vserverType") + protected String type; + protected String diskimageId; + protected String creator; - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public String getDiskimageId() { - return diskimageId; - } + public String getDiskimageId() { + return diskimageId; + } - public String getCreator() { - return creator; - } + public String getCreator() { + return creator; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VServer that = VServer.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VServer that = VServer.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("type", type).add("creator", creator) - .add("diskimageId", diskimageId).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("type", type).add("creator", creator) + .add("diskimageId", diskimageId).toString(); + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerStatus.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerStatus.java index 8576538965..1df5ce0591 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerStatus.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerStatus.java @@ -18,12 +18,12 @@ */ package org.jclouds.fujitsu.fgcp.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.CaseFormat; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Possible statuses of a virtual server. * @@ -31,24 +31,24 @@ import static com.google.common.base.Preconditions.checkNotNull; */ @XmlRootElement(name = "vserverStatus") public enum VServerStatus { - DEPLOYING, RUNNING, STOPPING, STOPPED, STARTING, FAILOVER, UNEXPECTED_STOP, RESTORING, BACKUP_ING, ERROR, START_ERROR, STOP_ERROR, CHANGE_TYPE, REGISTERING, UNRECOGNIZED; + DEPLOYING, RUNNING, STOPPING, STOPPED, STARTING, FAILOVER, UNEXPECTED_STOP, RESTORING, BACKUP_ING, ERROR, START_ERROR, STOP_ERROR, CHANGE_TYPE, REGISTERING, UNRECOGNIZED; - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); - } + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } - @Override - public String toString() { - return value(); - } + @Override + public String toString() { + return value(); + } - public static VServerStatus fromValue(String status) { - try { - return valueOf(CaseFormat.UPPER_CAMEL - .to(CaseFormat.UPPER_UNDERSCORE, - checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static VServerStatus fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL + .to(CaseFormat.UPPER_UNDERSCORE, + checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithDetails.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithDetails.java index d9613a41c2..c969953896 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithDetails.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithDetails.java @@ -35,25 +35,25 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "vserver") public class VServerWithDetails extends VServerWithVNICs { - @XmlElementWrapper(name = "vdisks") - @XmlElement(name = "vdisk") - protected Set vdisks = new LinkedHashSet(); - protected Image image; + @XmlElementWrapper(name = "vdisks") + @XmlElement(name = "vdisk") + protected Set vdisks = new LinkedHashSet(); + protected Image image; - public Set getVdisks() { - return vdisks == null ? ImmutableSet. of() : ImmutableSet - .copyOf(vdisks); - } + public Set getVdisks() { + return vdisks == null ? ImmutableSet. of() : ImmutableSet + .copyOf(vdisks); + } - public Image getImage() { - return image; - } + public Image getImage() { + return image; + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("type", type).add("creator", creator) - .add("diskimageId", diskimageId).add("vdisks", vdisks) - .add("vnics", vnics).add("image", image).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("type", type).add("creator", creator) + .add("diskimageId", diskimageId).add("vdisks", vdisks) + .add("vnics", vnics).add("image", image).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithVNICs.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithVNICs.java index 3117241320..8e46a1de6a 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithVNICs.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VServerWithVNICs.java @@ -11,19 +11,19 @@ import com.google.common.collect.ImmutableSet; public class VServerWithVNICs extends VServer { - @XmlElementWrapper(name = "vnics") - @XmlElement(name = "vnic") - protected Set vnics = new LinkedHashSet(); + @XmlElementWrapper(name = "vnics") + @XmlElement(name = "vnic") + protected Set vnics = new LinkedHashSet(); - public Set getVnics() { - return vnics == null ? ImmutableSet. of() : ImmutableSet - .copyOf(vnics); - } + public Set getVnics() { + return vnics == null ? ImmutableSet. of() : ImmutableSet + .copyOf(vnics); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("type", type).add("creator", creator) - .add("diskimageId", diskimageId).add("vnics", vnics).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("type", type).add("creator", creator) + .add("diskimageId", diskimageId).add("vnics", vnics).toString(); + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystem.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystem.java index ae86034ce3..30f51de348 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystem.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystem.java @@ -28,57 +28,57 @@ import com.google.common.base.Objects; * @author Dies Koper */ public class VSystem { - @XmlElement(name = "vsysId") - protected String id; - @XmlElement(name = "vsysName") - protected String name; - protected String creator; - @XmlElement(name = "baseDescriptor") - protected String template; - protected String description; + @XmlElement(name = "vsysId") + protected String id; + @XmlElement(name = "vsysName") + protected String name; + protected String creator; + @XmlElement(name = "baseDescriptor") + protected String template; + protected String description; - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getCreator() { - return creator; - } + public String getCreator() { + return creator; + } - public String getTemplate() { - return template; - } + public String getTemplate() { + return template; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - @Override - public int hashCode() { - return Objects.hashCode(id); - } + @Override + public int hashCode() { + return Objects.hashCode(id); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VSystem that = VSystem.class.cast(obj); - return Objects.equal(this.id, that.id); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VSystem that = VSystem.class.cast(obj); + return Objects.equal(this.id, that.id); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("creator", creator) - .add("template", template).add("description", description) - .toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("creator", creator) + .add("template", template).add("description", description) + .toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemDescriptor.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemDescriptor.java index 46f448ab9d..31a7a7e2f2 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemDescriptor.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemDescriptor.java @@ -34,71 +34,71 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "vsysdescriptor") public class VSystemDescriptor { - @XmlElement(name = "vsysdescriptorId") - private String id; + @XmlElement(name = "vsysdescriptorId") + private String id; - @XmlElement(name = "vsysdescriptorName") - private String name; + @XmlElement(name = "vsysdescriptorName") + private String name; - private String creatorName; + private String creatorName; - private String registrant; + private String registrant; - private String description; + private String description; - private String keyword; + private String keyword; - @XmlElementWrapper(name = "vservers") - @XmlElement(name = "vserver") - private Set servers = new LinkedHashSet(); + @XmlElementWrapper(name = "vservers") + @XmlElement(name = "vserver") + private Set servers = new LinkedHashSet(); - /** - * @return the id - */ - public String getId() { - return id; - } + /** + * @return the id + */ + public String getId() { + return id; + } - /** - * @return the name - */ - public String getName() { - return name; - } + /** + * @return the name + */ + public String getName() { + return name; + } - /** - * @return the creatorName - */ - public String getCreatorName() { - return creatorName; - } + /** + * @return the creatorName + */ + public String getCreatorName() { + return creatorName; + } - /** - * @return the registrant - */ - public String getRegistrant() { - return registrant; - } + /** + * @return the registrant + */ + public String getRegistrant() { + return registrant; + } - /** - * @return the description - */ - public String getDescription() { - return description; - } + /** + * @return the description + */ + public String getDescription() { + return description; + } - /** - * @return the keyword - */ - public String getKeyword() { - return keyword; - } + /** + * @return the keyword + */ + public String getKeyword() { + return keyword; + } - /** - * @return the servers - */ - public Set getServers() { - return servers == null ? ImmutableSet. of() - : ImmutableSet.copyOf(servers); - } + /** + * @return the servers + */ + public Set getServers() { + return servers == null ? ImmutableSet. of() + : ImmutableSet.copyOf(servers); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemStatus.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemStatus.java index 58e6e7a048..1668b291e3 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemStatus.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemStatus.java @@ -18,12 +18,12 @@ */ package org.jclouds.fujitsu.fgcp.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.CaseFormat; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Possible statuses of a virtual system. * @@ -31,24 +31,24 @@ import static com.google.common.base.Preconditions.checkNotNull; */ @XmlRootElement(name = "vsysStatus") public enum VSystemStatus { - NORMAL, RECONFIG_ING, DEPLOYING, ERROR, UNRECOGNIZED; + NORMAL, RECONFIG_ING, DEPLOYING, ERROR, UNRECOGNIZED; - public String value() { - return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); - } + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } - @Override - public String toString() { - return value(); - } + @Override + public String toString() { + return value(); + } - public static VSystemStatus fromValue(String status) { - try { - return valueOf(CaseFormat.UPPER_CAMEL - .to(CaseFormat.UPPER_UNDERSCORE, - checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } + public static VSystemStatus fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL + .to(CaseFormat.UPPER_UNDERSCORE, + checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemWithDetails.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemWithDetails.java index 16839889a7..7ae51fd203 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemWithDetails.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/VSystemWithDetails.java @@ -36,45 +36,45 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "vsys") public class VSystemWithDetails extends VSystem { - @XmlElementWrapper(name = "vservers") - @XmlElement(name = "vserver") - private Set servers = new LinkedHashSet(); - @XmlElementWrapper(name = "vdisks") - @XmlElement(name = "vdisk") - private Set disks = new LinkedHashSet(); - @XmlElementWrapper(name = "publicips") - @XmlElement(name = "publicip") - private Set publicips = new LinkedHashSet(); - @XmlElementWrapper(name = "vnets") - @XmlElement(name = "vnet") - private Set networks = new LinkedHashSet(); + @XmlElementWrapper(name = "vservers") + @XmlElement(name = "vserver") + private Set servers = new LinkedHashSet(); + @XmlElementWrapper(name = "vdisks") + @XmlElement(name = "vdisk") + private Set disks = new LinkedHashSet(); + @XmlElementWrapper(name = "publicips") + @XmlElement(name = "publicip") + private Set publicips = new LinkedHashSet(); + @XmlElementWrapper(name = "vnets") + @XmlElement(name = "vnet") + private Set networks = new LinkedHashSet(); - public Set getServers() { - return servers == null ? ImmutableSet. of() : ImmutableSet - .copyOf(servers); - } + public Set getServers() { + return servers == null ? ImmutableSet. of() : ImmutableSet + .copyOf(servers); + } - public Set getDisks() { - return disks == null ? ImmutableSet. of() : ImmutableSet - .copyOf(disks); - } + public Set getDisks() { + return disks == null ? ImmutableSet. of() : ImmutableSet + .copyOf(disks); + } - public Set getPublicips() { - return publicips == null ? ImmutableSet. of() : ImmutableSet - .copyOf(publicips); - } + public Set getPublicips() { + return publicips == null ? ImmutableSet. of() : ImmutableSet + .copyOf(publicips); + } - public Set getNetworks() { - return networks == null ? ImmutableSet. of() : ImmutableSet - .copyOf(networks); - } + public Set getNetworks() { + return networks == null ? ImmutableSet. of() : ImmutableSet + .copyOf(networks); + } - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("id", id) - .add("name", name).add("creator", creator) - .add("template", template).add("description", description) - .add("disks", disks).add("networks", networks) - .add("publicips", publicips).add("servers", servers).toString(); - } + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id) + .add("name", name).add("creator", creator) + .add("template", template).add("description", description) + .add("disks", disks).add("networks", networks) + .add("publicips", publicips).add("servers", servers).toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/package-info.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/package-info.java index 4f79fc1182..4c2494a2a8 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/package-info.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/domain/package-info.java @@ -20,7 +20,7 @@ @XmlAccessorType(XmlAccessType.FIELD) package org.jclouds.fujitsu.fgcp.domain; -import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlSchema; diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java index 9fecf69ca3..4cf2340d5d 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java @@ -42,7 +42,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.jclouds.Constants; -import org.jclouds.crypto.CryptoStreams; import org.jclouds.date.TimeStamp; import org.jclouds.encryption.internal.Base64; import org.jclouds.fujitsu.fgcp.reference.RequestParameters; @@ -69,174 +68,174 @@ import com.google.common.collect.Multimap; @Singleton public class RequestAuthenticator implements HttpRequestFilter, RequestSigner { - @Resource - @Named(Constants.LOGGER_SIGNATURE) - private Logger signatureLog = Logger.NULL; + @Resource + @Named(Constants.LOGGER_SIGNATURE) + private Logger signatureLog = Logger.NULL; - final Provider calendarProvider; - final Signature signer; - final Provider builder; - final String apiVersion; + final Provider calendarProvider; + final Signature signer; + final Provider builder; + final String apiVersion; - public String signatureVersion = "1.0"; - public String signatureMethod = "SHA1withRSA"; + public String signatureVersion = "1.0"; + public String signatureMethod = "SHA1withRSA"; - private HttpUtils utils; + private HttpUtils utils; - @Inject - public RequestAuthenticator(@TimeStamp Provider calendarProvider, - Provider keyStoreProvider, - @Credential String keyPassword, Provider builder, - HttpUtils utils, SignatureWire signatureWire, - @ApiVersion String apiVersion) throws NoSuchAlgorithmException, - InvalidKeyException, KeyStoreException, UnrecoverableKeyException { - this.calendarProvider = checkNotNull(calendarProvider); - this.builder = checkNotNull(builder); - this.utils = checkNotNull(utils, "utils"); - this.apiVersion = checkNotNull(apiVersion, "apiVersion"); + @Inject + public RequestAuthenticator(@TimeStamp Provider calendarProvider, + Provider keyStoreProvider, + @Credential String keyPassword, Provider builder, + HttpUtils utils, SignatureWire signatureWire, + @ApiVersion String apiVersion) throws NoSuchAlgorithmException, + InvalidKeyException, KeyStoreException, UnrecoverableKeyException { + this.calendarProvider = checkNotNull(calendarProvider); + this.builder = checkNotNull(builder); + this.utils = checkNotNull(utils, "utils"); + this.apiVersion = checkNotNull(apiVersion, "apiVersion"); - signer = Signature.getInstance(signatureMethod); + signer = Signature.getInstance(signatureMethod); - KeyStore keyStore = checkNotNull(keyStoreProvider).get(); - String alias = keyStore.aliases().nextElement(); // there should be only - // one private key - PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, - keyPassword.toCharArray()); + KeyStore keyStore = checkNotNull(keyStoreProvider).get(); + String alias = keyStore.aliases().nextElement(); // there should be only + // one private key + PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, + keyPassword.toCharArray()); - signer.initSign(privateKey); - } + signer.initSign(privateKey); + } - public HttpRequest filter(HttpRequest request) throws HttpException { - checkNotNull(request, "request must be present"); + public HttpRequest filter(HttpRequest request) throws HttpException { + checkNotNull(request, "request must be present"); - utils.logRequest(signatureLog, request, ">>"); + utils.logRequest(signatureLog, request, ">>"); - // create accesskeyid - String accessKeyId = createStringToSign(request); - String signature = sign(accessKeyId); + // create accesskeyid + String accessKeyId = createStringToSign(request); + String signature = sign(accessKeyId); - // leaving this in for now for reference in case I need it for multipart - // POSTs - // add parameters. Note that in case of a GET, url escaping is required - /* - * Multimap decodedParams = null; if - * (HttpMethod.GET.equals(request.getMethod())) { decodedParams = - * ModifyRequest.parseQueryToMap(request.getEndpoint().getRawQuery()); - * - * } else if (HttpMethod.POST.equals(request.getMethod())) { - * decodedParams = - * ModifyRequest.parseQueryToMap(request.getPayload().getRawContent() - * .toString()); } - * - * checkNotNull(decodedParams, "no query params found"); - * System.out.println("filter: request params before: " + - * decodedParams.toString()); addAuthenticationParams(decodedParams, - * accessKeyId, signature); addLocaleParam(decodedParams); - * System.out.println("filter: request params after : " + - * decodedParams.toString()); if (signatureWire.enabled()) - * signatureWire.output(decodedParams); - * - * - * request = setPayload(request, decodedParams); - */ - // only "en" and "ja" are allowed - String lang = Locale.JAPANESE.getLanguage().equals( - Locale.getDefault().getLanguage()) ? Locale.JAPANESE - .getLanguage() : Locale.ENGLISH.getLanguage(); + // leaving this in for now for reference in case I need it for multipart + // POSTs + // add parameters. Note that in case of a GET, url escaping is required + /* + * Multimap decodedParams = null; if + * (HttpMethod.GET.equals(request.getMethod())) { decodedParams = + * ModifyRequest.parseQueryToMap(request.getEndpoint().getRawQuery()); + * + * } else if (HttpMethod.POST.equals(request.getMethod())) { + * decodedParams = + * ModifyRequest.parseQueryToMap(request.getPayload().getRawContent() + * .toString()); } + * + * checkNotNull(decodedParams, "no query params found"); + * System.out.println("filter: request params before: " + + * decodedParams.toString()); addAuthenticationParams(decodedParams, + * accessKeyId, signature); addLocaleParam(decodedParams); + * System.out.println("filter: request params after : " + + * decodedParams.toString()); if (signatureWire.enabled()) + * signatureWire.output(decodedParams); + * + * + * request = setPayload(request, decodedParams); + */ + // only "en" and "ja" are allowed + String lang = Locale.JAPANESE.getLanguage().equals( + Locale.getDefault().getLanguage()) ? Locale.JAPANESE + .getLanguage() : Locale.ENGLISH.getLanguage(); - if (HttpMethod.GET.equals(request.getMethod())) { - Multimap decodedParams = Queries - .parseQueryToMap(request.getEndpoint().getRawQuery()); + if (HttpMethod.GET.equals(request.getMethod())) { + Multimap decodedParams = Queries + .parseQueryToMap(request.getEndpoint().getRawQuery()); - if (!decodedParams.containsKey(RequestParameters.VERSION)) { - decodedParams.put(RequestParameters.VERSION, apiVersion); - } - decodedParams.put(RequestParameters.LOCALE, lang); - decodedParams.put(RequestParameters.ACCESS_KEY_ID, accessKeyId); - decodedParams.put(RequestParameters.SIGNATURE, signature); - request = request.toBuilder().replaceQueryParams(decodedParams) - .build(); - } else { + if (!decodedParams.containsKey(RequestParameters.VERSION)) { + decodedParams.put(RequestParameters.VERSION, apiVersion); + } + decodedParams.put(RequestParameters.LOCALE, lang); + decodedParams.put(RequestParameters.ACCESS_KEY_ID, accessKeyId); + decodedParams.put(RequestParameters.SIGNATURE, signature); + request = request.toBuilder().replaceQueryParams(decodedParams) + .build(); + } else { - String payload = request.getPayload().getRawContent().toString(); - payload = createXmlElementWithValue(payload, - RequestParameters.VERSION, apiVersion); - payload = createXmlElementWithValue(payload, - RequestParameters.LOCALE, lang); - payload = createXmlElementWithValue(payload, - RequestParameters.ACCESS_KEY_ID, accessKeyId); - payload = createXmlElementWithValue(payload, - RequestParameters.SIGNATURE, signature); + String payload = request.getPayload().getRawContent().toString(); + payload = createXmlElementWithValue(payload, + RequestParameters.VERSION, apiVersion); + payload = createXmlElementWithValue(payload, + RequestParameters.LOCALE, lang); + payload = createXmlElementWithValue(payload, + RequestParameters.ACCESS_KEY_ID, accessKeyId); + payload = createXmlElementWithValue(payload, + RequestParameters.SIGNATURE, signature); - // ensure there are no other query params left - request.setPayload(payload); - request.getPayload().getContentMetadata() - .setContentType(MediaType.TEXT_XML); - } + // ensure there are no other query params left + request.setPayload(payload); + request.getPayload().getContentMetadata() + .setContentType(MediaType.TEXT_XML); + } - // may need to do this elsewhere (see ConvertToGaeRequest) - HttpRequest filteredRequest = request.toBuilder() - .replaceHeader(HttpHeaders.USER_AGENT, "OViSS-API-CLIENT") - .build(); + // may need to do this elsewhere (see ConvertToGaeRequest) + HttpRequest filteredRequest = request.toBuilder() + .replaceHeader(HttpHeaders.USER_AGENT, "OViSS-API-CLIENT") + .build(); - utils.logRequest(signatureLog, filteredRequest, ">>->"); + utils.logRequest(signatureLog, filteredRequest, ">>->"); - return filteredRequest; - } + return filteredRequest; + } - String createXmlElementWithValue(String payload, String tag, String value) { - String startTag = String.format("<%s>", tag); - String endTag = String.format("", tag); + String createXmlElementWithValue(String payload, String tag, String value) { + String startTag = String.format("<%s>", tag); + String endTag = String.format("", tag); - return payload.replace(startTag + endTag, startTag + value + endTag); - } + return payload.replace(startTag + endTag, startTag + value + endTag); + } - /* - * HttpRequest setPayload(HttpRequest request, Multimap - * decodedParams) { - * request.setPayload(ModifyRequest.makeQueryLine(decodedParams, null)); // - * request.getPayload().getContentMetadata().setContentType( - * "application/x-www-form-urlencoded"); return request; } - */ + /* + * HttpRequest setPayload(HttpRequest request, Multimap + * decodedParams) { + * request.setPayload(ModifyRequest.makeQueryLine(decodedParams, null)); // + * request.getPayload().getContentMetadata().setContentType( + * "application/x-www-form-urlencoded"); return request; } + */ - @VisibleForTesting - public String sign(String stringToSign) { - String signed; + @VisibleForTesting + public String sign(String stringToSign) { + String signed; - try { - signer.update(stringToSign.getBytes("UTF-8")); - signed = Base64.encodeBytes(signer.sign()).replace("\n", "\r\n"); -// signed = CryptoStreams.base64(signer.sign()); - } catch (Exception e) { - throw new HttpException("error signing request", e); - } - // if (signatureWire.enabled()) - // signatureWire.input(Strings2.toInputStream(signed)); + try { + signer.update(stringToSign.getBytes("UTF-8")); + signed = Base64.encodeBytes(signer.sign()).replace("\n", "\r\n"); +// signed = CryptoStreams.base64(signer.sign()); + } catch (Exception e) { + throw new HttpException("error signing request", e); + } + // if (signatureWire.enabled()) + // signatureWire.input(Strings2.toInputStream(signed)); - return signed; - } + return signed; + } - @VisibleForTesting - public String generateAccessKeyId() { - Calendar cal = calendarProvider.get(); - String timezone = cal.getTimeZone().getDisplayName(Locale.ENGLISH); - String expires = String.valueOf(cal.getTime().getTime()); + @VisibleForTesting + public String generateAccessKeyId() { + Calendar cal = calendarProvider.get(); + String timezone = cal.getTimeZone().getDisplayName(Locale.ENGLISH); + String expires = String.valueOf(cal.getTime().getTime()); - String signatureData = String.format("%s&%s&%s&%s", timezone, expires, - signatureVersion, signatureMethod); - try { - String accessKeyId = Base64.encodeBytes(signatureData.getBytes("UTF-8")); - return accessKeyId.replace("\n", "\r\n"); -// return CryptoStreams.base64(signatureData.getBytes("UTF-8")).; - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); // should never happen as - // signatureData contains only ASCII - } - } + String signatureData = String.format("%s&%s&%s&%s", timezone, expires, + signatureVersion, signatureMethod); + try { + String accessKeyId = Base64.encodeBytes(signatureData.getBytes("UTF-8")); + return accessKeyId.replace("\n", "\r\n"); +// return CryptoStreams.base64(signatureData.getBytes("UTF-8")).; + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); // should never happen as + // signatureData contains only ASCII + } + } - @Override - public String createStringToSign(HttpRequest input) { - return generateAccessKeyId(); - } + @Override + public String createStringToSign(HttpRequest input) { + return generateAccessKeyId(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/handlers/FGCPRetryIfNotProxyAuthenticationFailureHandler.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/handlers/FGCPRetryIfNotProxyAuthenticationFailureHandler.java index 0104aaf61c..9d4c05de9c 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/handlers/FGCPRetryIfNotProxyAuthenticationFailureHandler.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/handlers/FGCPRetryIfNotProxyAuthenticationFailureHandler.java @@ -18,13 +18,14 @@ */ package org.jclouds.fujitsu.fgcp.handlers; -import com.google.inject.Singleton; +import javax.annotation.Resource; + import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpRetryHandler; import org.jclouds.logging.Logger; -import javax.annotation.Resource; +import com.google.inject.Singleton; /** * Created by IntelliJ IDEA. @@ -33,15 +34,15 @@ import javax.annotation.Resource; */ @Singleton public class FGCPRetryIfNotProxyAuthenticationFailureHandler implements - HttpRetryHandler { - @Resource - protected Logger logger = Logger.NULL; + HttpRetryHandler { + @Resource + protected Logger logger = Logger.NULL; - @Override - public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { - int statusCode = response.getStatusCode(); - System.out.println("Response status code: " + statusCode); - logger.error("StatusCode", statusCode); - return true; - } + @Override + public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { + int statusCode = response.getStatusCode(); + System.out.println("Response status code: " + statusCode); + logger.error("StatusCode", statusCode); + return true; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/http/SSLContextWithKeysSupplier.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/http/SSLContextWithKeysSupplier.java index c0e20196a5..38974e348f 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/http/SSLContextWithKeysSupplier.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/http/SSLContextWithKeysSupplier.java @@ -45,27 +45,27 @@ import com.google.common.base.Supplier; */ @Singleton public class SSLContextWithKeysSupplier implements Supplier { - private SSLContext sc; + private SSLContext sc; - @Inject - SSLContextWithKeysSupplier(KeyStore keyStore, - @Credential String keyStorePassword, HttpUtils utils, - TrustAllCerts trustAllCerts) throws NoSuchAlgorithmException, - KeyStoreException, UnrecoverableKeyException, - KeyManagementException { + @Inject + SSLContextWithKeysSupplier(KeyStore keyStore, + @Credential String keyStorePassword, HttpUtils utils, + TrustAllCerts trustAllCerts) throws NoSuchAlgorithmException, + KeyStoreException, UnrecoverableKeyException, + KeyManagementException { - TrustManager[] trustManager = null; - if (utils.trustAllCerts()) { - trustManager = new TrustManager[] { trustAllCerts }; - } - KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); - kmf.init(keyStore, keyStorePassword.toCharArray()); - sc = SSLContext.getInstance("TLS"); - sc.init(kmf.getKeyManagers(), trustManager, new SecureRandom()); - } + TrustManager[] trustManager = null; + if (utils.trustAllCerts()) { + trustManager = new TrustManager[] { trustAllCerts }; + } + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(keyStore, keyStorePassword.toCharArray()); + sc = SSLContext.getInstance("TLS"); + sc.init(kmf.getKeyManagers(), trustManager, new SecureRandom()); + } - @Override - public SSLContext get() { - return sc; - } + @Override + public SSLContext get() { + return sc; + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/location/SystemAndNetworkSegmentToLocationSupplier.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/location/SystemAndNetworkSegmentToLocationSupplier.java index 569d3aedb8..476db4cd6c 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/location/SystemAndNetworkSegmentToLocationSupplier.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/location/SystemAndNetworkSegmentToLocationSupplier.java @@ -66,55 +66,55 @@ import com.google.common.util.concurrent.ListenableFuture; */ @Singleton public class SystemAndNetworkSegmentToLocationSupplier implements - LocationsSupplier { + LocationsSupplier { - private final RegionToProviderOrJustProvider regionProvider; - private FGCPAsyncApi api; + private final RegionToProviderOrJustProvider regionProvider; + private FGCPAsyncApi api; - @Inject - SystemAndNetworkSegmentToLocationSupplier( - RegionToProviderOrJustProvider regionProvider, FGCPAsyncApi api) { - this.regionProvider = checkNotNull(regionProvider, - "regionToProviderOrJustProvider"); - this.api = checkNotNull(api, "api"); - } + @Inject + SystemAndNetworkSegmentToLocationSupplier( + RegionToProviderOrJustProvider regionProvider, FGCPAsyncApi api) { + this.regionProvider = checkNotNull(regionProvider, + "regionToProviderOrJustProvider"); + this.api = checkNotNull(api, "api"); + } - @Override - public Set get() { - Builder locations = ImmutableSet.builder(); - try { - List> futures = new ArrayList>(); - for (VSystem system : api.getVirtualDCApi().listVirtualSystems() - .get()) { + @Override + public Set get() { + Builder locations = ImmutableSet.builder(); + try { + List> futures = new ArrayList>(); + for (VSystem system : api.getVirtualDCApi().listVirtualSystems() + .get()) { - futures.add(api.getVirtualSystemApi() - .getDetails(system.getId())); + futures.add(api.getVirtualSystemApi() + .getDetails(system.getId())); + } + for (VSystemWithDetails system : Futures.successfulAsList(futures) + .get()) { + + Location systemLocation = new LocationBuilder() + .scope(LocationScope.SYSTEM) + .parent(Iterables.getOnlyElement(regionProvider.get())) + .description(system.getName()).id(system.getId()) + .build(); + + for (VNet net : system.getNetworks()) { + + locations.add(new LocationBuilder() + .scope(LocationScope.NETWORK) + .parent(systemLocation) + .description( + net.getNetworkId().replaceFirst( + ".+(DMZ|SECURE.)", "\\1")) + .id(net.getNetworkId()).build()); } - for (VSystemWithDetails system : Futures.successfulAsList(futures) - .get()) { - - Location systemLocation = new LocationBuilder() - .scope(LocationScope.SYSTEM) - .parent(Iterables.getOnlyElement(regionProvider.get())) - .description(system.getName()).id(system.getId()) - .build(); - - for (VNet net : system.getNetworks()) { - - locations.add(new LocationBuilder() - .scope(LocationScope.NETWORK) - .parent(systemLocation) - .description( - net.getNetworkId().replaceFirst( - ".+(DMZ|SECURE.)", "\\1")) - .id(net.getNetworkId()).build()); - } - } - } catch (InterruptedException e) { - throw Throwables.propagate(e); - } catch (ExecutionException e) { - throw Throwables.propagate(e); - } - return locations.build(); - } + } + } catch (InterruptedException e) { + throw Throwables.propagate(e); + } catch (ExecutionException e) { + throw Throwables.propagate(e); + } + return locations.build(); + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/reference/RequestParameters.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/reference/RequestParameters.java index d4870c540d..784773cb10 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/reference/RequestParameters.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/reference/RequestParameters.java @@ -25,57 +25,57 @@ package org.jclouds.fujitsu.fgcp.reference; */ public interface RequestParameters { - /** - * Indicates the action to perform. Example: ListVSYS - */ - public static final String ACTION = "Action"; + /** + * Indicates the action to perform. Example: ListVSYS + */ + public static final String ACTION = "Action"; - /** - * The API version to use. Example: 2011-01-31 - */ - public static final String VERSION = "Version"; + /** + * The API version to use. Example: 2011-01-31 + */ + public static final String VERSION = "Version"; - /** - * The locale to use. Example: en - */ - public static final String LOCALE = "Locale"; + /** + * The locale to use. Example: en + */ + public static final String LOCALE = "Locale"; - /** - * The Access Key ID for the request sender. This identifies the account - * which will be charged for usage of the service. The account with which - * the Access Key ID is associated must be signed up for FGCP, or requests - * will not be accepted. AKIADQKE4SARGYLE - */ - public static final String ACCESS_KEY_ID = "AccessKeyId"; + /** + * The Access Key ID for the request sender. This identifies the account + * which will be charged for usage of the service. The account with which + * the Access Key ID is associated must be signed up for FGCP, or requests + * will not be accepted. AKIADQKE4SARGYLE + */ + public static final String ACCESS_KEY_ID = "AccessKeyId"; - /** - * The date and time at which the request is signed, in the format - * YYYY-MM-DDThh:mm:ssZ. For more information, go to ISO 8601. Example: - * 2006-07-07T15:04:56Z - */ - public static final String TIMESTAMP = "Timestamp"; + /** + * The date and time at which the request is signed, in the format + * YYYY-MM-DDThh:mm:ssZ. For more information, go to ISO 8601. Example: + * 2006-07-07T15:04:56Z + */ + public static final String TIMESTAMP = "Timestamp"; - /** - * The date and time at which the signer included in the request expires, in - * the format YYYY-MM-DDThh:mm:ssZ. Example: 2006-07-07T15:04:56Z - */ - public static final String EXPIRES = "Expires"; + /** + * The date and time at which the signer included in the request expires, in + * the format YYYY-MM-DDThh:mm:ssZ. Example: 2006-07-07T15:04:56Z + */ + public static final String EXPIRES = "Expires"; - /** - * The request signer. For more information, go to the Amazon Elastic - * Compute Cloud Developer Guide. Example: Qnpl4Qk/7tINHzfXCiT7VbBatDA= - */ - public static final String SIGNATURE = "Signature"; + /** + * The request signer. For more information, go to the Amazon Elastic + * Compute Cloud Developer Guide. Example: Qnpl4Qk/7tINHzfXCiT7VbBatDA= + */ + public static final String SIGNATURE = "Signature"; - /** - * The hash algorithm you use to create the request signer. Valid value: - * SHA1withRSA. - */ - public static final String SIGNATURE_METHOD = "SignatureMethod"; + /** + * The hash algorithm you use to create the request signer. Valid value: + * SHA1withRSA. + */ + public static final String SIGNATURE_METHOD = "SignatureMethod"; - /** - * The signer version you use to sign the request. Set this value to 1.0. - * - */ - public static final String SIGNATURE_VERSION = "SignatureVersion"; + /** + * The signer version you use to sign the request. Set this value to 1.0. + * + */ + public static final String SIGNATURE_VERSION = "SignatureVersion"; } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApi.java index 2b4cbb658a..ec0e455e54 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.fujitsu.fgcp.services; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -33,21 +32,21 @@ import org.jclouds.fujitsu.fgcp.domain.VDiskStatus; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface AdditionalDiskApi { - VDiskStatus getStatus(String id); + VDiskStatus getStatus(String id); - VDisk get(String id); + VDisk get(String id); - void update(String id, String name, String value); + void update(String id, String name, String value); - void backup(String id); + void backup(String id); - void restore(String systemId, String backupId); + void restore(String systemId, String backupId); - void destroy(String id); + void destroy(String id); - void detach(String diskId, String serverId); + void detach(String diskId, String serverId); - void destroyBackup(String sysId, String backupId); + void destroyBackup(String sysId, String backupId); - // Set<> listBackups(String sysId); + // Set<> listBackups(String sysId); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskAsyncApi.java index 440be5baf9..e3774855c4 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskAsyncApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.fujitsu.fgcp.services; -import java.util.Set; import java.util.concurrent.TimeUnit; import javax.ws.rs.Consumes; @@ -55,58 +54,58 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface AdditionalDiskAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVDiskStatus") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getStatus( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVDiskStatus") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getStatus( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVDiskAttributes") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVDiskAttributes") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); - @GET - @QueryParams(keys = "Action", values = "UpdateVDiskAttribute") - ListenableFuture update( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id, - @QueryParam("attributeName") String name, - @QueryParam("attributeValue") String value); + @GET + @QueryParams(keys = "Action", values = "UpdateVDiskAttribute") + ListenableFuture update( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id, + @QueryParam("attributeName") String name, + @QueryParam("attributeValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "BackupVDisk") - ListenableFuture backup( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "BackupVDisk") + ListenableFuture backup( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "RestoreVDisk") - ListenableFuture restore(@QueryParam("vsysId") String systemId, - @QueryParam("backupId") String backupId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "RestoreVDisk") + ListenableFuture restore(@QueryParam("vsysId") String systemId, + @QueryParam("backupId") String backupId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DestroyVDisk") - ListenableFuture destroy( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DestroyVDisk") + ListenableFuture destroy( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DetachVDisk") - ListenableFuture detach( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String diskId, - @QueryParam("vserverId") String serverId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DetachVDisk") + ListenableFuture detach( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String diskId, + @QueryParam("vserverId") String serverId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DestroyVDiskBackup") - ListenableFuture destroyBackup(@QueryParam("vsysId") String sysId, - @QueryParam("backupId") String backupId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DestroyVDiskBackup") + ListenableFuture destroyBackup(@QueryParam("vsysId") String sysId, + @QueryParam("backupId") String backupId); - // Set<> listBackups(String sysId); + // Set<> listBackups(String sysId); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApi.java index 274b1fbce3..82bb512cb1 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApi.java @@ -36,38 +36,38 @@ import org.jclouds.fujitsu.fgcp.domain.BuiltinServerStatus; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface BuiltinServerApi { - void start(String id); + void start(String id); - void stop(String id); + void stop(String id); - void destroy(String id); + void destroy(String id); - void backup(String id); + void backup(String id); - void restore(String id, String backupId); + void restore(String id, String backupId); - Set listBackups(String id); + Set listBackups(String id); - void destroyBackup(String id, String backupId); + void destroyBackup(String id, String backupId); - BuiltinServer get(String id); + BuiltinServer get(String id); - void update(String id, String name, String value); + void update(String id, String name, String value); - BuiltinServerStatus getStatus(String id); + BuiltinServerStatus getStatus(String id); - BuiltinServer getConfiguration(String id, BuiltinServerConfiguration configuration); + BuiltinServer getConfiguration(String id, BuiltinServerConfiguration configuration); - // BuiltinServer getConfiguration(String id, BuiltinServerConfiguration configuration, ConfigurationRequest request); - // void updateConfiguration(String id, xml?); - /* + // BuiltinServer getConfiguration(String id, BuiltinServerConfiguration configuration, ConfigurationRequest request); + // void updateConfiguration(String id, xml?); + /* getDNSConfiguration(String id) getNATConfiguration(String id) getPolicyConfiguration(String id) getLBConfiguration(String id) - * UpdateEFMConfiguration - BuiltinServer getConfiguration(String id, BuiltinServerConfiguration configuration); + * UpdateEFMConfiguration + BuiltinServer getConfiguration(String id, BuiltinServerConfiguration configuration); - */ + */ } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerAsyncApi.java index 569577fc4d..b5b3bdcb19 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerAsyncApi.java @@ -58,79 +58,79 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface BuiltinServerAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "StartEFM") - ListenableFuture start( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "StartEFM") + ListenableFuture start( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "StopEFM") - ListenableFuture stop( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "StopEFM") + ListenableFuture stop( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DestroyEFM") - ListenableFuture destroy( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DestroyEFM") + ListenableFuture destroy( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "BackupEFM") - ListenableFuture backup( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "BackupEFM") + ListenableFuture backup( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "RestoreEFM") - ListenableFuture restore( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, - @QueryParam("backupId") String backupId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "RestoreEFM") + ListenableFuture restore( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, + @QueryParam("backupId") String backupId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListEFMBackup") - ListenableFuture> listBackups( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListEFMBackup") + ListenableFuture> listBackups( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DestroyEFMBackup") - ListenableFuture destroyBackup( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, - @QueryParam("backupId") String backupId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DestroyEFMBackup") + ListenableFuture destroyBackup( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, + @QueryParam("backupId") String backupId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetEFMAttributes") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetEFMAttributes") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UpdateEFMAttribute") - ListenableFuture update( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, - @QueryParam("attributeName") String name, - @QueryParam("attributeValue") String value); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UpdateEFMAttribute") + ListenableFuture update( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, + @QueryParam("attributeName") String name, + @QueryParam("attributeValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetEFMStatus") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getStatus( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetEFMStatus") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getStatus( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetEFMConfiguration") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getConfiguration( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, - @QueryParam("configurationName") BuiltinServerConfiguration configuration); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetEFMConfiguration") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getConfiguration( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id, + @QueryParam("configurationName") BuiltinServerConfiguration configuration); // @POST // @JAXBResponseParser @@ -138,8 +138,8 @@ public interface BuiltinServerAsyncApi { // @Transform(SingleElementResponseToElement.class) // ListenableFuture> getUpdateDetails(String id); - // ListenableFuture - // updateConfiguration(@BinderParam(BindAlsoToSystemId.class) - // @QueryParam("efmId") String id, xml?); -// EFM_UPDATE, getUpdateStatus(String id); + // ListenableFuture + // updateConfiguration(@BinderParam(BindAlsoToSystemId.class) + // @QueryParam("efmId") String id, xml?); +// EFM_UPDATE, getUpdateStatus(String id); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageApi.java index 610e61dbeb..294d2827ef 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageApi.java @@ -31,9 +31,9 @@ import org.jclouds.fujitsu.fgcp.domain.DiskImage; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface DiskImageApi { - DiskImage get(String id); + DiskImage get(String id); - void update(String diskImageId, String localeId, String name, String value); + void update(String diskImageId, String localeId, String name, String value); - void deregister(String id); + void deregister(String id); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageAsyncApi.java index 9b4d613f2f..112a24dd5e 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/DiskImageAsyncApi.java @@ -51,23 +51,23 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface DiskImageAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetDiskImageAttributes") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get(@QueryParam("diskImageId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetDiskImageAttributes") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get(@QueryParam("diskImageId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UpdateDiskImageAttribute") - ListenableFuture update( - @QueryParam("diskImageId") String diskImageId, - @QueryParam("updateLcId") String localeId, - @QueryParam("attributeName") String name, - @QueryParam("attributeValue") String value); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UpdateDiskImageAttribute") + ListenableFuture update( + @QueryParam("diskImageId") String diskImageId, + @QueryParam("updateLcId") String localeId, + @QueryParam("attributeName") String name, + @QueryParam("attributeValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UnregisterDiskImage") - ListenableFuture deregister(@QueryParam("diskImageId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UnregisterDiskImage") + ListenableFuture deregister(@QueryParam("diskImageId") String id); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallApi.java index bfe54e95f7..bbb5067dd0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallApi.java @@ -32,6 +32,6 @@ import org.jclouds.fujitsu.fgcp.domain.Rule; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface FirewallApi extends BuiltinServerApi { - Set getNATConfiguration(String id); - + Set getNATConfiguration(String id); + } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallAsyncApi.java index df06dc9d5f..597e15dd2a 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/FirewallAsyncApi.java @@ -22,23 +22,15 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.POST; -import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.jclouds.concurrent.Timeout; import org.jclouds.fujitsu.fgcp.FGCPAsyncApi; -import org.jclouds.fujitsu.fgcp.binders.BindAlsoToSystemId; import org.jclouds.fujitsu.fgcp.compute.functions.SingleElementResponseToElement; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServer; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerBackup; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerConfiguration; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerStatus; import org.jclouds.fujitsu.fgcp.domain.Rule; import org.jclouds.fujitsu.fgcp.filters.RequestAuthenticator; import org.jclouds.fujitsu.fgcp.reference.RequestParameters; -import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.PayloadParams; import org.jclouds.rest.annotations.QueryParams; @@ -60,20 +52,20 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface FirewallAsyncApi extends BuiltinServerAsyncApi { - @POST - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetEFMConfiguration") - @Transform(SingleElementResponseToElement.class) - ListenableFuture> getNATConfiguration(String id); + @POST + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetEFMConfiguration") + @Transform(SingleElementResponseToElement.class) + ListenableFuture> getNATConfiguration(String id); - /* - FW_NAT_RULE, getNATConfiguration(String id) + /* + FW_NAT_RULE, getNATConfiguration(String id) - FW_DNS, getDNSConfiguration(String id) - FW_POLICY, getPolicyConfiguration(String id) + FW_DNS, getDNSConfiguration(String id) + FW_POLICY, getPolicyConfiguration(String id) - FW_LOG, getFirewallLogs(String id); - FW_LIMIT_POLICY, + FW_LOG, getFirewallLogs(String id); + FW_LIMIT_POLICY, - */ + */ } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/LoadBalancerAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/LoadBalancerAsyncApi.java index a7a645201b..49871284bd 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/LoadBalancerAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/LoadBalancerAsyncApi.java @@ -18,32 +18,18 @@ */ package org.jclouds.fujitsu.fgcp.services; -import java.util.Set; import java.util.concurrent.TimeUnit; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.jclouds.concurrent.Timeout; import org.jclouds.fujitsu.fgcp.FGCPAsyncApi; -import org.jclouds.fujitsu.fgcp.binders.BindAlsoToSystemId; -import org.jclouds.fujitsu.fgcp.compute.functions.SingleElementResponseToElement; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServer; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerBackup; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerConfiguration; -import org.jclouds.fujitsu.fgcp.domain.BuiltinServerStatus; import org.jclouds.fujitsu.fgcp.filters.RequestAuthenticator; import org.jclouds.fujitsu.fgcp.reference.RequestParameters; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.PayloadParams; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.Transform; - -import com.google.common.util.concurrent.ListenableFuture; /** * Non-blocking API relating to a built-in server, also called extended function @@ -58,12 +44,12 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface LoadBalancerAsyncApi extends BuiltinServerAsyncApi { - /* - SLB_RULE, getLBConfiguration(String id) - SLB_LOAD_STATISTICS, getLoadBalancerStats(String id) - SLB_ERROR_STATISTICS, getLoadBalancerErrorStats(String id) - SLB_CERTIFICATE_LIST, getLoadBalancerCerts(String id) - SLB_CONNECTION, getLoadBalancerConnection(String id) + /* + SLB_RULE, getLBConfiguration(String id) + SLB_LOAD_STATISTICS, getLoadBalancerStats(String id) + SLB_ERROR_STATISTICS, getLoadBalancerErrorStats(String id) + SLB_CERTIFICATE_LIST, getLoadBalancerCerts(String id) + SLB_CONNECTION, getLoadBalancerConnection(String id) - */ + */ } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApi.java index 9bb40355ac..21771d74d0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApi.java @@ -32,13 +32,13 @@ import org.jclouds.fujitsu.fgcp.domain.PublicIPStatus; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface PublicIPAddressApi { - void attach(String systemId, String ip); + void attach(String systemId, String ip); - void detach(String systemId, String ip); + void detach(String systemId, String ip); - void free(String systemId, String ip); + void free(String systemId, String ip); - PublicIPStatus getStatus(String ip); + PublicIPStatus getStatus(String ip); - PublicIP get(String ip); + PublicIP get(String ip); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressAsyncApi.java index 0b50dc7fa5..5b26fa1cf0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressAsyncApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.fujitsu.fgcp.services; -import java.util.Set; import java.util.concurrent.TimeUnit; import javax.ws.rs.Consumes; @@ -53,35 +52,35 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface PublicIPAddressAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "AttachPublicIP") - ListenableFuture attach(@QueryParam("vsysId") String systemId, - @QueryParam("publicIp") String ip); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "AttachPublicIP") + ListenableFuture attach(@QueryParam("vsysId") String systemId, + @QueryParam("publicIp") String ip); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DetachPublicIP") - ListenableFuture detach(@QueryParam("vsysId") String systemId, - @QueryParam("publicIp") String ip); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DetachPublicIP") + ListenableFuture detach(@QueryParam("vsysId") String systemId, + @QueryParam("publicIp") String ip); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetPublicIPStatus") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getStatus( - @QueryParam("publicIp") String ip); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetPublicIPStatus") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getStatus( + @QueryParam("publicIp") String ip); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetPublicIPAttributes") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get(@QueryParam("publicIp") String ip); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetPublicIPAttributes") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get(@QueryParam("publicIp") String ip); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "FreePublicIP") - ListenableFuture free(@QueryParam("vsysId") String systemId, - @QueryParam("publicIp") String ip); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "FreePublicIP") + ListenableFuture free(@QueryParam("vsysId") String systemId, + @QueryParam("publicIp") String ip); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApi.java index e995a72de4..16bfde89d4 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApi.java @@ -32,12 +32,12 @@ import org.jclouds.fujitsu.fgcp.domain.VSystemDescriptor; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface SystemTemplateApi { - VSystemDescriptor get(String id); + VSystemDescriptor get(String id); - void update(String id, String localeId, String name, String value); + void update(String id, String localeId, String name, String value); - void deregister(String id); + void deregister(String id); - void deregisterPrivateTemplate(String id); + void deregisterPrivateTemplate(String id); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateAsyncApi.java index 74a93b2b3d..0deb371877 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateAsyncApi.java @@ -52,30 +52,30 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface SystemTemplateAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVSYSDescriptorConfiguration") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get( - @QueryParam("vsysDescriptorId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVSYSDescriptorConfiguration") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get( + @QueryParam("vsysDescriptorId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UpdateVSYSDescriptorAttribute") - ListenableFuture update(@QueryParam("vsysDescriptorId") String id, - @QueryParam("updateLcId") String localeId, - @QueryParam("attributeName") String name, - @QueryParam("attributeValue") String value); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UpdateVSYSDescriptorAttribute") + ListenableFuture update(@QueryParam("vsysDescriptorId") String id, + @QueryParam("updateLcId") String localeId, + @QueryParam("attributeName") String name, + @QueryParam("attributeValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UnregisterVSYSDescriptor") - ListenableFuture deregister( - @QueryParam("vsysDescriptorId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UnregisterVSYSDescriptor") + ListenableFuture deregister( + @QueryParam("vsysDescriptorId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UnregisterPrivateVSYSDescriptor") - ListenableFuture deregisterPrivateTemplate( - @QueryParam("vsysDescriptorId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UnregisterPrivateVSYSDescriptor") + ListenableFuture deregisterPrivateTemplate( + @QueryParam("vsysDescriptorId") String id); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java index bb3ec3597a..7a8a4628c7 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java @@ -18,13 +18,21 @@ */ package org.jclouds.fujitsu.fgcp.services; -import org.jclouds.concurrent.Timeout; -import org.jclouds.fujitsu.fgcp.domain.*; - import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.concurrent.Timeout; +import org.jclouds.fujitsu.fgcp.domain.AddressRange; +import org.jclouds.fujitsu.fgcp.domain.DiskImage; +import org.jclouds.fujitsu.fgcp.domain.EventLog; +import org.jclouds.fujitsu.fgcp.domain.Information; +import org.jclouds.fujitsu.fgcp.domain.PublicIP; +import org.jclouds.fujitsu.fgcp.domain.ServerType; +import org.jclouds.fujitsu.fgcp.domain.UsageInfo; +import org.jclouds.fujitsu.fgcp.domain.VSystem; +import org.jclouds.fujitsu.fgcp.domain.VSystemDescriptor; + /** * API relating to the virtual data center. * @@ -33,43 +41,43 @@ import java.util.concurrent.TimeUnit; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VirtualDCApi { - String createVirtualSystem(String descriptorId, String name); + String createVirtualSystem(String descriptorId, String name); - Set listVirtualSystems(); + Set listVirtualSystems(); - // according to the manual it takes a 'String diskImageId' but value seems - // to be ignored - Set listServerTypes(); + // according to the manual it takes a 'String diskImageId' but value seems + // to be ignored + Set listServerTypes(); - Set listDiskImages(); + Set listDiskImages(); - Set listDiskImages(String serverCategory, - String vsysDescriptorId); + Set listDiskImages(String serverCategory, + String vsysDescriptorId); - Map listPublicIPs(); + Map listPublicIPs(); - void addAddressRange(String pipFrom, String pipTo); + void addAddressRange(String pipFrom, String pipTo); - void createAddressPool(String pipFrom, String pipTo); + void createAddressPool(String pipFrom, String pipTo); - void deleteAddressRange(String pipFrom, String pipTo); + void deleteAddressRange(String pipFrom, String pipTo); - Set getAddressRange(); + Set getAddressRange(); - Set listVSYSDescriptor(); + Set listVSYSDescriptor(); - Set listVSYSDescriptor(String keyword, int estimateFrom, - int estimateTo); + Set listVSYSDescriptor(String keyword, int estimateFrom, + int estimateTo); - Set getEventLogs(boolean all); + Set getEventLogs(boolean all); - Set getEventLogs(); + Set getEventLogs(); - Set getInformation(boolean all); + Set getInformation(boolean all); - Set getInformation(); + Set getInformation(); - Set getSystemUsage(); + Set getSystemUsage(); - Set getSystemUsage(String systemIds); + Set getSystemUsage(String systemIds); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java index ec4bad9629..b9e85191ad 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java @@ -61,129 +61,129 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VirtualDCAsyncApi { - // @POST - @GET - @JAXBResponseParser - // @XMLResponseParser(VSYSCreateHandler.class) - @QueryParams(keys = "Action", values = "CreateVSYS") - @Transform(SingleElementResponseToElement.class) - // @PayloadParams(keys = "Action", values = "CreateVSYS") - // @Produces(MediaType.TEXT_XML) - // @MapBinder(BindParamsToXmlPayload.class) - // ListenableFuture - // createVirtualSystem(@PayloadParam("vsysDescriptorId") String - // vsysDescriptorId, @PayloadParam("vsysName") String vsysName); - ListenableFuture createVirtualSystem( - @QueryParam("vsysDescriptorId") String descriptorId, - @QueryParam("vsysName") String name); + // @POST + @GET + @JAXBResponseParser + // @XMLResponseParser(VSYSCreateHandler.class) + @QueryParams(keys = "Action", values = "CreateVSYS") + @Transform(SingleElementResponseToElement.class) + // @PayloadParams(keys = "Action", values = "CreateVSYS") + // @Produces(MediaType.TEXT_XML) + // @MapBinder(BindParamsToXmlPayload.class) + // ListenableFuture + // createVirtualSystem(@PayloadParam("vsysDescriptorId") String + // vsysDescriptorId, @PayloadParam("vsysName") String vsysName); + ListenableFuture createVirtualSystem( + @QueryParam("vsysDescriptorId") String descriptorId, + @QueryParam("vsysName") String name); - @GET - @JAXBResponseParser - // @XMLResponseParser(VSYSListHandler.class) - @QueryParams(keys = "Action", values = "ListVSYS") - ListenableFuture> listVirtualSystems(); + @GET + @JAXBResponseParser + // @XMLResponseParser(VSYSListHandler.class) + @QueryParams(keys = "Action", values = "ListVSYS") + ListenableFuture> listVirtualSystems(); - @GET - @JAXBResponseParser - // according to the manual it takes a 'String diskImageId' but value seems - // to be ignored - @QueryParams(keys = { "Action", "diskImageId" }, values = { - "ListServerType", "dummy" }) - // @XmlJavaTypeAdapter(SetOfServerTypesXMLAdapter.class) - // @XmlElement(type = ServerType.class) - ListenableFuture> listServerTypes(); + @GET + @JAXBResponseParser + // according to the manual it takes a 'String diskImageId' but value seems + // to be ignored + @QueryParams(keys = { "Action", "diskImageId" }, values = { + "ListServerType", "dummy" }) + // @XmlJavaTypeAdapter(SetOfServerTypesXMLAdapter.class) + // @XmlElement(type = ServerType.class) + ListenableFuture> listServerTypes(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListDiskImage") - ListenableFuture> listDiskImages(); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListDiskImage") + ListenableFuture> listDiskImages(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListDiskImage") - ListenableFuture> listDiskImages( - @QueryParam("serverCategory") String serverCategory, - @QueryParam("vsysDescriptorId") String vsysDescriptorId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListDiskImage") + ListenableFuture> listDiskImages( + @QueryParam("serverCategory") String serverCategory, + @QueryParam("vsysDescriptorId") String vsysDescriptorId); - /** - * - * @return - * @see VirtualSystemAsyncApi#listPublicIPs(String) - */ - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListPublicIP") - ListenableFuture> listPublicIPs(); + /** + * + * @return + * @see VirtualSystemAsyncApi#listPublicIPs(String) + */ + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListPublicIP") + ListenableFuture> listPublicIPs(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "AddAddressRange") - ListenableFuture addAddressRange( - @QueryParam("pipFrom") String pipFrom, - @QueryParam("pipTo") String pipTo); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "AddAddressRange") + ListenableFuture addAddressRange( + @QueryParam("pipFrom") String pipFrom, + @QueryParam("pipTo") String pipTo); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "CreateAddressPool") - ListenableFuture createAddressPool( - @QueryParam("pipFrom") String pipFrom, - @QueryParam("pipTo") String pipTo); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "CreateAddressPool") + ListenableFuture createAddressPool( + @QueryParam("pipFrom") String pipFrom, + @QueryParam("pipTo") String pipTo); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DeleteAddressRange") - ListenableFuture deleteAddressRange( - @QueryParam("pipFrom") String pipFrom, - @QueryParam("pipTo") String pipTo); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DeleteAddressRange") + ListenableFuture deleteAddressRange( + @QueryParam("pipFrom") String pipFrom, + @QueryParam("pipTo") String pipTo); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetAddressRange") - ListenableFuture> getAddressRange(); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetAddressRange") + ListenableFuture> getAddressRange(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListVSYSDescriptor") - ListenableFuture> listVSYSDescriptor(); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListVSYSDescriptor") + ListenableFuture> listVSYSDescriptor(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListVSYSDescriptor") - ListenableFuture> listVSYSDescriptor( - @QueryParam("keyword") String keyword, - @QueryParam("estimateFrom") int estimateFrom, - @QueryParam("estimateTo") int estimateTo); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListVSYSDescriptor") + ListenableFuture> listVSYSDescriptor( + @QueryParam("keyword") String keyword, + @QueryParam("estimateFrom") int estimateFrom, + @QueryParam("estimateTo") int estimateTo); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetEventLog") - ListenableFuture> getEventLogs(); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetEventLog") + ListenableFuture> getEventLogs(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetEventLog") - ListenableFuture> getEventLogs(@QueryParam("all") boolean all); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetEventLog") + ListenableFuture> getEventLogs(@QueryParam("all") boolean all); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetInformation") - ListenableFuture> getInformation(); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetInformation") + ListenableFuture> getInformation(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetInformation") - ListenableFuture> getInformation( - @QueryParam("all") boolean all); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetInformation") + ListenableFuture> getInformation( + @QueryParam("all") boolean all); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetSystemUsage") - ListenableFuture> getSystemUsage(); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetSystemUsage") + ListenableFuture> getSystemUsage(); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetSystemUsage") - ListenableFuture> getSystemUsage( - @QueryParam("systemIds") String systemIds); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetSystemUsage") + ListenableFuture> getSystemUsage( + @QueryParam("systemIds") String systemIds); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApi.java index 70be613e2b..e1dabaf021 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApi.java @@ -35,27 +35,27 @@ import org.jclouds.fujitsu.fgcp.domain.VServerWithDetails; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VirtualServerApi { - void start(String id); + void start(String id); - void stop(String id); + void stop(String id); - void stopForcefully(String id); + void stopForcefully(String id); - void destroy(String id); + void destroy(String id); - VServer get(String id); + VServer get(String id); - VServerWithDetails getDetails(String id); + VServerWithDetails getDetails(String id); - void update(String id, String name, String value); + void update(String id, String name, String value); - VServerStatus getStatus(String id); + VServerStatus getStatus(String id); - String getInitialPassword(String id); + String getInitialPassword(String id); - void attachDisk(String serverId, String diskId); + void attachDisk(String serverId, String diskId); - Set getPerformanceInformation(String id, String interval); + Set getPerformanceInformation(String id, String interval); - void registerAsPrivateDiskImage(String xml); + void registerAsPrivateDiskImage(String xml); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerAsyncApi.java index 5159c3bdce..15d85a2299 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualServerAsyncApi.java @@ -58,91 +58,91 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VirtualServerAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "StartVServer") - ListenableFuture start( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "StartVServer") + ListenableFuture start( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "StopVServer") - ListenableFuture stop( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "StopVServer") + ListenableFuture stop( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = { "Action", "force" }, values = { "StopVServer", "true" }) - ListenableFuture stopForcefully( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = { "Action", "force" }, values = { "StopVServer", "true" }) + ListenableFuture stopForcefully( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DestroyVServer") - ListenableFuture destroy( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DestroyVServer") + ListenableFuture destroy( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVServerAttributes") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVServerAttributes") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVServerConfiguration") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getDetails( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVServerConfiguration") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getDetails( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UpdateVServerAttribute") - ListenableFuture update( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id, - @QueryParam("attributeName") String name, - @QueryParam("attributeValue") String value); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UpdateVServerAttribute") + ListenableFuture update( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id, + @QueryParam("attributeName") String name, + @QueryParam("attributeValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVServerStatus") - // @Transform(StringToVServerStatus.class) - @Transform(SingleElementResponseToElement.class) - ListenableFuture getStatus( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVServerStatus") + // @Transform(StringToVServerStatus.class) + @Transform(SingleElementResponseToElement.class) + ListenableFuture getStatus( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVServerInitialPassword") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getInitialPassword( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVServerInitialPassword") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getInitialPassword( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "AttachVDisk") - ListenableFuture attachDisk( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String serverId, - @QueryParam("vdiskId") String diskId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "AttachVDisk") + ListenableFuture attachDisk( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String serverId, + @QueryParam("vdiskId") String diskId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetPerformanceInformation") - ListenableFuture> getPerformanceInformation( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("serverId") String id, - @QueryParam("interval") String interval); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetPerformanceInformation") + ListenableFuture> getPerformanceInformation( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("serverId") String id, + @QueryParam("interval") String interval); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetPerformanceInformation") - ListenableFuture> getPerformanceInformation( - @BinderParam(BindAlsoToSystemId.class) @QueryParam("serverId") String id, - @QueryParam("dataType") String dataType, - @QueryParam("interval") String interval); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetPerformanceInformation") + ListenableFuture> getPerformanceInformation( + @BinderParam(BindAlsoToSystemId.class) @QueryParam("serverId") String id, + @QueryParam("dataType") String dataType, + @QueryParam("interval") String interval); - @POST - @JAXBResponseParser - @QueryParams(keys = "Action", values = "RegisterPrivateDiskImage") - ListenableFuture registerAsPrivateDiskImage(String xml); + @POST + @JAXBResponseParser + @QueryParams(keys = "Action", values = "RegisterPrivateDiskImage") + ListenableFuture registerAsPrivateDiskImage(String xml); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApi.java index 5ec70204ff..3bc12cda1b 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApi.java @@ -38,37 +38,37 @@ import org.jclouds.fujitsu.fgcp.domain.VSystemWithDetails; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VirtualSystemApi { - void destroy(String id); + void destroy(String id); - VSystemStatus getStatus(String id); + VSystemStatus getStatus(String id); - VSystem get(String id); + VSystem get(String id); - VSystemWithDetails getDetails(String id); + VSystemWithDetails getDetails(String id); - void update(String id, String name, String value); + void update(String id, String name, String value); - void updateConfiguration(String id, String name, String value); + void updateConfiguration(String id, String name, String value); - String createServer(String name, String type, String diskImageId, - String networkId); + String createServer(String name, String type, String diskImageId, + String networkId); - Set listServers(String id); + Set listServers(String id); - String createBuiltinServer(String name, String networkId); + String createBuiltinServer(String name, String networkId); - Set listBuiltinServers(String id, String type); + Set listBuiltinServers(String id, String type); - String createDisk(String id, String name, int size); + String createDisk(String id, String name, int size); - Set listDisks(String id); + Set listDisks(String id); - void allocatePublicIP(String id); + void allocatePublicIP(String id); - Set listPublicIPs(String id); + Set listPublicIPs(String id); - String standByConsole(String id, String networkId); + String standByConsole(String id, String networkId); - void registerAsPrivateVSYSDescriptor(String id, - String vsysDescriptorXMLFilePath); + void registerAsPrivateVSYSDescriptor(String id, + String vsysDescriptorXMLFilePath); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemAsyncApi.java index c9d4d20b71..12a02753b5 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemAsyncApi.java @@ -60,115 +60,115 @@ import com.google.common.util.concurrent.ListenableFuture; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface VirtualSystemAsyncApi { - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "DestroyVSYS") - ListenableFuture destroy(@QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "DestroyVSYS") + ListenableFuture destroy(@QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVSYSStatus") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getStatus(@QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVSYSStatus") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getStatus(@QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVSYSAttributes") - @Transform(SingleElementResponseToElement.class) - ListenableFuture get(@QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVSYSAttributes") + @Transform(SingleElementResponseToElement.class) + ListenableFuture get(@QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "GetVSYSConfiguration") - @Transform(SingleElementResponseToElement.class) - ListenableFuture getDetails( - @QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "GetVSYSConfiguration") + @Transform(SingleElementResponseToElement.class) + ListenableFuture getDetails( + @QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UpdateVSYSAttribute") - ListenableFuture update(@QueryParam("vsysId") String id, - @QueryParam("attributeName") String name, - @QueryParam("attributeValue") String value); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UpdateVSYSAttribute") + ListenableFuture update(@QueryParam("vsysId") String id, + @QueryParam("attributeName") String name, + @QueryParam("attributeValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "UpdateVSYSConfiguration") - ListenableFuture updateConfiguration(@QueryParam("vsysId") String id, - @QueryParam("configurationName") String name, - @QueryParam("configurationValue") String value); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "UpdateVSYSConfiguration") + ListenableFuture updateConfiguration(@QueryParam("vsysId") String id, + @QueryParam("configurationName") String name, + @QueryParam("configurationValue") String value); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "CreateVServer") - @Transform(SingleElementResponseToElement.class) - ListenableFuture createServer( - @QueryParam("vserverName") String name, - @QueryParam("vserverType") String type, - @QueryParam("diskImageId") String diskImageId, - @BinderParam(BindAlsoToSystemId.class) @QueryParam("networkId") String networkId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "CreateVServer") + @Transform(SingleElementResponseToElement.class) + ListenableFuture createServer( + @QueryParam("vserverName") String name, + @QueryParam("vserverType") String type, + @QueryParam("diskImageId") String diskImageId, + @BinderParam(BindAlsoToSystemId.class) @QueryParam("networkId") String networkId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListVServer") - ListenableFuture> listServers(@QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListVServer") + ListenableFuture> listServers(@QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "CreateVDisk") - @Transform(SingleElementResponseToElement.class) - ListenableFuture createDisk(@QueryParam("vsysId") String id, - @QueryParam("vdiskName") String name, @QueryParam("size") int size); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "CreateVDisk") + @Transform(SingleElementResponseToElement.class) + ListenableFuture createDisk(@QueryParam("vsysId") String id, + @QueryParam("vdiskName") String name, @QueryParam("size") int size); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListVDisk") - ListenableFuture> listDisks(@QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListVDisk") + ListenableFuture> listDisks(@QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "AllocatePublicIP") - ListenableFuture allocatePublicIP(@QueryParam("vsysId") String id); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "AllocatePublicIP") + ListenableFuture allocatePublicIP(@QueryParam("vsysId") String id); - /** - * - * @return - * @see VirtualDCAsyncApi#listPublicIPs() - */ - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListPublicIP") - @Transform(SingleElementResponseToElement.class) - ListenableFuture> listPublicIPs( - @QueryParam("vsysId") String id); + /** + * + * @return + * @see VirtualDCAsyncApi#listPublicIPs() + */ + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListPublicIP") + @Transform(SingleElementResponseToElement.class) + ListenableFuture> listPublicIPs( + @QueryParam("vsysId") String id); - @GET - @JAXBResponseParser - // SLB is the only built-in server that can currently be created so - // hard-code it - @QueryParams(keys = { "Action", "efmType" }, values = { "CreateEFM", "SLB" }) - @Transform(SingleElementResponseToElement.class) - ListenableFuture createBuiltinServer( - @QueryParam("efmName") String name, - @BinderParam(BindAlsoToSystemId.class) @QueryParam("networkId") String networkId); + @GET + @JAXBResponseParser + // SLB is the only built-in server that can currently be created so + // hard-code it + @QueryParams(keys = { "Action", "efmType" }, values = { "CreateEFM", "SLB" }) + @Transform(SingleElementResponseToElement.class) + ListenableFuture createBuiltinServer( + @QueryParam("efmName") String name, + @BinderParam(BindAlsoToSystemId.class) @QueryParam("networkId") String networkId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "ListEFM") - ListenableFuture> listBuiltinServers( - @QueryParam("vsysId") String id, @QueryParam("efmType") String type); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "ListEFM") + ListenableFuture> listBuiltinServers( + @QueryParam("vsysId") String id, @QueryParam("efmType") String type); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "StandByConsole") - @Transform(SingleElementResponseToElement.class) - ListenableFuture standByConsole(@QueryParam("vsysId") String id, - @QueryParam("networkId") String networkId); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "StandByConsole") + @Transform(SingleElementResponseToElement.class) + ListenableFuture standByConsole(@QueryParam("vsysId") String id, + @QueryParam("networkId") String networkId); - @GET - @JAXBResponseParser - @QueryParams(keys = "Action", values = "RegisterPrivateVSYSDescriptor") - ListenableFuture registerAsPrivateVSYSDescriptor( - @QueryParam("vsysId") String id, - @QueryParam("vsysDescriptorXMLFilePath") String vsysDescriptorXMLFilePath); + @GET + @JAXBResponseParser + @QueryParams(keys = "Action", values = "RegisterPrivateVSYSDescriptor") + ListenableFuture registerAsPrivateVSYSDescriptor( + @QueryParam("vsysId") String id, + @QueryParam("vsysDescriptorXMLFilePath") String vsysDescriptorXMLFilePath); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/BindParamsToXmlPayload.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/BindParamsToXmlPayload.java index 0783787bd0..153207338d 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/BindParamsToXmlPayload.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/BindParamsToXmlPayload.java @@ -18,18 +18,20 @@ */ package org.jclouds.fujitsu.fgcp.xml; -import com.google.common.base.Strings; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + import org.jclouds.fujitsu.fgcp.reference.RequestParameters; import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToStringPayload; -import javax.ws.rs.core.MediaType; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Map; - -import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Strings; /** * Not currently used but leaving for reference when implementing multipart POST @@ -38,59 +40,60 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Dies Koper */ public class BindParamsToXmlPayload extends BindToStringPayload implements - MapBinder { + MapBinder { - @Override - public R bindToRequest(R request, - Map mapParams) { - String action = checkNotNull( - mapParams.remove(RequestParameters.ACTION), - RequestParameters.ACTION).toString(); - String version = Strings.nullToEmpty((String) mapParams - .remove(RequestParameters.VERSION)); + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, + Map mapParams) { + String action = checkNotNull( + mapParams.remove(RequestParameters.ACTION), + RequestParameters.ACTION).toString(); + String version = Strings.nullToEmpty((String) mapParams + .remove(RequestParameters.VERSION)); - StringBuilder xml = new StringBuilder(); - xml.append("\r\n"); - xml.append("\r\n"); - xml.append(" " + action + "\r\n"); + StringBuilder xml = new StringBuilder(); + xml.append("\r\n"); + xml.append("\r\n"); + xml.append(" " + action + "\r\n"); - for (Map.Entry entry : mapParams.entrySet()) { - String key = entry.getKey(); - xml.append(" <" + key + ">" + checkNotNull(mapParams.get(key)) - + "\r\n"); - } + for (Map.Entry entry : mapParams.entrySet()) { + String key = entry.getKey(); + xml.append(" <" + key + ">" + checkNotNull(mapParams.get(key)) + + "\r\n"); + } - xml.append(" " + version + "\r\n"); - xml.append(" \r\n"); // value inserted in - // RequestAuthenticator#filter - xml.append(" \r\n"); // value inserted in - // RequestAuthenticator#filter - xml.append(" \r\n"); // value inserted in - // RequestAuthenticator#filter - xml.append(""); + xml.append(" " + version + "\r\n"); + xml.append(" \r\n"); // value inserted in + // RequestAuthenticator#filter + xml.append(" \r\n"); // value inserted in + // RequestAuthenticator#filter + xml.append(" \r\n"); // value inserted in + // RequestAuthenticator#filter + xml.append(""); - request = super.bindToRequest(request, xml); - request.getPayload().getContentMetadata() - .setContentType(MediaType.TEXT_XML); + request = super.bindToRequest(request, xml); + request.getPayload().getContentMetadata() + .setContentType(MediaType.TEXT_XML); - // remove version query param if set as it was moved to the xml body - URI uri = request.getEndpoint(); - URI uriWithoutQueryParams; - try { - uriWithoutQueryParams = new URI(uri.getScheme(), uri.getUserInfo(), - uri.getHost(), uri.getPort(), uri.getPath(), null, - uri.getFragment()); - } catch (URISyntaxException e) { - // should never happen as we're copying the components from a URI - uriWithoutQueryParams = uri; - } + // remove version query param if set as it was moved to the xml body + URI uri = request.getEndpoint(); + URI uriWithoutQueryParams; + try { + uriWithoutQueryParams = new URI(uri.getScheme(), uri.getUserInfo(), + uri.getHost(), uri.getPort(), uri.getPath(), null, + uri.getFragment()); + } catch (URISyntaxException e) { + // should never happen as we're copying the components from a URI + uriWithoutQueryParams = uri; + } - return (R) request.toBuilder().endpoint(uriWithoutQueryParams).build(); - } + return (R) request.toBuilder().endpoint(uriWithoutQueryParams).build(); + } - @Override - public R bindToRequest(R request, Object toBind) { - throw new IllegalArgumentException( - "BindParamsToXmlPayload needs bind parameters"); - } + @Override + public R bindToRequest(R request, Object toBind) { + throw new IllegalArgumentException( + "BindParamsToXmlPayload needs bind parameters"); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/FGCPJAXBParser.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/FGCPJAXBParser.java index b5349ab859..7e8dfff2f7 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/FGCPJAXBParser.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/FGCPJAXBParser.java @@ -40,49 +40,49 @@ import org.jclouds.xml.XMLParser; */ @Singleton public class FGCPJAXBParser implements XMLParser { - JAXBContext context; + JAXBContext context; - public FGCPJAXBParser() throws JAXBException { - context = JAXBContext.newInstance(VServerWithDetails.class.getPackage() - .getName() - + ":" - + ListServerTypeResponse.class.getPackage().getName(), - VServerWithDetails.class.getClassLoader()); - } + public FGCPJAXBParser() throws JAXBException { + context = JAXBContext.newInstance(VServerWithDetails.class.getPackage() + .getName() + + ":" + + ListServerTypeResponse.class.getPackage().getName(), + VServerWithDetails.class.getClassLoader()); + } - @Override - public String toXML(final Object src) throws IOException { - return toXML(src, src.getClass()); - } + @Override + public String toXML(final Object src) throws IOException { + return toXML(src, src.getClass()); + } - @Override - public String toXML(final Object src, final Class type) - throws IOException { - throw new UnsupportedOperationException( - "only marshaling from XML is implemented"); - } + @Override + public String toXML(final Object src, final Class type) + throws IOException { + throw new UnsupportedOperationException( + "only marshaling from XML is implemented"); + } - @SuppressWarnings("unchecked") - @Override - public T fromXML(final String xml, final Class type) - throws IOException { - T response = null; - try { - StringReader reader = new StringReader(xml); + @SuppressWarnings("unchecked") + @Override + public T fromXML(final String xml, final Class type) + throws IOException { + T response = null; + try { + StringReader reader = new StringReader(xml); - Unmarshaller unmarshaller = context.createUnmarshaller(); + Unmarshaller unmarshaller = context.createUnmarshaller(); - response = (T) unmarshaller.unmarshal(reader); - } catch (Exception ex) { - throw new IOException("Could not unmarshal document", ex); - } + response = (T) unmarshaller.unmarshal(reader); + } catch (Exception ex) { + throw new IOException("Could not unmarshal document", ex); + } - if (((StatusQuerable) response).isError()) { - throw new HttpException( - ((StatusQuerable) response).getResponseMessage()); - } + if (((StatusQuerable) response).isError()) { + throw new HttpException( + ((StatusQuerable) response).getResponseMessage()); + } - return response; - } + return response; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateEFMResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateEFMResponse.java index 237fde513f..8c3fdb9757 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateEFMResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateEFMResponse.java @@ -28,17 +28,17 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "CreateEFMResponse") public class CreateEFMResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private String efmId; + SingleElementResponse { + @XmlElement(required = true) + private String efmId; - @Override - public String toString() { - return getElement(); - } + @Override + public String toString() { + return getElement(); + } - @Override - public String getElement() { - return efmId; - } + @Override + public String getElement() { + return efmId; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVDiskResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVDiskResponse.java index b31a637f9d..6bf1a1f555 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVDiskResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVDiskResponse.java @@ -28,17 +28,17 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "CreateVDiskResponse") public class CreateVDiskResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private String vdiskId; + SingleElementResponse { + @XmlElement(required = true) + private String vdiskId; - @Override - public String toString() { - return getElement(); - } + @Override + public String toString() { + return getElement(); + } - @Override - public String getElement() { - return vdiskId; - } + @Override + public String getElement() { + return vdiskId; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVSYSResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVSYSResponse.java index a18a3fada7..61dd417633 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVSYSResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVSYSResponse.java @@ -28,17 +28,17 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "CreateVSYSResponse") public class CreateVSYSResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private String vsysId; + SingleElementResponse { + @XmlElement(required = true) + private String vsysId; - @Override - public String toString() { - return getElement(); - } + @Override + public String toString() { + return getElement(); + } - @Override - public String getElement() { - return vsysId; - } + @Override + public String getElement() { + return vsysId; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVServerResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVServerResponse.java index 6170ee407a..7d7ddcd88b 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVServerResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/CreateVServerResponse.java @@ -28,17 +28,17 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "CreateVServerResponse") public class CreateVServerResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private String vserverId; + SingleElementResponse { + @XmlElement(required = true) + private String vserverId; - @Override - public String toString() { - return getElement(); - } + @Override + public String toString() { + return getElement(); + } - @Override - public String getElement() { - return vserverId; - } + @Override + public String getElement() { + return vserverId; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetAddressRangeResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetAddressRangeResponse.java index 9ea55713ac..799b3df445 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetAddressRangeResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetAddressRangeResponse.java @@ -37,14 +37,14 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "GetAddressRangeResponse") public class GetAddressRangeResponse extends - SetWithStatusResponse { - @XmlElementWrapper(name = "addressranges") - @XmlElement(name = "addressrange") - private Set ranges = new LinkedHashSet(); + SetWithStatusResponse { + @XmlElementWrapper(name = "addressranges") + @XmlElement(name = "addressrange") + private Set ranges = new LinkedHashSet(); - @Override - protected Set delegate() { - return ranges == null ? ImmutableSet. of() : Collections - .unmodifiableSet(ranges); - } + @Override + protected Set delegate() { + return ranges == null ? ImmutableSet. of() : Collections + .unmodifiableSet(ranges); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetDiskImageAttributesResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetDiskImageAttributesResponse.java index ccef26f210..a6c59cfecf 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetDiskImageAttributesResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetDiskImageAttributesResponse.java @@ -18,11 +18,11 @@ */ package org.jclouds.fujitsu.fgcp.xml.internal; -import org.jclouds.fujitsu.fgcp.domain.DiskImage; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.fujitsu.fgcp.domain.DiskImage; + /** * Wrapper for GetDiskImageAttributesResponse. * @@ -30,17 +30,17 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "GetDiskImageAttributesResponse") public class GetDiskImageAttributesResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(name = "diskimage") - private DiskImage diskImage; + SingleElementResponse { + @XmlElement(name = "diskimage") + private DiskImage diskImage; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public DiskImage getElement() { - return diskImage; - } + @Override + public DiskImage getElement() { + return diskImage; + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMAttributesResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMAttributesResponse.java index 9764a9e516..939d63e4a0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMAttributesResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMAttributesResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.BuiltinServer; */ @XmlRootElement(name = "GetEFMAttributesResponse") public class GetEFMAttributesResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private BuiltinServer efm; + SingleElementResponse { + @XmlElement(required = true) + private BuiltinServer efm; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return efm; - } + @Override + public Object getElement() { + return efm; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMStatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMStatusResponse.java index 34fa4c6204..a243c80459 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMStatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEFMStatusResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.BuiltinServerStatus; */ @XmlRootElement(name = "GetEFMStatusResponse") public class GetEFMStatusResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private BuiltinServerStatus efmStatus; + SingleElementResponse { + @XmlElement(required = true) + private BuiltinServerStatus efmStatus; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return efmStatus; - } + @Override + public Object getElement() { + return efmStatus; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEventLogResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEventLogResponse.java index c9f35d25e9..988d79dc63 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEventLogResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetEventLogResponse.java @@ -37,13 +37,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "GetEventLogResponse") public class GetEventLogResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "eventlogs") - @XmlElement(name = "eventlog") - private Set logs = new LinkedHashSet(); + @XmlElementWrapper(name = "eventlogs") + @XmlElement(name = "eventlog") + private Set logs = new LinkedHashSet(); - @Override - protected Set delegate() { - return logs == null ? ImmutableSet. of() : Collections - .unmodifiableSet(logs); - } + @Override + protected Set delegate() { + return logs == null ? ImmutableSet. of() : Collections + .unmodifiableSet(logs); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPerformanceInformationResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPerformanceInformationResponse.java index e8c92909d1..2c3b5f5b09 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPerformanceInformationResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPerformanceInformationResponse.java @@ -37,14 +37,14 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "GetPerformanceInformationResponse") public class GetPerformanceInformationResponse extends - SetWithStatusResponse { - @XmlElementWrapper(name = "performanceinfos") - @XmlElement(name = "performanceinfo") - private Set stats = new LinkedHashSet(); + SetWithStatusResponse { + @XmlElementWrapper(name = "performanceinfos") + @XmlElement(name = "performanceinfo") + private Set stats = new LinkedHashSet(); - @Override - protected Set delegate() { - return stats == null ? ImmutableSet. of() - : Collections.unmodifiableSet(stats); - } + @Override + protected Set delegate() { + return stats == null ? ImmutableSet. of() + : Collections.unmodifiableSet(stats); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPAttributesResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPAttributesResponse.java index d0a0488819..cb4f958b62 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPAttributesResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPAttributesResponse.java @@ -26,7 +26,6 @@ import javax.xml.bind.annotation.XmlRootElement; import org.jclouds.fujitsu.fgcp.domain.PublicIP; - import com.google.common.collect.Iterables; /** @@ -36,18 +35,18 @@ import com.google.common.collect.Iterables; */ @XmlRootElement(name = "GetPublicIPAttributesResponse") public class GetPublicIPAttributesResponse extends StatusResponse implements - SingleElementResponse { - @XmlElementWrapper(name = "publicips") - @XmlElement(name = "publicip") - private Set publicIPs; + SingleElementResponse { + @XmlElementWrapper(name = "publicips") + @XmlElement(name = "publicip") + private Set publicIPs; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return Iterables.getOnlyElement(publicIPs); - } + @Override + public Object getElement() { + return Iterables.getOnlyElement(publicIPs); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPStatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPStatusResponse.java index 29e5ce91f3..69b4fc26db 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPStatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetPublicIPStatusResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.PublicIPStatus; */ @XmlRootElement(name = "GetPublicIPStatusResponse") public class GetPublicIPStatusResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private PublicIPStatus publicipStatus; + SingleElementResponse { + @XmlElement(required = true) + private PublicIPStatus publicipStatus; - @Override - public String toString() { - return publicipStatus.toString(); - } + @Override + public String toString() { + return publicipStatus.toString(); + } - @Override - public Object getElement() { - return publicipStatus; - } + @Override + public Object getElement() { + return publicipStatus; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVDiskAttributesResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVDiskAttributesResponse.java index 0634f00c22..cc486d1213 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVDiskAttributesResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVDiskAttributesResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VDisk; */ @XmlRootElement(name = "GetVDiskAttributesResponse") public class GetVDiskAttributesResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private VDisk vdisk; + SingleElementResponse { + @XmlElement(required = true) + private VDisk vdisk; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return vdisk; - } + @Override + public Object getElement() { + return vdisk; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSAttributesResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSAttributesResponse.java index 0833a4df0e..bd2ff354ac 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSAttributesResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSAttributesResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VSystem; */ @XmlRootElement(name = "GetVSYSAttributesResponse") public class GetVSYSAttributesResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(name = "vsys") - private VSystem system; + SingleElementResponse { + @XmlElement(name = "vsys") + private VSystem system; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return system; - } + @Override + public Object getElement() { + return system; + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSConfigurationResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSConfigurationResponse.java index c593a3bb4b..977a177ae8 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSConfigurationResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSConfigurationResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VSystemWithDetails; */ @XmlRootElement(name = "GetVSYSConfigurationResponse") public class GetVSYSConfigurationResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(name = "vsys") - private VSystemWithDetails system; + SingleElementResponse { + @XmlElement(name = "vsys") + private VSystemWithDetails system; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return system; - } + @Override + public Object getElement() { + return system; + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSDescriptorConfigurationResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSDescriptorConfigurationResponse.java index af21f20658..75e7a5ea36 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSDescriptorConfigurationResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSDescriptorConfigurationResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VSystemDescriptor; */ @XmlRootElement(name = "GetVSYSDescriptorConfigurationResponse") public class GetVSYSDescriptorConfigurationResponse extends StatusResponse - implements SingleElementResponse { - @XmlElement - private VSystemDescriptor vsysdescriptor; + implements SingleElementResponse { + @XmlElement + private VSystemDescriptor vsysdescriptor; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return vsysdescriptor; - } + @Override + public Object getElement() { + return vsysdescriptor; + } } \ No newline at end of file diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSStatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSStatusResponse.java index 08d1dc97d1..074ea0bab6 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSStatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVSYSStatusResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VSystemStatus; */ @XmlRootElement(name = "GetVSYSStatusResponse") public class GetVSYSStatusResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private VSystemStatus vsysStatus; + SingleElementResponse { + @XmlElement(required = true) + private VSystemStatus vsysStatus; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return vsysStatus; - } + @Override + public Object getElement() { + return vsysStatus; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerAttributesResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerAttributesResponse.java index 404cceca87..5f9637c98b 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerAttributesResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerAttributesResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VServer; */ @XmlRootElement(name = "GetVServerAttributesResponse") public class GetVServerAttributesResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private VServer vserver; + SingleElementResponse { + @XmlElement(required = true) + private VServer vserver; - @Override - public String toString() { - return vserver.toString(); - } + @Override + public String toString() { + return vserver.toString(); + } - @Override - public Object getElement() { - return vserver; - } + @Override + public Object getElement() { + return vserver; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerConfigurationResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerConfigurationResponse.java index f69daa5f12..cebe6ceda1 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerConfigurationResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerConfigurationResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VServerWithDetails; */ @XmlRootElement(name = "GetVServerConfigurationResponse") public class GetVServerConfigurationResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private VServerWithDetails vserver; + SingleElementResponse { + @XmlElement(required = true) + private VServerWithDetails vserver; - @Override - public String toString() { - return vserver.toString(); - } + @Override + public String toString() { + return vserver.toString(); + } - @Override - public Object getElement() { - return vserver; - } + @Override + public Object getElement() { + return vserver; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerInitialPasswordResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerInitialPasswordResponse.java index f5a1a162f5..39f6ee3797 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerInitialPasswordResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerInitialPasswordResponse.java @@ -28,12 +28,12 @@ import javax.xml.bind.annotation.XmlRootElement; */ @XmlRootElement(name = "GetVServerInitialPasswordResponse") public class GetVServerInitialPasswordResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private String initialPassword; + SingleElementResponse { + @XmlElement(required = true) + private String initialPassword; - @Override - public Object getElement() { - return initialPassword; - } + @Override + public Object getElement() { + return initialPassword; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerStatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerStatusResponse.java index ea22965525..657c5b6e8f 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerStatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/GetVServerStatusResponse.java @@ -30,17 +30,17 @@ import org.jclouds.fujitsu.fgcp.domain.VServerStatus; */ @XmlRootElement(name = "GetVServerStatusResponse") public class GetVServerStatusResponse extends StatusResponse implements - SingleElementResponse { - @XmlElement(required = true) - private VServerStatus vserverStatus; + SingleElementResponse { + @XmlElement(required = true) + private VServerStatus vserverStatus; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - public Object getElement() { - return vserverStatus; - } + @Override + public Object getElement() { + return vserverStatus; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListDiskImageResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListDiskImageResponse.java index 5e19ad697b..339b472b9d 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListDiskImageResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListDiskImageResponse.java @@ -37,13 +37,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListDiskImageResponse") public class ListDiskImageResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "diskimages") - @XmlElement(name = "diskimage") - private Set diskImages = new LinkedHashSet(); + @XmlElementWrapper(name = "diskimages") + @XmlElement(name = "diskimage") + private Set diskImages = new LinkedHashSet(); - @Override - protected Set delegate() { - return diskImages == null ? ImmutableSet. of() : Collections - .unmodifiableSet(diskImages); - } + @Override + protected Set delegate() { + return diskImages == null ? ImmutableSet. of() : Collections + .unmodifiableSet(diskImages); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMBackupResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMBackupResponse.java index a9026252a3..2acbfd4141 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMBackupResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMBackupResponse.java @@ -37,14 +37,14 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListEFMBackupResponse") public class ListEFMBackupResponse extends - SetWithStatusResponse { - @XmlElementWrapper(name = "backups") - @XmlElement(name = "backup") - private Set backup = new LinkedHashSet(); + SetWithStatusResponse { + @XmlElementWrapper(name = "backups") + @XmlElement(name = "backup") + private Set backup = new LinkedHashSet(); - @Override - protected Set delegate() { - return backup == null ? ImmutableSet. of() - : Collections.unmodifiableSet(backup); - } + @Override + protected Set delegate() { + return backup == null ? ImmutableSet. of() + : Collections.unmodifiableSet(backup); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMResponse.java index 9ebbb1a613..cffa13f681 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListEFMResponse.java @@ -37,13 +37,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListEFMResponse") public class ListEFMResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "efms") - @XmlElement(name = "efm") - private Set efm = new LinkedHashSet(); + @XmlElementWrapper(name = "efms") + @XmlElement(name = "efm") + private Set efm = new LinkedHashSet(); - @Override - protected Set delegate() { - return efm == null ? ImmutableSet. of() : Collections - .unmodifiableSet(efm); - } + @Override + protected Set delegate() { + return efm == null ? ImmutableSet. of() : Collections + .unmodifiableSet(efm); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListPublicIPResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListPublicIPResponse.java index 2b6c1a1bf5..6ddfa79126 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListPublicIPResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListPublicIPResponse.java @@ -39,32 +39,32 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListPublicIPResponse") public class ListPublicIPResponse extends - MapWithStatusResponse implements - SingleElementResponse { - @XmlElementWrapper(name = "publicips") - @XmlElement(name = "publicip") - private Set ips; + MapWithStatusResponse implements + SingleElementResponse { + @XmlElementWrapper(name = "publicips") + @XmlElement(name = "publicip") + private Set ips; - @Override - public String toString() { - return getElement().toString(); - } + @Override + public String toString() { + return getElement().toString(); + } - @Override - protected Map delegate() { - Builder returnVal = ImmutableMap.builder(); - if (ips != null) { + @Override + protected Map delegate() { + Builder returnVal = ImmutableMap.builder(); + if (ips != null) { - for (PublicIPWithSystemId ip : ips) { - returnVal.put(ip, ip.getVsysId()); - } - } - return returnVal.build(); - } + for (PublicIPWithSystemId ip : ips) { + returnVal.put(ip, ip.getVsysId()); + } + } + return returnVal.build(); + } - @Override - public Set getElement() { - return ips == null ? ImmutableSet. of() : Collections - .unmodifiableSet(ips); - } + @Override + public Set getElement() { + return ips == null ? ImmutableSet. of() : Collections + .unmodifiableSet(ips); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListServerTypeResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListServerTypeResponse.java index 6d1e49e2ee..c10b0c8120 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListServerTypeResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListServerTypeResponse.java @@ -36,13 +36,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListServerTypeResponse") public class ListServerTypeResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "servertypes") - @XmlElement(name = "servertype") - private Set serverTypes; + @XmlElementWrapper(name = "servertypes") + @XmlElement(name = "servertype") + private Set serverTypes; - @Override - protected Set delegate() { - return serverTypes == null ? ImmutableSet. of() - : Collections.unmodifiableSet(serverTypes); - } + @Override + protected Set delegate() { + return serverTypes == null ? ImmutableSet. of() + : Collections.unmodifiableSet(serverTypes); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVDiskResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVDiskResponse.java index 0489a93042..3be8d5d6ea 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVDiskResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVDiskResponse.java @@ -37,13 +37,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListVDiskResponse") public class ListVDiskResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "vdisks") - @XmlElement(name = "vdisk") - private Set disks = new LinkedHashSet(); + @XmlElementWrapper(name = "vdisks") + @XmlElement(name = "vdisk") + private Set disks = new LinkedHashSet(); - @Override - protected Set delegate() { - return disks == null ? ImmutableSet. of() : Collections - .unmodifiableSet(disks); - } + @Override + protected Set delegate() { + return disks == null ? ImmutableSet. of() : Collections + .unmodifiableSet(disks); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVSYSResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVSYSResponse.java index 90826f63da..0cce1b252e 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVSYSResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVSYSResponse.java @@ -37,13 +37,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListVSYSResponse") public class ListVSYSResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "vsyss") - @XmlElement(name = "vsys") - private Set systems = new LinkedHashSet(); + @XmlElementWrapper(name = "vsyss") + @XmlElement(name = "vsys") + private Set systems = new LinkedHashSet(); - @Override - protected Set delegate() { - return systems == null ? ImmutableSet. of() : Collections - .unmodifiableSet(systems); - } + @Override + protected Set delegate() { + return systems == null ? ImmutableSet. of() : Collections + .unmodifiableSet(systems); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVServerResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVServerResponse.java index 802a779ba1..2d8dc4e161 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVServerResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/ListVServerResponse.java @@ -37,13 +37,13 @@ import com.google.common.collect.ImmutableSet; */ @XmlRootElement(name = "ListVServerResponse") public class ListVServerResponse extends SetWithStatusResponse { - @XmlElementWrapper(name = "vservers") - @XmlElement(name = "vserver") - private Set servers = new LinkedHashSet(); + @XmlElementWrapper(name = "vservers") + @XmlElement(name = "vserver") + private Set servers = new LinkedHashSet(); - @Override - protected Set delegate() { - return servers == null ? ImmutableSet. of() : Collections - .unmodifiableSet(servers); - } + @Override + protected Set delegate() { + return servers == null ? ImmutableSet. of() : Collections + .unmodifiableSet(servers); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/MapWithStatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/MapWithStatusResponse.java index ffc54303a4..e0f841ae87 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/MapWithStatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/MapWithStatusResponse.java @@ -18,10 +18,10 @@ */ package org.jclouds.fujitsu.fgcp.xml.internal; -import com.google.common.collect.ForwardingMap; - import javax.xml.bind.annotation.XmlElement; +import com.google.common.collect.ForwardingMap; + /** * Special base class extending (forwardable) Map with fields for the elements * that FGCP XML responses specify. @@ -32,27 +32,27 @@ import javax.xml.bind.annotation.XmlElement; * @author Dies Koper */ public abstract class MapWithStatusResponse extends ForwardingMap - implements StatusQuerable { - @XmlElement(required = true) - private String responseMessage; - @XmlElement(required = true) - private String responseStatus; + implements StatusQuerable { + @XmlElement(required = true) + private String responseMessage; + @XmlElement(required = true) + private String responseStatus; - public String getResponseMessage() { - return responseMessage; - } + public String getResponseMessage() { + return responseMessage; + } - public String getResponseStatus() { - return responseStatus; - } + public String getResponseStatus() { + return responseStatus; + } - public boolean isError() { - return !"SUCCESS".equals(responseStatus); - } + public boolean isError() { + return !"SUCCESS".equals(responseStatus); + } - @Override - public String toString() { - return "StatusResponse{" + "responseMessage='" + responseMessage + '\'' - + ", responseStatus='" + responseStatus + '\'' + '}'; - } + @Override + public String toString() { + return "StatusResponse{" + "responseMessage='" + responseMessage + '\'' + + ", responseStatus='" + responseStatus + '\'' + '}'; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/PublicIPWithSystemId.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/PublicIPWithSystemId.java index fd9f18cb30..6995541d50 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/PublicIPWithSystemId.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/PublicIPWithSystemId.java @@ -29,15 +29,15 @@ import org.jclouds.fujitsu.fgcp.domain.PublicIP; */ @XmlRootElement(name = "publicip") public class PublicIPWithSystemId extends PublicIP { - private String vsysId; + private String vsysId; - public String getVsysId() { - return vsysId; - } + public String getVsysId() { + return vsysId; + } - @Override - public String toString() { - return "PublicIP{" + "address='" + address + '\'' + ", IP version='" - + version + '\'' + ", vsysId='" + vsysId + '\'' + '}'; - } + @Override + public String toString() { + return "PublicIP{" + "address='" + address + '\'' + ", IP version='" + + version + '\'' + ", vsysId='" + vsysId + '\'' + '}'; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SetWithStatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SetWithStatusResponse.java index bb7158f10b..6ee4e7c8f0 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SetWithStatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SetWithStatusResponse.java @@ -18,10 +18,10 @@ */ package org.jclouds.fujitsu.fgcp.xml.internal; -import com.google.common.collect.ForwardingSet; - import javax.xml.bind.annotation.XmlElement; +import com.google.common.collect.ForwardingSet; + /** * Special base class extending (forwardable) Set with fields for the elements * that FGCP XML responses specify. @@ -32,27 +32,27 @@ import javax.xml.bind.annotation.XmlElement; * @author Dies Koper */ public abstract class SetWithStatusResponse extends ForwardingSet - implements StatusQuerable { - @XmlElement(required = true) - private String responseMessage; - @XmlElement(required = true) - private String responseStatus; + implements StatusQuerable { + @XmlElement(required = true) + private String responseMessage; + @XmlElement(required = true) + private String responseStatus; - public String getResponseMessage() { - return responseMessage; - } + public String getResponseMessage() { + return responseMessage; + } - public String getResponseStatus() { - return responseStatus; - } + public String getResponseStatus() { + return responseStatus; + } - public boolean isError() { - return !"SUCCESS".equals(responseStatus); - } + public boolean isError() { + return !"SUCCESS".equals(responseStatus); + } - @Override - public String toString() { - return delegate().toString(); - } + @Override + public String toString() { + return delegate().toString(); + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SingleElementResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SingleElementResponse.java index 759586fe98..4ced6da144 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SingleElementResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/SingleElementResponse.java @@ -25,5 +25,5 @@ package org.jclouds.fujitsu.fgcp.xml.internal; */ public interface SingleElementResponse { - Object getElement(); + Object getElement(); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusQuerable.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusQuerable.java index 9046c68720..5a83701844 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusQuerable.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusQuerable.java @@ -24,9 +24,9 @@ package org.jclouds.fujitsu.fgcp.xml.internal; * @author Dies Koper */ public interface StatusQuerable { - public String getResponseMessage(); + public String getResponseMessage(); - public String getResponseStatus(); + public String getResponseStatus(); - public boolean isError(); + public boolean isError(); } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusResponse.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusResponse.java index 7ea3361de3..d9d7f06126 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusResponse.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/StatusResponse.java @@ -19,7 +19,6 @@ package org.jclouds.fujitsu.fgcp.xml.internal; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Base class with fields for the elements that FGCP XML responses specify. @@ -27,34 +26,34 @@ import javax.xml.bind.annotation.XmlRootElement; * @author Dies Koper */ public abstract class StatusResponse implements StatusQuerable { - @XmlElement(required = true) - private String responseMessage; - @XmlElement(required = true) - private String responseStatus; + @XmlElement(required = true) + private String responseMessage; + @XmlElement(required = true) + private String responseStatus; - public String getResponseMessage() { - return responseMessage; - } + public String getResponseMessage() { + return responseMessage; + } - public void setResponseMessage(String responseMessage) { - this.responseMessage = responseMessage; - } + public void setResponseMessage(String responseMessage) { + this.responseMessage = responseMessage; + } - public String getResponseStatus() { - return responseStatus; - } + public String getResponseStatus() { + return responseStatus; + } - public void setResponseStatus(String responseStatus) { - this.responseStatus = responseStatus; - } + public void setResponseStatus(String responseStatus) { + this.responseStatus = responseStatus; + } - public boolean isError() { - return !"SUCCESS".equals(responseStatus); - } + public boolean isError() { + return !"SUCCESS".equals(responseStatus); + } - @Override - public String toString() { - return "StatusResponse{" + "responseMessage='" + responseMessage + '\'' - + ", responseStatus='" + responseStatus + '\'' + '}'; - } + @Override + public String toString() { + return "StatusResponse{" + "responseMessage='" + responseMessage + '\'' + + ", responseStatus='" + responseStatus + '\'' + '}'; + } } diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/package-info.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/package-info.java index 12b705bccc..1347685ce9 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/package-info.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/xml/internal/package-info.java @@ -22,7 +22,7 @@ @XmlAccessorType(XmlAccessType.FIELD) package org.jclouds.fujitsu.fgcp.xml.internal; -import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlSchema; diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPBaseTemplateBuilderLiveTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPBaseTemplateBuilderLiveTest.java index 54388cdaf3..66da95ebd1 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPBaseTemplateBuilderLiveTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPBaseTemplateBuilderLiveTest.java @@ -16,69 +16,69 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; public abstract class FGCPBaseTemplateBuilderLiveTest extends - BaseTemplateBuilderLiveTest { + BaseTemplateBuilderLiveTest { - @Override - protected Properties setupProperties() { - Properties overrides = super.setupProperties(); + @Override + protected Properties setupProperties() { + Properties overrides = super.setupProperties(); - String proxy = System.getenv("http_proxy"); - if (proxy != null) { + String proxy = System.getenv("http_proxy"); + if (proxy != null) { - String[] parts = proxy.split("http://|:|@"); + String[] parts = proxy.split("http://|:|@"); - overrides.setProperty(Constants.PROPERTY_PROXY_HOST, - parts[parts.length - 2]); - overrides.setProperty(Constants.PROPERTY_PROXY_PORT, - parts[parts.length - 1]); + overrides.setProperty(Constants.PROPERTY_PROXY_HOST, + parts[parts.length - 2]); + overrides.setProperty(Constants.PROPERTY_PROXY_PORT, + parts[parts.length - 1]); - if (parts.length >= 4) { - overrides.setProperty(Constants.PROPERTY_PROXY_USER, - parts[parts.length - 4]); - overrides.setProperty(Constants.PROPERTY_PROXY_PASSWORD, - parts[parts.length - 3]); + if (parts.length >= 4) { + overrides.setProperty(Constants.PROPERTY_PROXY_USER, + parts[parts.length - 4]); + overrides.setProperty(Constants.PROPERTY_PROXY_PASSWORD, + parts[parts.length - 3]); + } + } + + // enables peer verification using the CAs bundled with the JRE (or + // value of javax.net.ssl.trustStore if set) + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); + + return overrides; + } + + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return Predicates.not(new Predicate() { + + @Override + public boolean apply(OsFamilyVersion64Bit input) { + switch (input.family) { + case CENTOS: + return input.version.matches("5.[46]") + || input.version.equals("6.[2]"); + case WINDOWS: + return (input.version.equals("2008 R2 SE") || input.version + .equals("2008 R2 EE")) && input.is64Bit; + default: + return false; } - } + } - // enables peer verification using the CAs bundled with the JRE (or - // value of javax.net.ssl.trustStore if set) - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); + }); + } - return overrides; - } - - @Override - protected Predicate defineUnsupportedOperatingSystems() { - return Predicates.not(new Predicate() { - - @Override - public boolean apply(OsFamilyVersion64Bit input) { - switch (input.family) { - case CENTOS: - return input.version.matches("5.[46]") - || input.version.equals("6.[2]"); - case WINDOWS: - return (input.version.equals("2008 R2 SE") || input.version - .equals("2008 R2 EE")) && input.is64Bit; - default: - return false; - } - } - - }); - } - - public void testDefaultTemplateBuilder() throws IOException { - Template defaultTemplate = view.getComputeService().templateBuilder() - .build(); - assert defaultTemplate.getImage().getOperatingSystem().getVersion() - .matches("6.2") : defaultTemplate.getImage() - .getOperatingSystem().getVersion(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), - true); - assertEquals(defaultTemplate.getImage().getOperatingSystem() - .getFamily(), OsFamily.CENTOS); - assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); - } + public void testDefaultTemplateBuilder() throws IOException { + Template defaultTemplate = view.getComputeService().templateBuilder() + .build(); + assert defaultTemplate.getImage().getOperatingSystem().getVersion() + .matches("6.2") : defaultTemplate.getImage() + .getOperatingSystem().getVersion(); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), + true); + assertEquals(defaultTemplate.getImage().getOperatingSystem() + .getFamily(), OsFamily.CENTOS); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); + } } \ No newline at end of file diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModuleTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModuleTest.java index 9c1c8804ce..2706e97ca4 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModuleTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/FGCPRestClientModuleTest.java @@ -18,15 +18,8 @@ */ package org.jclouds.fujitsu.fgcp.compute; -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.jclouds.crypto.Crypto; -import org.jclouds.fujitsu.fgcp.FGCPApiMetadata; +import static org.testng.Assert.assertNotNull; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import java.io.File; import java.io.IOException; import java.net.URL; import java.security.KeyStore; @@ -34,9 +27,13 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.spec.InvalidKeySpecException; -import java.util.Scanner; -import static org.testng.Assert.*; +import org.jclouds.crypto.Crypto; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; /** * @author Dies Koper @@ -44,55 +41,55 @@ import static org.testng.Assert.*; @Test(groups = "unit", testName = "FGCPRestClientModuleTest") public class FGCPRestClientModuleTest { - protected FGCPRestClientModule module; - protected Crypto crypto; + protected FGCPRestClientModule module; + protected Crypto crypto; - @BeforeTest - protected void createCrypto() { - Injector i = Guice.createInjector(); - crypto = i.getInstance(Crypto.class); - } + @BeforeTest + protected void createCrypto() { + Injector i = Guice.createInjector(); + crypto = i.getInstance(Crypto.class); + } - @BeforeTest - protected void createRestClientModule() { - Injector i = Guice.createInjector(); - module = i.getInstance(FGCPRestClientModule.class); - } + @BeforeTest + protected void createRestClientModule() { + Injector i = Guice.createInjector(); + module = i.getInstance(FGCPRestClientModule.class); + } - public void testKeyStoreAsPkcs12() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, CertificateException { - assertNotNull(crypto); - assertNotNull(module); + public void testKeyStoreAsPkcs12() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, CertificateException { + assertNotNull(crypto); + assertNotNull(module); - // self-signed dummy cert: - // keytool -genkey -alias test-fgcp -keyalg RSA -keysize 1024 -validity 5475 -dname "CN=localhost" -keystore jclouds-test-fgcp.p12 -storepass jcloudsjclouds -storetype pkcs12 - String cert = "/certs/jclouds-test-fgcp.p12"; - String keyPassword = "jcloudsjclouds"; + // self-signed dummy cert: + // keytool -genkey -alias test-fgcp -keyalg RSA -keysize 1024 -validity 5475 -dname "CN=localhost" -keystore jclouds-test-fgcp.p12 -storepass jcloudsjclouds -storetype pkcs12 + String cert = "/certs/jclouds-test-fgcp.p12"; + String keyPassword = "jcloudsjclouds"; - URL url = this.getClass().getResource(cert); - String certPath = url.getFile(); + URL url = this.getClass().getResource(cert); + String certPath = url.getFile(); - KeyStore ks = module.provideKeyStore(crypto, certPath, keyPassword); + KeyStore ks = module.provideKeyStore(crypto, certPath, keyPassword); - assertNotNull(ks.getCertificate("test-fgcp"), "cert with alias"); - } + assertNotNull(ks.getCertificate("test-fgcp"), "cert with alias"); + } -/* public void testKeyStoreAsPEM() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, CertificateException { - assertNotNull(crypto); - assertNotNull(module); +/* public void testKeyStoreAsPEM() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, CertificateException { + assertNotNull(crypto); + assertNotNull(module); - //openssl pkcs12 -nodes -in jclouds-test-fgcp.p12 -out jclouds-test-fgcp.pem -// String privKeyFilename = "D:\\UserCert.pem.pkcs12-nodes";//_nobags"; - String cert = "/certs/jclouds-test-fgcp.pem"; - String keyPassword = "jcloudsjclouds"; + //openssl pkcs12 -nodes -in jclouds-test-fgcp.p12 -out jclouds-test-fgcp.pem +// String privKeyFilename = "D:\\UserCert.pem.pkcs12-nodes";//_nobags"; + String cert = "/certs/jclouds-test-fgcp.pem"; + String keyPassword = "jcloudsjclouds"; - URL url = this.getClass().getResource(cert); - String certPath = url.getFile(); - Scanner scanner = new Scanner(new File(certPath)); - String content = scanner.useDelimiter("\\A").next(); + URL url = this.getClass().getResource(cert); + String certPath = url.getFile(); + Scanner scanner = new Scanner(new File(certPath)); + String content = scanner.useDelimiter("\\A").next(); - KeyStore ks = module.provideKeyStore(crypto, content, keyPassword); + KeyStore ks = module.provideKeyStore(crypto, content, keyPassword); - assertNotNull(ks.getCertificate("test-fgcp"), "cert with alias"); - } + assertNotNull(ks.getCertificate("test-fgcp"), "cert with alias"); + } */ } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java index 996965b12c..c51c2dcd6f 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java @@ -15,173 +15,173 @@ import com.google.common.collect.ImmutableSet; import com.google.inject.Module; public abstract class FGCPBaseComputeServiceLiveTest extends - BaseComputeServiceLiveTest { + BaseComputeServiceLiveTest { - @Override - protected Properties setupProperties() { - Properties overrides = super.setupProperties(); - - String proxy = System.getenv("http_proxy"); - if (proxy != null) { - - String[] parts = proxy.split("http://|:|@"); - - overrides.setProperty(Constants.PROPERTY_PROXY_HOST, parts[parts.length - 2]); - overrides.setProperty(Constants.PROPERTY_PROXY_PORT, parts[parts.length - 1]); - - if (parts.length >= 4) { - overrides.setProperty(Constants.PROPERTY_PROXY_USER, parts[parts.length - 4]); - overrides.setProperty(Constants.PROPERTY_PROXY_PASSWORD, parts[parts.length - 3]); - } - } - - // enables peer verification using the CAs bundled with the JRE (or - // value of javax.net.ssl.trustStore if set) - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); - - return overrides; + @Override + protected Properties setupProperties() { + Properties overrides = super.setupProperties(); + + String proxy = System.getenv("http_proxy"); + if (proxy != null) { + + String[] parts = proxy.split("http://|:|@"); + + overrides.setProperty(Constants.PROPERTY_PROXY_HOST, parts[parts.length - 2]); + overrides.setProperty(Constants.PROPERTY_PROXY_PORT, parts[parts.length - 1]); + + if (parts.length >= 4) { + overrides.setProperty(Constants.PROPERTY_PROXY_USER, parts[parts.length - 4]); + overrides.setProperty(Constants.PROPERTY_PROXY_PASSWORD, parts[parts.length - 3]); + } + } + + // enables peer verification using the CAs bundled with the JRE (or + // value of javax.net.ssl.trustStore if set) + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); + + return overrides; + } + + @Override + protected Module getSshModule() { + return new SshjSshClientModule(); + } + + @Override + @Test(enabled = false, expectedExceptions = AuthorizationException.class) + public void testCorrectAuthException() throws Exception { + // http://code.google.com/p/jclouds/issues/detail?id=1060 + } + + // fgcp does not support metadata + @Override + protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + assert node.getUserMetadata().isEmpty() : String.format( + "node userMetadata not empty: %s %s", node, + node.getUserMetadata()); } - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } + // node name can't be retrieved through the API and is therefore null + protected void checkResponseEqualsHostname(ExecResponse execResponse, + NodeMetadata node) { + assert node.getHostname() == null : node + " with hostname: " + + node.getHostname(); + } - @Override - @Test(enabled = false, expectedExceptions = AuthorizationException.class) - public void testCorrectAuthException() throws Exception { - // http://code.google.com/p/jclouds/issues/detail?id=1060 - } + // tags are not (yet) supported for fgcp + protected void checkTagsInNodeEquals(NodeMetadata node, + ImmutableSet tags) { + assert node.getTags().isEmpty() : String.format( + "node tags found %s (%s) in node %s", node.getTags(), tags, node); + } - // fgcp does not support metadata - @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { - assert node.getUserMetadata().isEmpty() : String.format( - "node userMetadata not empty: %s %s", node, - node.getUserMetadata()); - } + /* + * public void testCreateAndRunAService() throws Exception { + * super.testCreateAndRunAService(); } + */ - // node name can't be retrieved through the API and is therefore null - protected void checkResponseEqualsHostname(ExecResponse execResponse, - NodeMetadata node) { - assert node.getHostname() == null : node + " with hostname: " - + node.getHostname(); - } + // this test requires network access to the VM it creates: + // before running it, start an SSL/VPN connection to the last updated vsys' + // DMZ. + // may also need to configure SNAT and FW rules to allow the VM to + // communicate out (53 for DNS, 80 for yum). + public void testAScriptExecutionAfterBootWithBasicTemplate() + throws Exception { + super.testAScriptExecutionAfterBootWithBasicTemplate(); + } - // tags are not (yet) supported for fgcp - protected void checkTagsInNodeEquals(NodeMetadata node, - ImmutableSet tags) { - assert node.getTags().isEmpty() : String.format( - "node tags found %s (%s) in node %s", node.getTags(), tags, node); - } + @Override + @Test(enabled = false) + public void testOptionToNotBlock() throws Exception { + // start call returns before node reaches running state, but + // test may be failing due to the system being in a 're-configuring' + // state while destroying nodes of a previous test. + // http://code.google.com/p/jclouds/issues/detail?id=1066 + /* + org.jclouds.compute.RunNodesException: error running 1 node group(fgcp-aublock) location(UZXC0GRT-IZKDVGIL5-N-SECURE1) image(IMG_3c9820_71OW9NZC268) size(islanda-cbrm_140) options({inboundPorts=[], blockUntilRunning=false}) + Execution failures: + + 1) ExecutionException on fgcp-aublock-787: + java.util.concurrent.ExecutionException: java.lang.IllegalStateException: The status of Instance[UZXC0GRT-IZKDVGIL5] is [RECONFIG_ING]. + at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:289) + at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276) + at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:111) + at org.jclouds.concurrent.FutureIterables$1.run(FutureIterables.java:134) + at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) + at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) + at java.lang.Thread.run(Unknown Source) + Caused by: java.lang.IllegalStateException: The status of Instance[UZXC0GRT-IZKDVGIL5] is [RECONFIG_ING]. + at org.jclouds.fujitsu.fgcp.xml.FGCPJAXBParser.fromXML(FGCPJAXBParser.java:75) + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:91) + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:86) + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:73) + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:54) + at com.google.common.base.Functions$FunctionComposition.apply(Functions.java:209) + at com.google.common.util.concurrent.Futures$3.apply(Futures.java:380) + at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:522) + at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) + at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) + at java.lang.Thread.run(Unknown Source) + at org.jclouds.concurrent.config.DescribingExecutorService.submit(DescribingExecutorService.java:89) + at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.createNodeInGroupWithNameAndTemplate(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:170) + at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.execute(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:125) + at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:213) + at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:229) + at org.jclouds.compute.internal.BaseComputeServiceLiveTest.testOptionToNotBlock(BaseComputeServiceLiveTest.java:803) + */ + } - /* - * public void testCreateAndRunAService() throws Exception { - * super.testCreateAndRunAService(); } - */ +/* @Override + @Test(enabled = false) + public void testCreateTwoNodesWithRunScript() { + } - // this test requires network access to the VM it creates: - // before running it, start an SSL/VPN connection to the last updated vsys' - // DMZ. - // may also need to configure SNAT and FW rules to allow the VM to - // communicate out (53 for DNS, 80 for yum). - public void testAScriptExecutionAfterBootWithBasicTemplate() - throws Exception { - super.testAScriptExecutionAfterBootWithBasicTemplate(); - } + @Override + @Test(enabled = false) + public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() { + } - @Override - @Test(enabled = false) - public void testOptionToNotBlock() throws Exception { - // start call returns before node reaches running state, but - // test may be failing due to the system being in a 're-configuring' - // state while destroying nodes of a previous test. - // http://code.google.com/p/jclouds/issues/detail?id=1066 - /* - org.jclouds.compute.RunNodesException: error running 1 node group(fgcp-aublock) location(UZXC0GRT-IZKDVGIL5-N-SECURE1) image(IMG_3c9820_71OW9NZC268) size(islanda-cbrm_140) options({inboundPorts=[], blockUntilRunning=false}) - Execution failures: - - 1) ExecutionException on fgcp-aublock-787: - java.util.concurrent.ExecutionException: java.lang.IllegalStateException: The status of Instance[UZXC0GRT-IZKDVGIL5] is [RECONFIG_ING]. - at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:289) - at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276) - at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:111) - at org.jclouds.concurrent.FutureIterables$1.run(FutureIterables.java:134) - at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) - at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) - at java.lang.Thread.run(Unknown Source) - Caused by: java.lang.IllegalStateException: The status of Instance[UZXC0GRT-IZKDVGIL5] is [RECONFIG_ING]. - at org.jclouds.fujitsu.fgcp.xml.FGCPJAXBParser.fromXML(FGCPJAXBParser.java:75) - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:91) - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:86) - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:73) - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:54) - at com.google.common.base.Functions$FunctionComposition.apply(Functions.java:209) - at com.google.common.util.concurrent.Futures$3.apply(Futures.java:380) - at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:522) - at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) - at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) - at java.lang.Thread.run(Unknown Source) - at org.jclouds.concurrent.config.DescribingExecutorService.submit(DescribingExecutorService.java:89) - at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.createNodeInGroupWithNameAndTemplate(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:170) - at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.execute(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:125) - at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:213) - at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:229) - at org.jclouds.compute.internal.BaseComputeServiceLiveTest.testOptionToNotBlock(BaseComputeServiceLiveTest.java:803) - */ - } - -/* @Override - @Test(enabled = false) - public void testCreateTwoNodesWithRunScript() { - } - - @Override - @Test(enabled = false) - public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() { - } - - @Override - @Test(enabled = false) - public void testGet() { - } + @Override + @Test(enabled = false) + public void testGet() { + } */ -// @Override -// @Test(enabled = false) -// public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception { - // http://code.google.com/p/jclouds/issues/detail?id=1066 - /* - 1) ExecutionException on twin0-f6a: - java.util.concurrent.ExecutionException: org.jclouds.http.HttpResponseException: Error parsing input - {statusCode=200, message=OK, headers={Date=[Sun, 26 Aug 2012 01:22:50 GMT], Transfer-Encoding=[chunked], Set-Cookie=[JSESSIONID=8A07404DF0405E46B3A748C3763B0D9F; Path=/ovisspxy; Secure], Connection=[close]}, payload=[content=true, contentMetadata=[contentDisposition=null, contentEncoding=null, contentLanguage=null, contentLength=null, contentMD5=null, contentType=text/xml;charset=UTF-8, expires=null], written=false]} - at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:289) - at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276) - at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:111) - at org.jclouds.concurrent.FutureIterables$1.run(FutureIterables.java:134) - at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) - at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) - at java.lang.Thread.run(Unknown Source) - Caused by: org.jclouds.http.HttpResponseException: Error parsing input - {statusCode=200, message=OK, headers={Date=[Sun, 26 Aug 2012 01:22:50 GMT], Transfer-Encoding=[chunked], Set-Cookie=[JSESSIONID=8A07404DF0405E46B3A748C3763B0D9F; Path=/ovisspxy; Secure], Connection=[close]}, payload=[content=true, contentMetadata=[contentDisposition=null, contentEncoding=null, contentLanguage=null, contentLength=null, contentMD5=null, contentType=text/xml;charset=UTF-8, expires=null], written=false]} - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:78) - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:1) - at com.google.common.base.Functions$FunctionComposition.apply(Functions.java:209) - at com.google.common.util.concurrent.Futures$3.apply(Futures.java:380) - at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:522) - at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) - at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) - at java.lang.Thread.run(Unknown Source) - at org.jclouds.concurrent.config.DescribingExecutorService.submit(DescribingExecutorService.java:89) - at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.createNodeInGroupWithNameAndTemplate(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:170) - at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.execute(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:125) - at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:213) - at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:229) - at org.jclouds.compute.internal.BaseComputeServiceLiveTest$1.call(BaseComputeServiceLiveTest.java:442) - at org.jclouds.compute.internal.BaseComputeServiceLiveTest$1.call(BaseComputeServiceLiveTest.java:1) - ... 3 more - Caused by: org.jclouds.http.HttpException: The status of Instance[UZXC0GRT-9Q988189J] is [RECONFIG_ING]. - at org.jclouds.fujitsu.fgcp.xml.FGCPJAXBParser.fromXML(FGCPJAXBParser.java:81) - at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:91) -*/ -// } +// @Override +// @Test(enabled = false) +// public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception { + // http://code.google.com/p/jclouds/issues/detail?id=1066 + /* + 1) ExecutionException on twin0-f6a: + java.util.concurrent.ExecutionException: org.jclouds.http.HttpResponseException: Error parsing input + {statusCode=200, message=OK, headers={Date=[Sun, 26 Aug 2012 01:22:50 GMT], Transfer-Encoding=[chunked], Set-Cookie=[JSESSIONID=8A07404DF0405E46B3A748C3763B0D9F; Path=/ovisspxy; Secure], Connection=[close]}, payload=[content=true, contentMetadata=[contentDisposition=null, contentEncoding=null, contentLanguage=null, contentLength=null, contentMD5=null, contentType=text/xml;charset=UTF-8, expires=null], written=false]} + at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:289) + at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276) + at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:111) + at org.jclouds.concurrent.FutureIterables$1.run(FutureIterables.java:134) + at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) + at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) + at java.lang.Thread.run(Unknown Source) + Caused by: org.jclouds.http.HttpResponseException: Error parsing input + {statusCode=200, message=OK, headers={Date=[Sun, 26 Aug 2012 01:22:50 GMT], Transfer-Encoding=[chunked], Set-Cookie=[JSESSIONID=8A07404DF0405E46B3A748C3763B0D9F; Path=/ovisspxy; Secure], Connection=[close]}, payload=[content=true, contentMetadata=[contentDisposition=null, contentEncoding=null, contentLanguage=null, contentLength=null, contentMD5=null, contentType=text/xml;charset=UTF-8, expires=null], written=false]} + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:78) + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:1) + at com.google.common.base.Functions$FunctionComposition.apply(Functions.java:209) + at com.google.common.util.concurrent.Futures$3.apply(Futures.java:380) + at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:522) + at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) + at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) + at java.lang.Thread.run(Unknown Source) + at org.jclouds.concurrent.config.DescribingExecutorService.submit(DescribingExecutorService.java:89) + at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.createNodeInGroupWithNameAndTemplate(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:170) + at org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet.execute(CreateNodesWithGroupEncodedIntoNameThenAddToSet.java:125) + at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:213) + at org.jclouds.compute.internal.BaseComputeService.createNodesInGroup(BaseComputeService.java:229) + at org.jclouds.compute.internal.BaseComputeServiceLiveTest$1.call(BaseComputeServiceLiveTest.java:442) + at org.jclouds.compute.internal.BaseComputeServiceLiveTest$1.call(BaseComputeServiceLiveTest.java:1) + ... 3 more + Caused by: org.jclouds.http.HttpException: The status of Instance[UZXC0GRT-9Q988189J] is [RECONFIG_ING]. + at org.jclouds.fujitsu.fgcp.xml.FGCPJAXBParser.fromXML(FGCPJAXBParser.java:81) + at org.jclouds.http.functions.ParseXMLWithJAXB.apply(ParseXMLWithJAXB.java:91) +*/ +// } } \ No newline at end of file diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystemTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystemTest.java index 966ea07569..2c947e569b 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystemTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/functions/DiskImageToOperatingSystemTest.java @@ -11,7 +11,6 @@ import java.util.List; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.fujitsu.fgcp.compute.functions.DiskImageToOperatingSystem; import org.jclouds.fujitsu.fgcp.domain.DiskImage; import org.jclouds.fujitsu.fgcp.domain.DiskImage.Builder; import org.testng.annotations.Test; @@ -21,143 +20,143 @@ import org.testng.annotations.Test; */ @Test(groups = "unit", testName = "DiskImageToOperatingSystemTest") public class DiskImageToOperatingSystemTest { - // Operating Systems available JAN 2012 (taken from osName) - private static final List operatingSystems = Arrays.asList( - // JP - "CentOS 5.6 32bit (English)", - "CentOS 5.6 64bit (English)", - "Red Hat Enterprise Linux 5.5 32bit (Japanese)", - "Red Hat Enterprise Linux 5.5 64bit (Japanese)", - "Windows Server 2003 R2 EE 32bit SP2 (日本語版) サポート付", - "Windows Server 2003 R2 EE 32bit SP2 (日本語版)", - "Windows Server 2008 R2 EE 64bit (日本語版) サポート付", - "Windows Server 2008 R2 EE 64bit (日本語版)", - "Windows Server 2008 R2 SE 64bit (日本語版) サポート付", - "Windows Server 2008 R2 SE 64bit (日本語版)", - "Windows Server 2008 SE 32bit SP2 (日本語版) サポート付", - "Windows Server 2008 SE 32bit SP2 (日本語版)", - // AU - "CentOS 5.4 64bit (English)", "CentOS 5.4 32bit (English)", - "Windows Server 2008 R2 SE 64bit (English)", - "Windows Server 2008 R2 EE 64bit (English)"); + // Operating Systems available JAN 2012 (taken from osName) + private static final List operatingSystems = Arrays.asList( + // JP + "CentOS 5.6 32bit (English)", + "CentOS 5.6 64bit (English)", + "Red Hat Enterprise Linux 5.5 32bit (Japanese)", + "Red Hat Enterprise Linux 5.5 64bit (Japanese)", + "Windows Server 2003 R2 EE 32bit SP2 (日本語版) サポート付", + "Windows Server 2003 R2 EE 32bit SP2 (日本語版)", + "Windows Server 2008 R2 EE 64bit (日本語版) サポート付", + "Windows Server 2008 R2 EE 64bit (日本語版)", + "Windows Server 2008 R2 SE 64bit (日本語版) サポート付", + "Windows Server 2008 R2 SE 64bit (日本語版)", + "Windows Server 2008 SE 32bit SP2 (日本語版) サポート付", + "Windows Server 2008 SE 32bit SP2 (日本語版)", + // AU + "CentOS 5.4 64bit (English)", "CentOS 5.4 32bit (English)", + "Windows Server 2008 R2 SE 64bit (English)", + "Windows Server 2008 R2 EE 64bit (English)"); - @Test - public void testConversion() { - for (String description : operatingSystems) { - Builder builder = DiskImage.builder(); - builder.osName(description); - builder.osType("hvm"); - builder.creatorName("creator"); - builder.registrant("registrant"); - builder.description("description"); - builder.id("ABCDEFGH"); - DiskImage image = builder.build(); + @Test + public void testConversion() { + for (String description : operatingSystems) { + Builder builder = DiskImage.builder(); + builder.osName(description); + builder.osType("hvm"); + builder.creatorName("creator"); + builder.registrant("registrant"); + builder.description("description"); + builder.id("ABCDEFGH"); + DiskImage image = builder.build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os, description); - assertNotNull(os.getFamily(), description); - assertFalse(os.getFamily().equals(OsFamily.UNRECOGNIZED), - "OsFamily not recognised: " + description); - assertNotNull(os.getVersion(), "Version not recognised: " - + description); - assertEquals(os.getName(), description); - assertEquals(os.getDescription(), description); - assertNotNull(os.getArch(), description); - } - } + assertNotNull(os, description); + assertNotNull(os.getFamily(), description); + assertFalse(os.getFamily().equals(OsFamily.UNRECOGNIZED), + "OsFamily not recognised: " + description); + assertNotNull(os.getVersion(), "Version not recognised: " + + description); + assertEquals(os.getName(), description); + assertEquals(os.getDescription(), description); + assertNotNull(os.getArch(), description); + } + } - @Test - public void testOsFamilyUnrecognized() { - DiskImage image = DiskImage.builder() - .osName("not a known operating system").build(); + @Test + public void testOsFamilyUnrecognized() { + DiskImage image = DiskImage.builder() + .osName("not a known operating system").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertEquals(os.getFamily(), OsFamily.UNRECOGNIZED); - } + assertNotNull(os); + assertEquals(os.getFamily(), OsFamily.UNRECOGNIZED); + } - @Test - public void test64BitsWithSpace() { - DiskImage image = DiskImage.builder().osName("a (64 bit) os").build(); + @Test + public void test64BitsWithSpace() { + DiskImage image = DiskImage.builder().osName("a (64 bit) os").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertTrue(os.is64Bit()); - } + assertNotNull(os); + assertTrue(os.is64Bit()); + } - @Test - public void test64BitsNoSpace() { - DiskImage image = DiskImage.builder().osName("a (64bit) os").build(); + @Test + public void test64BitsNoSpace() { + DiskImage image = DiskImage.builder().osName("a (64bit) os").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertTrue(os.is64Bit()); - } + assertNotNull(os); + assertTrue(os.is64Bit()); + } - @Test - public void test32BitsNoSpace() { - DiskImage image = DiskImage.builder().osName("a (32bit) os").build(); + @Test + public void test32BitsNoSpace() { + DiskImage image = DiskImage.builder().osName("a (32bit) os").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertFalse(os.is64Bit()); - } + assertNotNull(os); + assertFalse(os.is64Bit()); + } - @Test - public void testx64NoSpace() { - DiskImage image = DiskImage.builder().osName("a (x64) os").build(); + @Test + public void testx64NoSpace() { + DiskImage image = DiskImage.builder().osName("a (x64) os").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertTrue(os.is64Bit()); - } + assertNotNull(os); + assertTrue(os.is64Bit()); + } - @Test - public void testWindowsVersion() { - DiskImage image = DiskImage.builder() - .osName("Windows Server 2008 R2 SE 64 bit").build(); + @Test + public void testWindowsVersion() { + DiskImage image = DiskImage.builder() + .osName("Windows Server 2008 R2 SE 64 bit").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertEquals(os.getVersion(), "2008 R2 SE"); - } + assertNotNull(os); + assertEquals(os.getVersion(), "2008 R2 SE"); + } - @Test - public void testCentOSVersion() { - DiskImage image = DiskImage.builder() - .osName("CentOS 6.2 64bit (English)").build(); + @Test + public void testCentOSVersion() { + DiskImage image = DiskImage.builder() + .osName("CentOS 6.2 64bit (English)").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertEquals(os.getVersion(), "6.2"); - } + assertNotNull(os); + assertEquals(os.getVersion(), "6.2"); + } - @Test - public void testUnrecognizedOsVersion() { - DiskImage image = DiskImage.builder() - .osName("Windows Server 2099 (256 bit)").build(); + @Test + public void testUnrecognizedOsVersion() { + DiskImage image = DiskImage.builder() + .osName("Windows Server 2099 (256 bit)").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertNull(os.getVersion()); - } + assertNotNull(os); + assertNull(os.getVersion()); + } - @Test - public void testOsVersionMissing() { - DiskImage image = DiskImage.builder().osName("asd Server").build(); + @Test + public void testOsVersionMissing() { + DiskImage image = DiskImage.builder().osName("asd Server").build(); - OperatingSystem os = new DiskImageToOperatingSystem().apply(image); - assertNotNull(os); - assertNull(os.getVersion(), "os.getVersion(): \'" + os.getVersion() - + "\'"); - } + OperatingSystem os = new DiskImageToOperatingSystem().apply(image); + assertNotNull(os); + assertNull(os.getVersion(), "os.getVersion(): \'" + os.getVersion() + + "\'"); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApiExpectTest.java index 953fceb870..b2a0fd2bd5 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/AdditionalDiskApiExpectTest.java @@ -30,128 +30,128 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "AdditionalDiskApiExpectTest", singleThreaded = true) public class AdditionalDiskApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetVDiskAttributes" - + "&vdiskId=CONTRACT-VSYS00001-D-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVDiskAttributes-response.xml")) - .build(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetVDiskAttributes" + + "&vdiskId=CONTRACT-VSYS00001-D-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVDiskAttributes-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - assertEquals(api.get("CONTRACT-VSYS00001-D-0001").getSize(), 10.0); - } + assertEquals(api.get("CONTRACT-VSYS00001-D-0001").getSize(), 10.0); + } - public void testGetStatus() { - HttpRequest request = buildGETWithQuery("Action=GetVDiskStatus" - + "&vdiskId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVDiskStatus-response.xml")) - .build(); + public void testGetStatus() { + HttpRequest request = buildGETWithQuery("Action=GetVDiskStatus" + + "&vdiskId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVDiskStatus-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - // api is returning STOPPED which is not a documented status. Documentation error? -// assertEquals(api.getStatus("CONTRACT-VSYS00001-S-0001"), VDiskStatus.STOPPED); - } + // api is returning STOPPED which is not a documented status. Documentation error? +// assertEquals(api.getStatus("CONTRACT-VSYS00001-S-0001"), VDiskStatus.STOPPED); + } - public void testUpdate() { - HttpRequest request = buildGETWithQuery("Action=UpdateVDiskAttribute" - + "&vdiskId=CONTRACT-VSYS00001-D-0001" - + "&attributeValue=new-name" + "&attributeName=updateName" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UpdateVDiskAttribute-response.xml")) - .build(); + public void testUpdate() { + HttpRequest request = buildGETWithQuery("Action=UpdateVDiskAttribute" + + "&vdiskId=CONTRACT-VSYS00001-D-0001" + + "&attributeValue=new-name" + "&attributeName=updateName" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UpdateVDiskAttribute-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - api.update("CONTRACT-VSYS00001-D-0001", "updateName", "new-name"); - } + api.update("CONTRACT-VSYS00001-D-0001", "updateName", "new-name"); + } - public void testDestroy() { - HttpRequest request = buildGETWithQuery("Action=DestroyVDisk" - + "&vdiskId=CONTRACT-VSYS00001-D-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DestroyVDisk-response.xml")) - .build(); + public void testDestroy() { + HttpRequest request = buildGETWithQuery("Action=DestroyVDisk" + + "&vdiskId=CONTRACT-VSYS00001-D-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DestroyVDisk-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - api.destroy("CONTRACT-VSYS00001-D-0001"); - } + api.destroy("CONTRACT-VSYS00001-D-0001"); + } - public void testBackup() { - HttpRequest request = buildGETWithQuery("Action=BackupVDisk" - + "&vdiskId=CONTRACT-VSYS00001-D-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/BackupVDisk-response.xml")) - .build(); + public void testBackup() { + HttpRequest request = buildGETWithQuery("Action=BackupVDisk" + + "&vdiskId=CONTRACT-VSYS00001-D-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/BackupVDisk-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - api.backup("CONTRACT-VSYS00001-D-0001"); - } + api.backup("CONTRACT-VSYS00001-D-0001"); + } - public void testRestore() { - HttpRequest request = buildGETWithQuery("Action=RestoreVDisk" - + "&vsysId=CONTRACT-VSYS00001" - + "&backupId=003"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/RestoreVDisk-response.xml")) - .build(); + public void testRestore() { + HttpRequest request = buildGETWithQuery("Action=RestoreVDisk" + + "&vsysId=CONTRACT-VSYS00001" + + "&backupId=003"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/RestoreVDisk-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - api.restore("CONTRACT-VSYS00001", "003"); - } + api.restore("CONTRACT-VSYS00001", "003"); + } - public void testDetach() { - HttpRequest request = buildGETWithQuery("Action=DetachVDisk" - + "&vdiskId=CONTRACT-VSYS00001-D-0001" - + "&vserverId=CONTRACT-VSYS00001-S-0006" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DetachVDisk-response.xml")) - .build(); + public void testDetach() { + HttpRequest request = buildGETWithQuery("Action=DetachVDisk" + + "&vdiskId=CONTRACT-VSYS00001-D-0001" + + "&vserverId=CONTRACT-VSYS00001-S-0006" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DetachVDisk-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - api.detach("CONTRACT-VSYS00001-D-0001", "CONTRACT-VSYS00001-S-0006"); - } + api.detach("CONTRACT-VSYS00001-D-0001", "CONTRACT-VSYS00001-S-0006"); + } - public void testDestroyBackup() { - HttpRequest request = buildGETWithQuery("Action=DestroyVDiskBackup" - + "&vsysId=CONTRACT-VSYS00001" - + "&backupId=003"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DestroyVDiskBackup-response.xml")) - .build(); + public void testDestroyBackup() { + HttpRequest request = buildGETWithQuery("Action=DestroyVDiskBackup" + + "&vsysId=CONTRACT-VSYS00001" + + "&backupId=003"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DestroyVDiskBackup-response.xml")) + .build(); - AdditionalDiskApi api = requestSendsResponse(request, response) - .getAdditionalDiskApi(); + AdditionalDiskApi api = requestSendsResponse(request, response) + .getAdditionalDiskApi(); - api.destroyBackup("CONTRACT-VSYS00001", "003"); - } + api.destroyBackup("CONTRACT-VSYS00001", "003"); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPApiLiveTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPApiLiveTest.java index 1da6e1fa84..0a209d36e5 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPApiLiveTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPApiLiveTest.java @@ -35,50 +35,50 @@ import com.google.inject.Module; */ public class BaseFGCPApiLiveTest extends BaseComputeServiceContextLiveTest { - protected RestContext fgcpContext; + protected RestContext fgcpContext; - public BaseFGCPApiLiveTest() { - provider = "fgcp"; - } + public BaseFGCPApiLiveTest() { + provider = "fgcp"; + } - @Override - protected Properties setupProperties() { - Properties overrides = super.setupProperties(); + @Override + protected Properties setupProperties() { + Properties overrides = super.setupProperties(); - String proxy = System.getenv("http_proxy"); - if (proxy != null) { + String proxy = System.getenv("http_proxy"); + if (proxy != null) { - String[] parts = proxy.split("http://|:|@"); + String[] parts = proxy.split("http://|:|@"); - overrides.setProperty(Constants.PROPERTY_PROXY_HOST, - parts[parts.length - 2]); - overrides.setProperty(Constants.PROPERTY_PROXY_PORT, - parts[parts.length - 1]); + overrides.setProperty(Constants.PROPERTY_PROXY_HOST, + parts[parts.length - 2]); + overrides.setProperty(Constants.PROPERTY_PROXY_PORT, + parts[parts.length - 1]); - if (parts.length >= 4) { - overrides.setProperty(Constants.PROPERTY_PROXY_USER, - parts[parts.length - 4]); - overrides.setProperty(Constants.PROPERTY_PROXY_PASSWORD, - parts[parts.length - 3]); - } - } + if (parts.length >= 4) { + overrides.setProperty(Constants.PROPERTY_PROXY_USER, + parts[parts.length - 4]); + overrides.setProperty(Constants.PROPERTY_PROXY_PASSWORD, + parts[parts.length - 3]); + } + } - // enables peer verification using the CAs bundled with the JRE (or - // value of javax.net.ssl.trustStore if set) - overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); + // enables peer verification using the CAs bundled with the JRE (or + // value of javax.net.ssl.trustStore if set) + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "false"); - return overrides; - } + return overrides; + } - @BeforeGroups(groups = { "integration", "live" }) - @Override - public void setupContext() { - super.setupContext(); - fgcpContext = view.unwrap(); - } + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + fgcpContext = view.unwrap(); + } - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } + @Override + protected Module getSshModule() { + return new SshjSshClientModule(); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPRestApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPRestApiExpectTest.java index 2fb42da3df..4a90da03d0 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPRestApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BaseFGCPRestApiExpectTest.java @@ -46,11 +46,11 @@ import com.google.inject.Module; public class BaseFGCPRestApiExpectTest extends BaseRestClientExpectTest { - public BaseFGCPRestApiExpectTest() { + public BaseFGCPRestApiExpectTest() { provider = "fgcp"; - // self-signed dummy cert: - // keytool -genkey -alias test-fgcp -keyalg RSA -keysize 1024 -validity 5475 -dname "CN=localhost" -keystore jclouds-test-fgcp.p12 -storepass jcloudsjclouds -storetype pkcs12 + // self-signed dummy cert: + // keytool -genkey -alias test-fgcp -keyalg RSA -keysize 1024 -validity 5475 -dname "CN=localhost" -keystore jclouds-test-fgcp.p12 -storepass jcloudsjclouds -storetype pkcs12 String cert = "/certs/jclouds-test-fgcp.p12"; URL url = this.getClass().getResource(cert); assertNotNull(url, cert + " not found"); @@ -79,47 +79,47 @@ public class BaseFGCPRestApiExpectTest extends return new TestFGCPRestClientModule(); } - @Override - protected ProviderMetadata createProviderMetadata() { - return new FGCPProviderMetadata(); - } + @Override + protected ProviderMetadata createProviderMetadata() { + return new FGCPProviderMetadata(); + } - @Override - public Payload payloadFromResource(String resource) { - return super.payloadFromResource("/responses" + resource); - } + @Override + public Payload payloadFromResource(String resource) { + return super.payloadFromResource("/responses" + resource); + } - protected static HttpRequest buildGETWithQuery(String query) { - URI uri = URI.create("https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint" - + "?Version=2012-02-18" - + "&" + query - + "&Locale=en" - + "&AccessKeyId=R01ULTA5OjAwJjEyMzQ1Njc4OTAmMS4wJlNIQTF3aXRoUlNB" -// + "&Signature=G2rGfLAkbq0IURQfXIWYxj3BnMGbjRk4KPnZLAze3Lt4SMMRt8lkjqKvR5Cm%2BnFpDN7J6IprVCCsIrRq5BqPeXT6xtWyb6qMNds2BAr1h%2FJePGs0UosOh2tgPUMSFlZwLVjgNyrSa2zeHA3AEHjF6H1jqcWXXqfCAD4SOHaNavk%3D"); - + "&Signature=G2rGfLAkbq0IURQfXIWYxj3BnMGbjRk4KPnZLAze3Lt4SMMRt8lkjqKvR5Cm%2BnFpDN7J6IprVCCs%0D%0AIrRq5BqPeXT6xtWyb6qMNds2BAr1h%2FJePGs0UosOh2tgPUMSFlZwLVjgNyrSa2zeHA3AEHjF6H1j%0D%0AqcWXXqfCAD4SOHaNavk%3D"); - return HttpRequest - .builder() - .method("GET") - .endpoint(uri) - .addHeader("Accept", "text/xml") - .addHeader("User-Agent", "OViSS-API-CLIENT") - .build(); - } + protected static HttpRequest buildGETWithQuery(String query) { + URI uri = URI.create("https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint" + + "?Version=2012-02-18" + + "&" + query + + "&Locale=en" + + "&AccessKeyId=R01ULTA5OjAwJjEyMzQ1Njc4OTAmMS4wJlNIQTF3aXRoUlNB" +// + "&Signature=G2rGfLAkbq0IURQfXIWYxj3BnMGbjRk4KPnZLAze3Lt4SMMRt8lkjqKvR5Cm%2BnFpDN7J6IprVCCsIrRq5BqPeXT6xtWyb6qMNds2BAr1h%2FJePGs0UosOh2tgPUMSFlZwLVjgNyrSa2zeHA3AEHjF6H1jqcWXXqfCAD4SOHaNavk%3D"); + + "&Signature=G2rGfLAkbq0IURQfXIWYxj3BnMGbjRk4KPnZLAze3Lt4SMMRt8lkjqKvR5Cm%2BnFpDN7J6IprVCCs%0D%0AIrRq5BqPeXT6xtWyb6qMNds2BAr1h%2FJePGs0UosOh2tgPUMSFlZwLVjgNyrSa2zeHA3AEHjF6H1j%0D%0AqcWXXqfCAD4SOHaNavk%3D"); + return HttpRequest + .builder() + .method("GET") + .endpoint(uri) + .addHeader("Accept", "text/xml") + .addHeader("User-Agent", "OViSS-API-CLIENT") + .build(); + } - protected HttpRequest preparePOSTForAction(String action) { - return HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint")) - .payload( - payloadFromResourceWithContentType( - "/" + action.toLowerCase() + "-request.xml", - MediaType.TEXT_XML)) - .headers( - ImmutableMultimap. builder() - .put("Accept", "text/xml") - .put("User-Agent", "OViSS-API-CLIENT").build()) - .build(); - } + protected HttpRequest preparePOSTForAction(String action) { + return HttpRequest + .builder() + .method("POST") + .endpoint( + URI.create("https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint")) + .payload( + payloadFromResourceWithContentType( + "/" + action.toLowerCase() + "-request.xml", + MediaType.TEXT_XML)) + .headers( + ImmutableMultimap. builder() + .put("Accept", "text/xml") + .put("User-Agent", "OViSS-API-CLIENT").build()) + .build(); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApiExpectTest.java index acb2f165c3..a26b0ff101 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/BuiltinServerApiExpectTest.java @@ -18,8 +18,8 @@ */ package org.jclouds.fujitsu.fgcp.services; -import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import java.util.Set; @@ -36,180 +36,180 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "BuiltinServerApiExpectTest", singleThreaded = true) public class BuiltinServerApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testStart() { - HttpRequest request = buildGETWithQuery("Action=StartEFM" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/StartEFM-response.xml")) - .build(); + public void testStart() { + HttpRequest request = buildGETWithQuery("Action=StartEFM" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/StartEFM-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.start("CONTRACT-VSYS00001-S-0001"); - } + api.start("CONTRACT-VSYS00001-S-0001"); + } - public void testStop() { - HttpRequest request = buildGETWithQuery("Action=StopEFM" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/StopEFM-response.xml")) - .build(); + public void testStop() { + HttpRequest request = buildGETWithQuery("Action=StopEFM" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/StopEFM-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.stop("CONTRACT-VSYS00001-S-0001"); - } + api.stop("CONTRACT-VSYS00001-S-0001"); + } - public void testDestroy() { - HttpRequest request = buildGETWithQuery("Action=DestroyEFM" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DestroyEFM-response.xml")) - .build(); + public void testDestroy() { + HttpRequest request = buildGETWithQuery("Action=DestroyEFM" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DestroyEFM-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.destroy("CONTRACT-VSYS00001-S-0001"); - } + api.destroy("CONTRACT-VSYS00001-S-0001"); + } - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetEFMAttributes" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetEFMAttributes-response.xml")) - .build(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetEFMAttributes" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetEFMAttributes-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - assertEquals(api.get("CONTRACT-VSYS00001-S-0001").getType(), BuiltinServer.BuiltinServerType.FW); - } + assertEquals(api.get("CONTRACT-VSYS00001-S-0001").getType(), BuiltinServer.BuiltinServerType.FW); + } /* - public void testGetDetails() { - HttpRequest request = buildGETWithQuery("Action=GetEFMConfiguration" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetEFMConfiguration-response.xml")) - .build(); + public void testGetDetails() { + HttpRequest request = buildGETWithQuery("Action=GetEFMConfiguration" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetEFMConfiguration-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); -// assertNotNull(api.getDetails("CONTRACT-VSYS00001-S-0001")); - } +// assertNotNull(api.getDetails("CONTRACT-VSYS00001-S-0001")); + } */ - public void testGetStatus() { - HttpRequest request = buildGETWithQuery("Action=GetEFMStatus" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetEFMStatus-response.xml")) - .build(); + public void testGetStatus() { + HttpRequest request = buildGETWithQuery("Action=GetEFMStatus" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetEFMStatus-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - assertEquals(api.getStatus("CONTRACT-VSYS00001-S-0001"), BuiltinServerStatus.RUNNING); - } + assertEquals(api.getStatus("CONTRACT-VSYS00001-S-0001"), BuiltinServerStatus.RUNNING); + } - public void testUpdate() { - HttpRequest request = buildGETWithQuery("Action=UpdateEFMAttribute" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&attributeValue=new%20name" - + "&attributeName=vserverName" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UpdateEFMAttribute-response.xml")) - .build(); + public void testUpdate() { + HttpRequest request = buildGETWithQuery("Action=UpdateEFMAttribute" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&attributeValue=new%20name" + + "&attributeName=vserverName" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UpdateEFMAttribute-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.update("CONTRACT-VSYS00001-S-0001", "vserverName", "new name"); - } + api.update("CONTRACT-VSYS00001-S-0001", "vserverName", "new name"); + } - public void testBackup() { - HttpRequest request = buildGETWithQuery("Action=BackupEFM" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/BackupEFM-response.xml")) - .build(); + public void testBackup() { + HttpRequest request = buildGETWithQuery("Action=BackupEFM" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/BackupEFM-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.backup("CONTRACT-VSYS00001-S-0001"); - } + api.backup("CONTRACT-VSYS00001-S-0001"); + } - public void testRestore() { - HttpRequest request = buildGETWithQuery("Action=RestoreEFM" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&backupId=003" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/RestoreEFM-response.xml")) - .build(); + public void testRestore() { + HttpRequest request = buildGETWithQuery("Action=RestoreEFM" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&backupId=003" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/RestoreEFM-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.restore("CONTRACT-VSYS00001-S-0001", "003"); - } + api.restore("CONTRACT-VSYS00001-S-0001", "003"); + } - public void testListBackups() { - HttpRequest request = buildGETWithQuery("Action=ListEFMBackup" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/ListEFMBackup-response.xml")) - .build(); + public void testListBackups() { + HttpRequest request = buildGETWithQuery("Action=ListEFMBackup" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/ListEFMBackup-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - Set backups = api.listBackups("CONTRACT-VSYS00001-S-0001"); - assertNotNull(backups, "backups"); - assertEquals(backups.size(), 2); - assertEquals(backups.iterator().next().getId(), "001"); - assertEquals(backups.iterator().next().getTime(), "20121008201127"); - } + Set backups = api.listBackups("CONTRACT-VSYS00001-S-0001"); + assertNotNull(backups, "backups"); + assertEquals(backups.size(), 2); + assertEquals(backups.iterator().next().getId(), "001"); + assertEquals(backups.iterator().next().getTime(), "20121008201127"); + } - public void testDestroyBackup() { - HttpRequest request = buildGETWithQuery("Action=DestroyEFMBackup" - + "&efmId=CONTRACT-VSYS00001-S-0001" - + "&backupId=003" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DestroyEFMBackup-response.xml")) - .build(); + public void testDestroyBackup() { + HttpRequest request = buildGETWithQuery("Action=DestroyEFMBackup" + + "&efmId=CONTRACT-VSYS00001-S-0001" + + "&backupId=003" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DestroyEFMBackup-response.xml")) + .build(); - BuiltinServerApi api = requestSendsResponse(request, response) - .getFirewallApi(); + BuiltinServerApi api = requestSendsResponse(request, response) + .getFirewallApi(); - api.destroyBackup("CONTRACT-VSYS00001-S-0001", "003"); - } + api.destroyBackup("CONTRACT-VSYS00001-S-0001", "003"); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/DiskImageApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/DiskImageApiExpectTest.java index d0ae9a027a..4e0efdae02 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/DiskImageApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/DiskImageApiExpectTest.java @@ -31,49 +31,49 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "DiskImageApiExpectTest", singleThreaded = true) public class DiskImageApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetDiskImageAttributes" - + "&diskImageId=IMG_A1B2C3_1234567890ABCD"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/GetDiskImageAttributes-response.xml")) - .build(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetDiskImageAttributes" + + "&diskImageId=IMG_A1B2C3_1234567890ABCD"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/GetDiskImageAttributes-response.xml")) + .build(); - DiskImageApi api = requestSendsResponse(request, response) - .getDiskImageApi(); + DiskImageApi api = requestSendsResponse(request, response) + .getDiskImageApi(); - DiskImage image = api.get("IMG_A1B2C3_1234567890ABCD"); + DiskImage image = api.get("IMG_A1B2C3_1234567890ABCD"); - assertEquals(image.getId(), "IMG_A1B2C3_1234567890ABCD"); - assertEquals(image.getCreatorName(), "ABCDEFGH"); - } + assertEquals(image.getId(), "IMG_A1B2C3_1234567890ABCD"); + assertEquals(image.getCreatorName(), "ABCDEFGH"); + } - public void testUpdate() { - HttpRequest request = buildGETWithQuery("Action=UpdateDiskImageAttribute" - + "&diskImageId=IMG_A1B2C3_1234567890ABCD" - + "&attributeName=updateName" - + "&updateLcId=en" - + "&attributeValue=new-name"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/UpdateDiskImageAttribute-response.xml")) - .build(); + public void testUpdate() { + HttpRequest request = buildGETWithQuery("Action=UpdateDiskImageAttribute" + + "&diskImageId=IMG_A1B2C3_1234567890ABCD" + + "&attributeName=updateName" + + "&updateLcId=en" + + "&attributeValue=new-name"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/UpdateDiskImageAttribute-response.xml")) + .build(); - DiskImageApi api = requestSendsResponse(request, response) - .getDiskImageApi(); + DiskImageApi api = requestSendsResponse(request, response) + .getDiskImageApi(); - api.update("IMG_A1B2C3_1234567890ABCD", "en", "updateName", "new-name"); - } + api.update("IMG_A1B2C3_1234567890ABCD", "en", "updateName", "new-name"); + } - public void testDeregister() { - HttpRequest request = buildGETWithQuery("Action=UnregisterDiskImage" - + "&diskImageId=IMG_A1B2C3_1234567890ABCD"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/UnregisterDiskImage-response.xml")) - .build(); + public void testDeregister() { + HttpRequest request = buildGETWithQuery("Action=UnregisterDiskImage" + + "&diskImageId=IMG_A1B2C3_1234567890ABCD"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/UnregisterDiskImage-response.xml")) + .build(); - DiskImageApi api = requestSendsResponse(request, response) - .getDiskImageApi(); + DiskImageApi api = requestSendsResponse(request, response) + .getDiskImageApi(); - api.deregister("IMG_A1B2C3_1234567890ABCD"); - } + api.deregister("IMG_A1B2C3_1234567890ABCD"); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApiExpectTest.java index 226ec070c2..8458fe2a92 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/PublicIPAddressApiExpectTest.java @@ -33,77 +33,77 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "PublicIPAddressApiExpectTest", singleThreaded = true) public class PublicIPAddressApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testAttach() { - HttpRequest request = buildGETWithQuery("Action=AttachPublicIP" - + "&vsysId=CONTRACT-VSYS00001" - + "&publicIp=123.45.67.89"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/AttachPublicIP-response.xml")) - .build(); + public void testAttach() { + HttpRequest request = buildGETWithQuery("Action=AttachPublicIP" + + "&vsysId=CONTRACT-VSYS00001" + + "&publicIp=123.45.67.89"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/AttachPublicIP-response.xml")) + .build(); - PublicIPAddressApi api = requestSendsResponse(request, response) - .getPublicIPAddressApi(); + PublicIPAddressApi api = requestSendsResponse(request, response) + .getPublicIPAddressApi(); - api.attach("CONTRACT-VSYS00001", "123.45.67.89"); - } + api.attach("CONTRACT-VSYS00001", "123.45.67.89"); + } - public void testDetach() { - HttpRequest request = buildGETWithQuery("Action=DetachPublicIP" - + "&vsysId=CONTRACT-VSYS00001" - + "&publicIp=123.45.67.89"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DetachPublicIP-response.xml")) - .build(); + public void testDetach() { + HttpRequest request = buildGETWithQuery("Action=DetachPublicIP" + + "&vsysId=CONTRACT-VSYS00001" + + "&publicIp=123.45.67.89"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DetachPublicIP-response.xml")) + .build(); - PublicIPAddressApi api = requestSendsResponse(request, response) - .getPublicIPAddressApi(); + PublicIPAddressApi api = requestSendsResponse(request, response) + .getPublicIPAddressApi(); - api.detach("CONTRACT-VSYS00001", "123.45.67.89"); - } + api.detach("CONTRACT-VSYS00001", "123.45.67.89"); + } - public void testFree() { - HttpRequest request = buildGETWithQuery("Action=FreePublicIP" - + "&vsysId=CONTRACT-VSYS00001" - + "&publicIp=123.45.67.89"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/FreePublicIP-response.xml")) - .build(); + public void testFree() { + HttpRequest request = buildGETWithQuery("Action=FreePublicIP" + + "&vsysId=CONTRACT-VSYS00001" + + "&publicIp=123.45.67.89"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/FreePublicIP-response.xml")) + .build(); - PublicIPAddressApi api = requestSendsResponse(request, response) - .getPublicIPAddressApi(); + PublicIPAddressApi api = requestSendsResponse(request, response) + .getPublicIPAddressApi(); - api.free("CONTRACT-VSYS00001", "123.45.67.89"); - } + api.free("CONTRACT-VSYS00001", "123.45.67.89"); + } - public void testGetStatus() { - HttpRequest request = buildGETWithQuery("Action=GetPublicIPStatus" - + "&publicIp=123.45.67.89"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/GetPublicIPStatus-response.xml")) - .build(); + public void testGetStatus() { + HttpRequest request = buildGETWithQuery("Action=GetPublicIPStatus" + + "&publicIp=123.45.67.89"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/GetPublicIPStatus-response.xml")) + .build(); - PublicIPAddressApi api = requestSendsResponse(request, response) - .getPublicIPAddressApi(); + PublicIPAddressApi api = requestSendsResponse(request, response) + .getPublicIPAddressApi(); - PublicIPStatus status = api.getStatus("123.45.67.89"); - assertEquals(status, PublicIPStatus.ATTACHED); - } + PublicIPStatus status = api.getStatus("123.45.67.89"); + assertEquals(status, PublicIPStatus.ATTACHED); + } - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetPublicIPAttributes" - + "&publicIp=123.45.67.89"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/GetPublicIPAttributes-response.xml")) - .build(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetPublicIPAttributes" + + "&publicIp=123.45.67.89"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/GetPublicIPAttributes-response.xml")) + .build(); - PublicIPAddressApi api = requestSendsResponse(request, response) - .getPublicIPAddressApi(); + PublicIPAddressApi api = requestSendsResponse(request, response) + .getPublicIPAddressApi(); - PublicIP ip = api.get("123.45.67.89"); + PublicIP ip = api.get("123.45.67.89"); - assertNotNull(ip, "ip"); - assertEquals(ip.getAddress(), "123.45.67.89"); - assertEquals(ip.getVersion(), PublicIP.Version.IPv4); - } + assertNotNull(ip, "ip"); + assertEquals(ip.getAddress(), "123.45.67.89"); + assertEquals(ip.getVersion(), PublicIP.Version.IPv4); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApiExpectTest.java index 182c13faf6..6b653c01f9 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/SystemTemplateApiExpectTest.java @@ -18,10 +18,8 @@ */ package org.jclouds.fujitsu.fgcp.services; -import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import org.jclouds.fujitsu.fgcp.domain.VSystem; import org.jclouds.fujitsu.fgcp.domain.VSystemDescriptor; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -33,71 +31,71 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "SystemTemplateApiExpectTest", singleThreaded = true) public class SystemTemplateApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetVSYSDescriptorConfiguration" - + "&vsysDescriptorId=3-tier%20Skeleton"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVSYSDescriptorConfiguration-response.xml")) - .build(); - SystemTemplateApi client = requestSendsResponse(request, response) - .getSystemTemplateApi(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetVSYSDescriptorConfiguration" + + "&vsysDescriptorId=3-tier%20Skeleton"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVSYSDescriptorConfiguration-response.xml")) + .build(); + SystemTemplateApi client = requestSendsResponse(request, response) + .getSystemTemplateApi(); - VSystemDescriptor desc = client.get("3-tier Skeleton"); - assertNotNull(desc, "desc"); -// assertEquals(desc.) - } + VSystemDescriptor desc = client.get("3-tier Skeleton"); + assertNotNull(desc, "desc"); +// assertEquals(desc.) + } - public void testUpdate() { - HttpRequest request = buildGETWithQuery("Action=UpdateVSYSDescriptorAttribute" - + "&vsysDescriptorId=3-tier%20Skeleton" + "&attributeName=updateName" - + "&updateLcId=en" - + "&attributeValue=new-name"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UpdateVSYSDescriptorAttribute-response.xml")) - .build(); + public void testUpdate() { + HttpRequest request = buildGETWithQuery("Action=UpdateVSYSDescriptorAttribute" + + "&vsysDescriptorId=3-tier%20Skeleton" + "&attributeName=updateName" + + "&updateLcId=en" + + "&attributeValue=new-name"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UpdateVSYSDescriptorAttribute-response.xml")) + .build(); - SystemTemplateApi api = requestSendsResponse(request, response) - .getSystemTemplateApi(); + SystemTemplateApi api = requestSendsResponse(request, response) + .getSystemTemplateApi(); - api.update("3-tier Skeleton", "en", "updateName", "new-name"); - } + api.update("3-tier Skeleton", "en", "updateName", "new-name"); + } - public void testDeregister() { - HttpRequest request = buildGETWithQuery("Action=UnregisterVSYSDescriptor" - + "&vsysDescriptorId=3-tier%20Skeleton"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UnregisterVSYSDescriptor-response.xml")) - .build(); + public void testDeregister() { + HttpRequest request = buildGETWithQuery("Action=UnregisterVSYSDescriptor" + + "&vsysDescriptorId=3-tier%20Skeleton"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UnregisterVSYSDescriptor-response.xml")) + .build(); - SystemTemplateApi api = requestSendsResponse(request, response) - .getSystemTemplateApi(); + SystemTemplateApi api = requestSendsResponse(request, response) + .getSystemTemplateApi(); - api.deregister("3-tier Skeleton"); - } + api.deregister("3-tier Skeleton"); + } - public void testDeregisterPrivateTemplate() { - HttpRequest request = buildGETWithQuery("Action=UnregisterPrivateVSYSDescriptor" - + "&vsysDescriptorId=3-tier%20Skeleton"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UnregisterPrivateVSYSDescriptor-response.xml")) - .build(); + public void testDeregisterPrivateTemplate() { + HttpRequest request = buildGETWithQuery("Action=UnregisterPrivateVSYSDescriptor" + + "&vsysDescriptorId=3-tier%20Skeleton"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UnregisterPrivateVSYSDescriptor-response.xml")) + .build(); - SystemTemplateApi api = requestSendsResponse(request, response) - .getSystemTemplateApi(); + SystemTemplateApi api = requestSendsResponse(request, response) + .getSystemTemplateApi(); - api.deregisterPrivateTemplate("3-tier Skeleton"); - } + api.deregisterPrivateTemplate("3-tier Skeleton"); + } } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiExpectTest.java index 277a449fe6..32ae3ad2ef 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiExpectTest.java @@ -41,166 +41,166 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "VirtualDCApiExpectTest", singleThreaded = true) public class VirtualDCApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testListVirtualSystems() { - HttpRequest request = buildGETWithQuery("Action=ListVSYS"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/ListVSYS-response.xml")) - .build(); + public void testListVirtualSystems() { + HttpRequest request = buildGETWithQuery("Action=ListVSYS"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/ListVSYS-response.xml")) + .build(); - VirtualDCApi api = requestSendsResponse(request, response).getVirtualDCApi(); + VirtualDCApi api = requestSendsResponse(request, response).getVirtualDCApi(); - Set vsysSet = api.listVirtualSystems(); - assertEquals(vsysSet.size(), 2); - } + Set vsysSet = api.listVirtualSystems(); + assertEquals(vsysSet.size(), 2); + } - public void testCreateVirtualSystem() { - HttpRequest request = buildGETWithQuery("Action=CreateVSYS&vsysDescriptorId=myDescId&vsysName=myVSYS"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/CreateVSYS-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testCreateVirtualSystem() { + HttpRequest request = buildGETWithQuery("Action=CreateVSYS&vsysDescriptorId=myDescId&vsysName=myVSYS"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/CreateVSYS-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - String vsysId = api.createVirtualSystem("myDescId", "myVSYS"); - assertEquals(vsysId, "CONTRACT-VSYS00001", "vsysId: " + vsysId); - } + String vsysId = api.createVirtualSystem("myDescId", "myVSYS"); + assertEquals(vsysId, "CONTRACT-VSYS00001", "vsysId: " + vsysId); + } - public void testListServerTypes() { - HttpRequest request = buildGETWithQuery("Action=ListServerType&diskImageId=dummy"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/ListServerType-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testListServerTypes() { + HttpRequest request = buildGETWithQuery("Action=ListServerType&diskImageId=dummy"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/ListServerType-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - Set serverTypes = api.listServerTypes(); - assertNotNull(serverTypes, "serverTypes"); - assertEquals(serverTypes.size(), 4, - "Unexpected number of server types: " + serverTypes.size()); - } + Set serverTypes = api.listServerTypes(); + assertNotNull(serverTypes, "serverTypes"); + assertEquals(serverTypes.size(), 4, + "Unexpected number of server types: " + serverTypes.size()); + } - public void testListPublicIPs() { - HttpRequest request = buildGETWithQuery("Action=ListPublicIP"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/ListPublicIP-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testListPublicIPs() { + HttpRequest request = buildGETWithQuery("Action=ListPublicIP"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/ListPublicIP-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - Map ips = api.listPublicIPs(); + Map ips = api.listPublicIPs(); - assertNotNull(ips, "ips"); - assertEquals(ips.size(), 2, "Unexpected number of ips: " + ips.size()); - assertEquals(ips.keySet().size(), 2, "Unexpected number of ips: " + ips.size()); - assertTrue(ips.containsValue("ABCDEFGH-A123B456CE"), "missing system id"); - assertEquals(ips.keySet().iterator().next().getVersion(), PublicIP.Version.IPv4); - } + assertNotNull(ips, "ips"); + assertEquals(ips.size(), 2, "Unexpected number of ips: " + ips.size()); + assertEquals(ips.keySet().size(), 2, "Unexpected number of ips: " + ips.size()); + assertTrue(ips.containsValue("ABCDEFGH-A123B456CE"), "missing system id"); + assertEquals(ips.keySet().iterator().next().getVersion(), PublicIP.Version.IPv4); + } - public void testListDiskImages() { - HttpRequest request = buildGETWithQuery("Action=ListDiskImage"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/ListDiskImages-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testListDiskImages() { + HttpRequest request = buildGETWithQuery("Action=ListDiskImage"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/ListDiskImages-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - Set images = api.listDiskImages(); + Set images = api.listDiskImages(); - assertNotNull(images, "images"); - assertTrue(images.size() > 5, "Unexpected number of images: " + images.size()); - } + assertNotNull(images, "images"); + assertTrue(images.size() > 5, "Unexpected number of images: " + images.size()); + } - public void testListDiskImage() { - HttpRequest request = buildGETWithQuery("Action=ListDiskImage&vsysDescriptorId=IMG_A1B2C3_1234567890ABCD"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/ListDiskImage-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testListDiskImage() { + HttpRequest request = buildGETWithQuery("Action=ListDiskImage&vsysDescriptorId=IMG_A1B2C3_1234567890ABCD"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/ListDiskImage-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - Set images = api.listDiskImages(null, "IMG_A1B2C3_1234567890ABCD"); + Set images = api.listDiskImages(null, "IMG_A1B2C3_1234567890ABCD"); - assertNotNull(images, "images"); - assertTrue(images.size() == 1, "Unexpected number of images: " + images.size()); - } + assertNotNull(images, "images"); + assertTrue(images.size() == 1, "Unexpected number of images: " + images.size()); + } - public void testGetAddressRange() { - HttpRequest request = buildGETWithQuery("Action=GetAddressRange"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/GetAddressRange-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testGetAddressRange() { + HttpRequest request = buildGETWithQuery("Action=GetAddressRange"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/GetAddressRange-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - Set range = api.getAddressRange(); - assertNotNull(range); - assertEquals(range.size(), 1); - } + Set range = api.getAddressRange(); + assertNotNull(range); + assertEquals(range.size(), 1); + } - public void testAddAddressRange() { - HttpRequest request = buildGETWithQuery("Action=AddAddressRange" - + "&pipFrom=192.168.0.0" - + "&pipTo=192.168.30.0"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/AddAddressRange-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testAddAddressRange() { + HttpRequest request = buildGETWithQuery("Action=AddAddressRange" + + "&pipFrom=192.168.0.0" + + "&pipTo=192.168.30.0"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/AddAddressRange-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - api.addAddressRange("192.168.0.0", "192.168.30.0"); - } + api.addAddressRange("192.168.0.0", "192.168.30.0"); + } - public void testDeleteAddressRange() { - HttpRequest request = buildGETWithQuery("Action=DeleteAddressRange" - + "&pipFrom=192.168.0.0" - + "&pipTo=192.168.30.0"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/DeleteAddressRange-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testDeleteAddressRange() { + HttpRequest request = buildGETWithQuery("Action=DeleteAddressRange" + + "&pipFrom=192.168.0.0" + + "&pipTo=192.168.30.0"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/DeleteAddressRange-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - api.deleteAddressRange("192.168.0.0", "192.168.30.0"); - } + api.deleteAddressRange("192.168.0.0", "192.168.30.0"); + } - public void testCreateAddressPool() { - HttpRequest request = buildGETWithQuery("Action=CreateAddressPool" - + "&pipFrom=192.168.0.0" - + "&pipTo=192.168.30.0"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/CreateAddressPool-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testCreateAddressPool() { + HttpRequest request = buildGETWithQuery("Action=CreateAddressPool" + + "&pipFrom=192.168.0.0" + + "&pipTo=192.168.30.0"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/CreateAddressPool-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - api.createAddressPool("192.168.0.0", "192.168.30.0"); - } + api.createAddressPool("192.168.0.0", "192.168.30.0"); + } - public void testGetEventLog() { - HttpRequest request = buildGETWithQuery("Action=GetEventLog"); - HttpResponse response = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/GetEventLog-response.xml")) - .build(); - VirtualDCApi api = requestSendsResponse(request, response) - .getVirtualDCApi(); + public void testGetEventLog() { + HttpRequest request = buildGETWithQuery("Action=GetEventLog"); + HttpResponse response = HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/GetEventLog-response.xml")) + .build(); + VirtualDCApi api = requestSendsResponse(request, response) + .getVirtualDCApi(); - Set logs = api.getEventLogs(); - assertNotNull(logs); - //TODO: get one with several -// assertEquals(logs.size(), 1); - } + Set logs = api.getEventLogs(); + assertNotNull(logs); + //TODO: get one with several +// assertEquals(logs.size(), 1); + } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiLiveTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiLiveTest.java index 0e873ed543..16a5191972 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiLiveTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApiLiveTest.java @@ -34,43 +34,43 @@ import org.testng.annotations.Test; @Test(groups = "live", enabled = true, singleThreaded = true, testName = "VirtualDCApiLiveTest") public class VirtualDCApiLiveTest extends BaseFGCPApiLiveTest { - private VirtualDCApi api; + private VirtualDCApi api; - @BeforeGroups(groups = { "live" }) - public void setupContext() { - super.setupContext(); - api = fgcpContext.getApi().getVirtualDCApi(); - } + @BeforeGroups(groups = { "live" }) + public void setupContext() { + super.setupContext(); + api = fgcpContext.getApi().getVirtualDCApi(); + } - public void testListVirtualSystems() { -/* Properties overrides = setupProperties(); - RestContext context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides);*/ + public void testListVirtualSystems() { +/* Properties overrides = setupProperties(); + RestContext context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), + overrides);*/ - Set vsysSet = api.listVirtualSystems(); - assertNotNull(vsysSet, "vsysSet"); - assertTrue(vsysSet.size() > 0, "vsysSet.size() should be greater than 0"); - for (VSystem vsys : vsysSet) { - System.out.println(vsys); - } - } + Set vsysSet = api.listVirtualSystems(); + assertNotNull(vsysSet, "vsysSet"); + assertTrue(vsysSet.size() > 0, "vsysSet.size() should be greater than 0"); + for (VSystem vsys : vsysSet) { + System.out.println(vsys); + } + } -/* public void testCreateVirtualSystem() { - String vsysId = api.createVirtualSystem("abc", "def"); +/* public void testCreateVirtualSystem() { + String vsysId = api.createVirtualSystem("abc", "def"); - assertNotNull(vsysId, "vsysId"); - assertFalse(vsysId.equals(""), "vsysId is empty (\"\")"); - System.out.println("vsysId: " + vsysId); - }*/ + assertNotNull(vsysId, "vsysId"); + assertFalse(vsysId.equals(""), "vsysId is empty (\"\")"); + System.out.println("vsysId: " + vsysId); + }*/ - public void testListServerTypes() { - Set serverTypes = api.listServerTypes(); + public void testListServerTypes() { + Set serverTypes = api.listServerTypes(); - assertNotNull(serverTypes, "serverTypes"); - assertTrue(serverTypes.size() == 4, "serverTypes.size should return 4, not " + serverTypes.size()); + assertNotNull(serverTypes, "serverTypes"); + assertTrue(serverTypes.size() == 4, "serverTypes.size should return 4, not " + serverTypes.size()); -// System.out.println("listServerTypes: " + serverTypes); - } +// System.out.println("listServerTypes: " + serverTypes); + } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApiExpectTest.java index 198993c25d..b6e4ec7d97 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualServerApiExpectTest.java @@ -18,8 +18,8 @@ */ package org.jclouds.fujitsu.fgcp.services; -import static org.testng.AssertJUnit.assertNotNull; import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; import org.jclouds.fujitsu.fgcp.domain.VServerStatus; import org.jclouds.fujitsu.fgcp.domain.VServerWithDetails; @@ -33,189 +33,189 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "VirtualServerApiExpectTest", singleThreaded = true) public class VirtualServerApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testStart() { - HttpRequest request = buildGETWithQuery("Action=StartVServer" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/StartVServer-response.xml")) - .build(); + public void testStart() { + HttpRequest request = buildGETWithQuery("Action=StartVServer" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/StartVServer-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - api.start("CONTRACT-VSYS00001-S-0005"); - } + api.start("CONTRACT-VSYS00001-S-0005"); + } - public void testStop() { - HttpRequest request = buildGETWithQuery("Action=StopVServer" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/StopVServer-response.xml")) - .build(); + public void testStop() { + HttpRequest request = buildGETWithQuery("Action=StopVServer" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/StopVServer-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - api.stop("CONTRACT-VSYS00001-S-0005"); - } + api.stop("CONTRACT-VSYS00001-S-0005"); + } - public void testStopForcefully() { - HttpRequest request = buildGETWithQuery("Action=StopVServer" - + "&force=true" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/StopVServer-response.xml")) - .build(); + public void testStopForcefully() { + HttpRequest request = buildGETWithQuery("Action=StopVServer" + + "&force=true" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/StopVServer-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - api.stopForcefully("CONTRACT-VSYS00001-S-0005"); - } + api.stopForcefully("CONTRACT-VSYS00001-S-0005"); + } - public void testDestroy() { - HttpRequest request = buildGETWithQuery("Action=DestroyVServer" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/DestroyVServer-response.xml")) - .build(); + public void testDestroy() { + HttpRequest request = buildGETWithQuery("Action=DestroyVServer" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/DestroyVServer-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - api.destroy("CONTRACT-VSYS00001-S-0005"); - } + api.destroy("CONTRACT-VSYS00001-S-0005"); + } - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetVServerAttributes" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVServerAttributes-response.xml")) - .build(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetVServerAttributes" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVServerAttributes-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - assertNotNull(api.get("CONTRACT-VSYS00001-S-0005")); - } + assertNotNull(api.get("CONTRACT-VSYS00001-S-0005")); + } - public void testGetDetails() { - HttpRequest request = buildGETWithQuery("Action=GetVServerConfiguration" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVServerConfiguration-response.xml")) - .build(); + public void testGetDetails() { + HttpRequest request = buildGETWithQuery("Action=GetVServerConfiguration" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVServerConfiguration-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - VServerWithDetails server = api.getDetails("CONTRACT-VSYS00001-S-0005"); - assertNotNull(server); - assertEquals(server.getId(), "CONTRACT-VSYS00001-S-0005"); - assertEquals(server.getVnics().iterator().next().getNicNo(), 0); - assertEquals(server.getVnics().iterator().next().getPrivateIp(), "192.168.4.13"); - assertEquals(server.getVnics().iterator().next().getNetworkId(), "CONTRACT-VSYS00001-N-DMZ"); - assertEquals(server.getImage().getId(), "IMG_A1B2C3_1234567890ABCD"); - assertEquals(server.getImage().getSysvolSize(), 10.0f); - } + VServerWithDetails server = api.getDetails("CONTRACT-VSYS00001-S-0005"); + assertNotNull(server); + assertEquals(server.getId(), "CONTRACT-VSYS00001-S-0005"); + assertEquals(server.getVnics().iterator().next().getNicNo(), 0); + assertEquals(server.getVnics().iterator().next().getPrivateIp(), "192.168.4.13"); + assertEquals(server.getVnics().iterator().next().getNetworkId(), "CONTRACT-VSYS00001-N-DMZ"); + assertEquals(server.getImage().getId(), "IMG_A1B2C3_1234567890ABCD"); + assertEquals(server.getImage().getSysvolSize(), 10.0f); + } - public void testGetStatus() { - HttpRequest request = buildGETWithQuery("Action=GetVServerStatus" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVServerStatus-response.xml")) - .build(); + public void testGetStatus() { + HttpRequest request = buildGETWithQuery("Action=GetVServerStatus" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVServerStatus-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - assertEquals(api.getStatus("CONTRACT-VSYS00001-S-0005"), VServerStatus.STOPPED); - } + assertEquals(api.getStatus("CONTRACT-VSYS00001-S-0005"), VServerStatus.STOPPED); + } - public void testInitialPassword() { - HttpRequest request = buildGETWithQuery("Action=GetVServerInitialPassword" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVServerInitialPassword-response.xml")) - .build(); + public void testInitialPassword() { + HttpRequest request = buildGETWithQuery("Action=GetVServerInitialPassword" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVServerInitialPassword-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - assertEquals(api.getInitialPassword("CONTRACT-VSYS00001-S-0005"), "mySecretpwd1"); - } + assertEquals(api.getInitialPassword("CONTRACT-VSYS00001-S-0005"), "mySecretpwd1"); + } - public void testUpdate() { - HttpRequest request = buildGETWithQuery("Action=UpdateVServerAttribute" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&attributeValue=new%20name" - + "&attributeName=vserverName" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UpdateVServerAttribute-response.xml")) - .build(); + public void testUpdate() { + HttpRequest request = buildGETWithQuery("Action=UpdateVServerAttribute" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&attributeValue=new%20name" + + "&attributeName=vserverName" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UpdateVServerAttribute-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - api.update("CONTRACT-VSYS00001-S-0005", "vserverName", "new name"); - } + api.update("CONTRACT-VSYS00001-S-0005", "vserverName", "new name"); + } - public void testAttachDisk() { - HttpRequest request = buildGETWithQuery("Action=AttachVDisk" - + "&vserverId=CONTRACT-VSYS00001-S-0005" - + "&vdiskId=CONTRACT-VSYS00001-D-0001" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/AttachVDisk-response.xml")) - .build(); + public void testAttachDisk() { + HttpRequest request = buildGETWithQuery("Action=AttachVDisk" + + "&vserverId=CONTRACT-VSYS00001-S-0005" + + "&vdiskId=CONTRACT-VSYS00001-D-0001" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/AttachVDisk-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - api.attachDisk("CONTRACT-VSYS00001-S-0005", "CONTRACT-VSYS00001-D-0001"); - } + api.attachDisk("CONTRACT-VSYS00001-S-0005", "CONTRACT-VSYS00001-D-0001"); + } -/* public void testGetPerformanceInformation() { - HttpRequest request = buildGETWithQuery("Action=GetPerformanceInformation" - + "&serverId=CONTRACT-VSYS00001-S-0005" - + "&interval=10minute" - + "&vsysId=CONTRACT-VSYS00001"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetPerformanceInformation-response.xml")) - .build(); +/* public void testGetPerformanceInformation() { + HttpRequest request = buildGETWithQuery("Action=GetPerformanceInformation" + + "&serverId=CONTRACT-VSYS00001-S-0005" + + "&interval=10minute" + + "&vsysId=CONTRACT-VSYS00001"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetPerformanceInformation-response.xml")) + .build(); - VirtualServerApi api = requestSendsResponse(request, response) - .getVirtualServerApi(); + VirtualServerApi api = requestSendsResponse(request, response) + .getVirtualServerApi(); - assertNotNull(api.getPerformanceInformation( - "CONTRACT-VSYS00001-S-0005", "10minute")); - } + assertNotNull(api.getPerformanceInformation( + "CONTRACT-VSYS00001-S-0005", "10minute")); + } */ } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApiExpectTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApiExpectTest.java index 31aaed1946..79fc009811 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApiExpectTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/services/VirtualSystemApiExpectTest.java @@ -40,220 +40,220 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "VirtualSystemApiExpectTest", singleThreaded = true) public class VirtualSystemApiExpectTest extends BaseFGCPRestApiExpectTest { - public void testGet() { - HttpRequest request = buildGETWithQuery("Action=GetVSYSAttributes&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVSYSAttributes-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testGet() { + HttpRequest request = buildGETWithQuery("Action=GetVSYSAttributes&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVSYSAttributes-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - VSystem system = api.get("ABCDEFGH-A123B456CE"); - assertNotNull(system, "system"); - } + VSystem system = api.get("ABCDEFGH-A123B456CE"); + assertNotNull(system, "system"); + } - public void testGetDetails() { - HttpRequest request = buildGETWithQuery("Action=GetVSYSConfiguration&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/GetVSYSConfiguration-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testGetDetails() { + HttpRequest request = buildGETWithQuery("Action=GetVSYSConfiguration&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/GetVSYSConfiguration-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - VSystem system = api.getDetails("ABCDEFGH-A123B456CE"); - assertNotNull(system, "system"); - } + VSystem system = api.getDetails("ABCDEFGH-A123B456CE"); + assertNotNull(system, "system"); + } - public void testGetStatus() { - HttpRequest request = buildGETWithQuery("Action=GetVSYSStatus" - + "&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/GetVSYSStatus-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testGetStatus() { + HttpRequest request = buildGETWithQuery("Action=GetVSYSStatus" + + "&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/GetVSYSStatus-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - assertEquals(api.getStatus("ABCDEFGH-A123B456CE"), VSystemStatus.NORMAL); - } + assertEquals(api.getStatus("ABCDEFGH-A123B456CE"), VSystemStatus.NORMAL); + } - public void testUpdate() { - HttpRequest request = buildGETWithQuery("Action=UpdateVSYSAttribute" - + "&vsysId=ABCDEFGH-A123B456CE" + "&attributeValue=new-name" - + "&attributeName=updateName"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/UpdateVDiskAttribute-response.xml")) - .build(); + public void testUpdate() { + HttpRequest request = buildGETWithQuery("Action=UpdateVSYSAttribute" + + "&vsysId=ABCDEFGH-A123B456CE" + "&attributeValue=new-name" + + "&attributeName=updateName"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/UpdateVDiskAttribute-response.xml")) + .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - api.update("ABCDEFGH-A123B456CE", "updateName", "new-name"); - } + api.update("ABCDEFGH-A123B456CE", "updateName", "new-name"); + } - public void testListPublicIPs() { - HttpRequest request = buildGETWithQuery("Action=ListPublicIP" - + "&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/ListPublicIP_one_vsys-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testListPublicIPs() { + HttpRequest request = buildGETWithQuery("Action=ListPublicIP" + + "&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/ListPublicIP_one_vsys-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - Set ips = api.listPublicIPs("ABCDEFGH-A123B456CE"); - assertNotNull(ips, "ips"); - assertTrue(ips.size() == 2, "Unexpected number of ips: " + ips.size()); - assertEquals(ips.iterator().next().getVersion(), PublicIP.Version.IPv4); - } + Set ips = api.listPublicIPs("ABCDEFGH-A123B456CE"); + assertNotNull(ips, "ips"); + assertTrue(ips.size() == 2, "Unexpected number of ips: " + ips.size()); + assertEquals(ips.iterator().next().getVersion(), PublicIP.Version.IPv4); + } - public void testListServers() { - HttpRequest request = buildGETWithQuery("Action=ListVServer" - + "&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/ListVServer-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testListServers() { + HttpRequest request = buildGETWithQuery("Action=ListVServer" + + "&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/ListVServer-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - Set servers = api.listServers("ABCDEFGH-A123B456CE"); - assertNotNull(servers, "servers"); - assertEquals(servers.size(), 2); - } + Set servers = api.listServers("ABCDEFGH-A123B456CE"); + assertNotNull(servers, "servers"); + assertEquals(servers.size(), 2); + } - public void testDisks() { - HttpRequest request = buildGETWithQuery("Action=ListVDisk" - + "&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/ListVDisk-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testDisks() { + HttpRequest request = buildGETWithQuery("Action=ListVDisk" + + "&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/ListVDisk-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - Set disks = api.listDisks("ABCDEFGH-A123B456CE"); - assertNotNull(disks, "disks"); - assertEquals(disks.size(), 1); - } + Set disks = api.listDisks("ABCDEFGH-A123B456CE"); + assertNotNull(disks, "disks"); + assertEquals(disks.size(), 1); + } - public void testListBuiltinServers() { - HttpRequest request = buildGETWithQuery("Action=ListEFM" - + "&vsysId=ABCDEFGH-A123B456CE" + "&efmType=FW"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/ListEFM-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testListBuiltinServers() { + HttpRequest request = buildGETWithQuery("Action=ListEFM" + + "&vsysId=ABCDEFGH-A123B456CE" + "&efmType=FW"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/ListEFM-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - Set fws = api.listBuiltinServers("ABCDEFGH-A123B456CE", "FW"); - assertNotNull(fws, "fws"); - assertEquals(fws.size(), 1); - } + Set fws = api.listBuiltinServers("ABCDEFGH-A123B456CE", "FW"); + assertNotNull(fws, "fws"); + assertEquals(fws.size(), 1); + } - public void testAllocatePublicIP() { - HttpRequest request = buildGETWithQuery("Action=AllocatePublicIP&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/AllocatePublicIP-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testAllocatePublicIP() { + HttpRequest request = buildGETWithQuery("Action=AllocatePublicIP&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/AllocatePublicIP-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - api.allocatePublicIP("ABCDEFGH-A123B456CE"); - } + api.allocatePublicIP("ABCDEFGH-A123B456CE"); + } - public void testCreateBuiltinServer() { - HttpRequest request = buildGETWithQuery("Action=CreateEFM" - + "&efmType=SLB" - + "&efmName=web%20load%20balancer" - + "&networkId=ABCDEFGH-A123B456CE-N-DMZ" - + "&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/CreateEFM-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testCreateBuiltinServer() { + HttpRequest request = buildGETWithQuery("Action=CreateEFM" + + "&efmType=SLB" + + "&efmName=web%20load%20balancer" + + "&networkId=ABCDEFGH-A123B456CE-N-DMZ" + + "&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/CreateEFM-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - String id = api.createBuiltinServer("web load balancer", - "ABCDEFGH-A123B456CE-N-DMZ"); - assertEquals(id, "CONTRACT-EFM00001"); - } + String id = api.createBuiltinServer("web load balancer", + "ABCDEFGH-A123B456CE-N-DMZ"); + assertEquals(id, "CONTRACT-EFM00001"); + } - public void testCreateServer() { - HttpRequest request = buildGETWithQuery("Action=CreateVServer" - + "&vserverName=vm1" - + "&diskImageId=IMG_A1B2C3_1234567890ABCD" - + "&vserverType=economy" - + "&networkId=ABCDEFGH-A123B456CE-N-DMZ" - + "&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/CreateVServer-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testCreateServer() { + HttpRequest request = buildGETWithQuery("Action=CreateVServer" + + "&vserverName=vm1" + + "&diskImageId=IMG_A1B2C3_1234567890ABCD" + + "&vserverType=economy" + + "&networkId=ABCDEFGH-A123B456CE-N-DMZ" + + "&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/CreateVServer-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - String id = api.createServer("vm1", "economy", "IMG_A1B2C3_1234567890ABCD", - "ABCDEFGH-A123B456CE-N-DMZ"); - assertEquals(id, "ABCDEFGH-A123B456CE-S-0007"); - } + String id = api.createServer("vm1", "economy", "IMG_A1B2C3_1234567890ABCD", + "ABCDEFGH-A123B456CE-N-DMZ"); + assertEquals(id, "ABCDEFGH-A123B456CE-S-0007"); + } - public void testCreateDisk() { - HttpRequest request = buildGETWithQuery("Action=CreateVDisk" - + "&vsysId=ABCDEFGH-A123B456CE" - + "&size=10" - + "&vdiskName=disk1"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/CreateVDisk-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testCreateDisk() { + HttpRequest request = buildGETWithQuery("Action=CreateVDisk" + + "&vsysId=ABCDEFGH-A123B456CE" + + "&size=10" + + "&vdiskName=disk1"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/CreateVDisk-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - String id = api.createDisk("ABCDEFGH-A123B456CE", "disk1", 10); - assertEquals(id, "ABCDEFGH-A123B456CE-S-0006"); - } + String id = api.createDisk("ABCDEFGH-A123B456CE", "disk1", 10); + assertEquals(id, "ABCDEFGH-A123B456CE-S-0006"); + } /* - public void testRegisterAsPrivateImage() { - HttpRequest request = buildGETWithQuery("Action=AllocatePublicIP&vsysId=ABCDEFGH-A123B456CE"); - HttpResponse response = HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResource("/AllocatePublicIP-response.xml")) - .build(); - VirtualSystemApi api = requestSendsResponse(request, response) - .getVirtualSystemApi(); + public void testRegisterAsPrivateImage() { + HttpRequest request = buildGETWithQuery("Action=AllocatePublicIP&vsysId=ABCDEFGH-A123B456CE"); + HttpResponse response = HttpResponse + .builder() + .statusCode(200) + .payload( + payloadFromResource("/AllocatePublicIP-response.xml")) + .build(); + VirtualSystemApi api = requestSendsResponse(request, response) + .getVirtualSystemApi(); - api.registerAsPrivateVSYSDescriptor("ABCDEFGH-A123B456CE"); - } + api.registerAsPrivateVSYSDescriptor("ABCDEFGH-A123B456CE"); + } */ } diff --git a/labs/fgcp/src/test/java/org/jclouds/http/internal/HttpInternalsLiveTest.java b/labs/fgcp/src/test/java/org/jclouds/http/internal/HttpInternalsLiveTest.java index 7ab8c2a667..e600072a1c 100644 --- a/labs/fgcp/src/test/java/org/jclouds/http/internal/HttpInternalsLiveTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/http/internal/HttpInternalsLiveTest.java @@ -31,8 +31,8 @@ import org.testng.annotations.Test; @Test(groups = "live", enabled = true, singleThreaded = true, testName = "HttpInternalsLiveTest") public class HttpInternalsLiveTest extends BaseFGCPApiLiveTest { - @Test - public void testTrustedSSLContext() { - assertNotNull(context.utils().injector().getInstance(JavaUrlHttpCommandExecutorService.class).sslContextSupplier); - } + @Test + public void testTrustedSSLContext() { + assertNotNull(context.utils().injector().getInstance(JavaUrlHttpCommandExecutorService.class).sslContextSupplier); + } } From 3a3439c9a0c9c501f9884c743113d342a1fd78a8 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 23:45:48 -0700 Subject: [PATCH 28/60] cleaned up cdmi --- .../org/jclouds/snia/cdmi/v1/CDMIApi.java | 13 +- .../jclouds/snia/cdmi/v1/CDMIApiMetadata.java | 11 +- .../jclouds/snia/cdmi/v1/CDMIAsyncApi.java | 15 +- .../org/jclouds/snia/cdmi/v1/ObjectTypes.java | 4 +- .../v1/binders/BindQueryParmsToSuffix.java | 25 +- .../cdmi/v1/config/CDMIRestClientModule.java | 16 +- .../snia/cdmi/v1/domain/CDMIObject.java | 455 +++---- .../snia/cdmi/v1/domain/Container.java | 129 +- .../snia/cdmi/v1/domain/DataObject.java | 266 ++-- .../snia/cdmi/v1/features/ContainerApi.java | 145 +- .../cdmi/v1/features/ContainerAsyncApi.java | 204 ++- .../snia/cdmi/v1/features/DataApi.java | 156 +-- .../snia/cdmi/v1/features/DataAsyncApi.java | 88 +- .../features/DataNonCDMIContentTypeApi.java | 314 +++-- .../DataNonCDMIContentTypeAsyncApi.java | 164 +-- .../snia/cdmi/v1/features/DomainApi.java | 1 - .../snia/cdmi/v1/features/DomainAsyncApi.java | 7 +- .../v1/filters/StripExtraAcceptHeader.java | 2 +- .../ParseObjectFromHeadersAndHttpContent.java | 21 +- .../v1/options/CreateCDMIObjectOptions.java | 48 +- .../v1/options/CreateContainerOptions.java | 30 +- .../CreateDataObjectNonCDMIOptions.java | 34 +- .../v1/options/CreateDataObjectOptions.java | 330 +++-- .../cdmi/v1/options/GetCDMIObjectOptions.java | 121 +- .../cdmi/v1/options/GetContainerOptions.java | 149 ++- .../v1/queryparams/CDMIObjectQueryParams.java | 126 +- .../v1/queryparams/ContainerQueryParams.java | 168 +-- .../v1/queryparams/DataObjectQueryParams.java | 175 ++- .../snia/cdmi/v1/CDMIErrorHandlerTest.java | 19 +- .../v1/features/ContainerApiExpectTest.java | 32 +- .../v1/features/ContainerApiLiveTest.java | 441 +++---- .../cdmi/v1/features/DataApiLiveTest.java | 1169 ++++++++--------- .../DataNonCDMIContentTypeApiLiveTest.java | 622 ++++----- .../cdmi/v1/internal/BaseCDMIApiLiveTest.java | 2 +- .../v1/options/ListContainersOptionsTest.java | 1 + .../cdmi/v1/parse/ParseContainerTest.java | 16 +- 36 files changed, 2588 insertions(+), 2931 deletions(-) diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApi.java index 5fcd3e6b39..a361c1a3f2 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApi.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApi.java @@ -20,6 +20,9 @@ package org.jclouds.snia.cdmi.v1; import java.util.concurrent.TimeUnit; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; import org.jclouds.snia.cdmi.v1.features.ContainerApi; @@ -48,18 +51,20 @@ public interface CDMIApi { * Provides synchronous access to Container Object Resource Operations. */ @Delegate - ContainerApi getContainerApi(); + ContainerApi getApi(); /** * Provides synchronous access to Data Object Resource Operations. */ @Delegate - DataApi getDataApi(); - + @Path("/{containerName}") + DataApi getDataApiForContainer(@PathParam("containerName") String containerName); + /** * Provides synchronous access to Data Object Resource Operations. */ @Delegate - DataNonCDMIContentTypeApi getDataNonCDMIContentTypeApi(); + @Path("/{containerName}") + DataNonCDMIContentTypeApi getDataNonCDMIContentTypeApiForContainer(@PathParam("containerName") String containerName); } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java index 0af9378e31..dd8ee87fd9 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java @@ -66,14 +66,9 @@ public class CDMIApiMetadata extends BaseRestApiMetadata { protected Builder() { super(CDMIApi.class, CDMIAsyncApi.class); - id("cdmi") - .name("SNIA CDMI API") - .identityName("tenantId:user") - .credentialName("password") - .documentation(URI.create("http://www.snia.org/cdmi")) - .version("1.0.1") - .defaultEndpoint("http://localhost:8080") - .defaultProperties(CDMIApiMetadata.defaultProperties()) + id("cdmi").name("SNIA CDMI API").identityName("tenantId:user").credentialName("password") + .documentation(URI.create("http://www.snia.org/cdmi")).version("1.0.1") + .defaultEndpoint("http://localhost:8080").defaultProperties(CDMIApiMetadata.defaultProperties()) .defaultModules(ImmutableSet.> of(CDMIRestClientModule.class)); } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncApi.java index a23670fe2a..8be45e56bd 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncApi.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncApi.java @@ -18,9 +18,13 @@ */ package org.jclouds.snia.cdmi.v1; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + import org.jclouds.rest.annotations.Delegate; import org.jclouds.snia.cdmi.v1.features.ContainerAsyncApi; import org.jclouds.snia.cdmi.v1.features.DataAsyncApi; +import org.jclouds.snia.cdmi.v1.features.DataNonCDMIContentTypeAsyncApi; import org.jclouds.snia.cdmi.v1.features.DomainAsyncApi; /** @@ -43,18 +47,21 @@ public interface CDMIAsyncApi { * Provides asynchronous access to Container Object Resource Operations. */ @Delegate - ContainerAsyncApi getContainerApi(); + ContainerAsyncApi getApi(); /** * Provides asynchronous access to Data Object Resource Operations. */ @Delegate - DataAsyncApi getDataApi(); + @Path("/{containerName}") + DataAsyncApi getDataApiForContainer(@PathParam("containerName") String containerName); /** * Provides asynchronous access to Data Object Resource Operations. */ @Delegate - DataAsyncApi getDataNonCDMIContentTypeApi(); - + @Path("/{containerName}") + DataNonCDMIContentTypeAsyncApi getDataNonCDMIContentTypeApiForContainer( + @PathParam("containerName") String containerName); + } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java index 17e627b0f1..d79f33e278 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java @@ -24,6 +24,6 @@ package org.jclouds.snia.cdmi.v1; */ public interface ObjectTypes { - public static final String CONTAINER = "application/cdmi-container"; - public static final String DATAOBJECT = "application/cdmi-object"; + public static final String CONTAINER = "application/cdmi-container"; + public static final String DATAOBJECT = "application/cdmi-object"; } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/binders/BindQueryParmsToSuffix.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/binders/BindQueryParmsToSuffix.java index d2fa4cf880..3ea4fa8539 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/binders/BindQueryParmsToSuffix.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/binders/BindQueryParmsToSuffix.java @@ -20,29 +20,28 @@ package org.jclouds.snia.cdmi.v1.binders; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; + import javax.inject.Singleton; + import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; import org.jclouds.snia.cdmi.v1.queryparams.CDMIObjectQueryParams; /** - * This binding solves the problem jax-rs encoding ? ; : which some servers can - * not handle + * This binding solves the problem jax-rs encoding ? ; : which some servers can not handle * * @author Kenneth Nagin */ @Singleton public class BindQueryParmsToSuffix implements Binder { - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object input) { - checkArgument( - checkNotNull(input, "input") instanceof CDMIObjectQueryParams, - "this binder is only valid for CDMIObjectQueryParams!"); - checkNotNull(request, "request"); - String queryParams = input.toString(); - return (R) request.toBuilder() - .endpoint(request.getEndpoint() + "?" + queryParams).build(); - } + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + checkArgument(checkNotNull(input, "input") instanceof CDMIObjectQueryParams, + "this binder is only valid for CDMIObjectQueryParams!"); + checkNotNull(request, "request"); + String queryParams = input.toString(); + return (R) request.toBuilder().endpoint(request.getEndpoint() + "?" + queryParams).build(); + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java index 2004e8cd0d..161951f66b 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java @@ -26,16 +26,16 @@ import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; -import org.jclouds.snia.cdmi.v1.CDMIAsyncApi; import org.jclouds.snia.cdmi.v1.CDMIApi; -import org.jclouds.snia.cdmi.v1.features.ContainerAsyncApi; +import org.jclouds.snia.cdmi.v1.CDMIAsyncApi; import org.jclouds.snia.cdmi.v1.features.ContainerApi; -import org.jclouds.snia.cdmi.v1.features.DataAsyncApi; +import org.jclouds.snia.cdmi.v1.features.ContainerAsyncApi; import org.jclouds.snia.cdmi.v1.features.DataApi; +import org.jclouds.snia.cdmi.v1.features.DataAsyncApi; import org.jclouds.snia.cdmi.v1.features.DataNonCDMIContentTypeApi; import org.jclouds.snia.cdmi.v1.features.DataNonCDMIContentTypeAsyncApi; -import org.jclouds.snia.cdmi.v1.features.DomainAsyncApi; import org.jclouds.snia.cdmi.v1.features.DomainApi; +import org.jclouds.snia.cdmi.v1.features.DomainAsyncApi; import org.jclouds.snia.cdmi.v1.handlers.CDMIErrorHandler; import com.google.common.collect.ImmutableMap; @@ -48,10 +48,10 @@ import com.google.common.collect.ImmutableMap; @ConfiguresRestClient public class CDMIRestClientModule extends RestClientModule { - public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder().put( - DomainApi.class, DomainAsyncApi.class).put(ContainerApi.class, ContainerAsyncApi.class).put( - DataApi.class, DataAsyncApi.class).put( - DataNonCDMIContentTypeApi.class, DataNonCDMIContentTypeAsyncApi.class).build(); + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() + .put(DomainApi.class, DomainAsyncApi.class).put(ContainerApi.class, ContainerAsyncApi.class) + .put(DataApi.class, DataAsyncApi.class) + .put(DataNonCDMIContentTypeApi.class, DataNonCDMIContentTypeAsyncApi.class).build(); public CDMIRestClientModule() { super(DELEGATE_MAP); diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java index a8437c01e3..dea0b740eb 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java @@ -42,269 +42,250 @@ import com.google.common.collect.Maps; */ public class CDMIObject { - public static Builder builder() { - return new ConcreteBuilder(); - } + public static Builder builder() { + return new ConcreteBuilder(); + } - public Builder toBuilder() { - return builder().fromCDMIObject(this); - } + public Builder toBuilder() { + return builder().fromCDMIObject(this); + } - private static class ConcreteBuilder extends Builder { - } + private static class ConcreteBuilder extends Builder { + } - public static abstract class Builder> { - private String objectID; - private String objectType; - private String objectName; - private String parentURI; + public static abstract class Builder> { + private String objectID; + private String objectType; + private String objectName; + private String parentURI; - private Map metadata = Maps.newHashMap(); + private Map metadata = Maps.newHashMap(); - /** - * @see DataObject#getMetadata() - */ - public B metadata(Map metadata) { - this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, - "metadata")); - return self(); - } + /** + * @see DataObject#getMetadata() + */ + public B metadata(Map metadata) { + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + return self(); + } - @SuppressWarnings("unchecked") - protected B self() { - return (B) this; - } + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } - /** - * @see CDMIObject#getObjectID() - */ - public B objectID(String objectID) { - this.objectID = objectID; - return self(); - } + /** + * @see CDMIObject#getObjectID() + */ + public B objectID(String objectID) { + this.objectID = objectID; + return self(); + } - /** - * @see CDMIObject#getObjectType() - */ - public B objectType(String objectType) { - this.objectType = objectType; - return self(); - } + /** + * @see CDMIObject#getObjectType() + */ + public B objectType(String objectType) { + this.objectType = objectType; + return self(); + } - /** - * @see CDMIObject#getObjectName() - */ - public B objectName(String objectName) { - this.objectName = objectName; - return self(); - } + /** + * @see CDMIObject#getObjectName() + */ + public B objectName(String objectName) { + this.objectName = objectName; + return self(); + } - /** - * @see CDMIObject#getParentURI() - */ - public B parentURI(String parentURI) { - this.parentURI = parentURI; - return self(); - } + /** + * @see CDMIObject#getParentURI() + */ + public B parentURI(String parentURI) { + this.parentURI = parentURI; + return self(); + } - public CDMIObject build() { - return new CDMIObject(this); - } + public CDMIObject build() { + return new CDMIObject(this); + } - protected B fromCDMIObject(CDMIObject in) { - return objectID(in.getObjectID()).objectType(in.getObjectType()) - .objectName(in.getObjectName()) - .parentURI(in.getParentURI()).metadata(in.getMetadata()); - } - } + protected B fromCDMIObject(CDMIObject in) { + return objectID(in.getObjectID()).objectType(in.getObjectType()).objectName(in.getObjectName()) + .parentURI(in.getParentURI()).metadata(in.getMetadata()); + } + } - private final String objectID; - private final String objectType; - private final String objectName; - private String parentURI; - private final Map metadata; - private Map userMetaDataIn; - private Map systemMetaDataIn; - private List> aclMetaDataIn; + private final String objectID; + private final String objectType; + private final String objectName; + private String parentURI; + private final Map metadata; + private Map userMetaDataIn; + private Map systemMetaDataIn; + private List> aclMetaDataIn; - protected CDMIObject(Builder builder) { - this.objectID = checkNotNull(builder.objectID, "objectID"); - this.objectType = checkNotNull(builder.objectType, "objectType"); - this.objectName = builder.objectName; - this.parentURI = checkNotNull(builder.parentURI, "parentURI"); - this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata, - "metadata")); - } + protected CDMIObject(Builder builder) { + this.objectID = checkNotNull(builder.objectID, "objectID"); + this.objectType = checkNotNull(builder.objectType, "objectType"); + this.objectName = builder.objectName; + this.parentURI = checkNotNull(builder.parentURI, "parentURI"); + this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata, "metadata")); + } - /** - * Object ID of the object
- * Every object stored within a CDMI-compliant system shall have a globally - * unique object identifier (ID) assigned at creation time. The CDMI object - * ID is a string with requirements for how it is generated and how it - * obtains its uniqueness. Each offering that implements CDMI is able to - * produce these identifiers without conflicting with other offerings. - * - * note: CDMI Servers do not always support ObjectID tags, however - * downstream jclouds code does not handle null so we return a empty String - * instead. - */ - public String getObjectID() { - return (objectID == null) ? "" : objectID; - } + /** + * Object ID of the object
+ * Every object stored within a CDMI-compliant system shall have a globally unique object + * identifier (ID) assigned at creation time. The CDMI object ID is a string with requirements + * for how it is generated and how it obtains its uniqueness. Each offering that implements CDMI + * is able to produce these identifiers without conflicting with other offerings. + * + * note: CDMI Servers do not always support ObjectID tags, however downstream jclouds code does + * not handle null so we return a empty String instead. + */ + public String getObjectID() { + return (objectID == null) ? "" : objectID; + } - /** - * - * type of the object - */ - public String getObjectType() { - return objectType; - } + /** + * + * type of the object + */ + public String getObjectType() { + return objectType; + } - /** - * For objects in a container, the objectName field shall be returned. For - * objects not in a container (objects that are only accessible by ID), the - * objectName field shall not be returned. - * - * Name of the object - */ - @Nullable - public String getObjectName() { - return (objectName == null) ? "" : objectName; - } + /** + * For objects in a container, the objectName field shall be returned. For objects not in a + * container (objects that are only accessible by ID), the objectName field shall not be + * returned. + * + * Name of the object + */ + @Nullable + public String getObjectName() { + return (objectName == null) ? "" : objectName; + } - /** - * - * parent URI - */ - public String getParentURI() { - return parentURI; - } + /** + * + * parent URI + */ + public String getParentURI() { + return parentURI; + } - /** - * Metadata for the CDMI object. This field includes any user and system - * metadata specified in the request body metadata field, along with storage - * system metadata generated by the cloud storage system. - */ - public Map getMetadata() { - return metadata; - } + /** + * Metadata for the CDMI object. This field includes any user and system metadata specified in + * the request body metadata field, along with storage system metadata generated by the cloud + * storage system. + */ + public Map getMetadata() { + return metadata; + } - /** - * Parse Metadata for the container object from the original JsonBall. - * System metadata data is prefixed with cdmi. System ACL metadata data is - * prefixed with cdmi_acl - * - */ - private void parseMetadata() { - userMetaDataIn = new HashMap(); - systemMetaDataIn = new HashMap(); - aclMetaDataIn = new ArrayList>(); - Iterator keys = metadata.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - JsonBall value = metadata.get(key); - if (key.startsWith("cdmi")) { - if (key.matches("cdmi_acl")) { - String[] cdmi_acl_array = value.toString().split("[{}]"); - for (int i = 0; i < cdmi_acl_array.length; i++) { - if (!(cdmi_acl_array[i].startsWith("[") - || cdmi_acl_array[i].startsWith("]") || cdmi_acl_array[i] - .startsWith(","))) { - HashMap aclMap = new HashMap(); - String[] cdmi_acl_member = cdmi_acl_array[i] - .split(","); - for (String s : cdmi_acl_member) { - String cdmi_acl_key = s.substring(0, - s.indexOf(":")); - String cdmi_acl_value = s.substring(s - .indexOf(":") + 1); - cdmi_acl_value.replace('"', ' ').trim(); - aclMap.put(cdmi_acl_key, cdmi_acl_value); - } - aclMetaDataIn.add(aclMap); - } - } - } else { - systemMetaDataIn.put(key, value.toString() - .replace('"', ' ').trim()); - } - } else { - userMetaDataIn.put(key, value.toString().replace('"', ' ') - .trim()); - } - } - } + /** + * Parse Metadata for the container object from the original JsonBall. System metadata data is + * prefixed with cdmi. System ACL metadata data is prefixed with cdmi_acl + * + */ + private void parseMetadata() { + userMetaDataIn = new HashMap(); + systemMetaDataIn = new HashMap(); + aclMetaDataIn = new ArrayList>(); + Iterator keys = metadata.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + JsonBall value = metadata.get(key); + if (key.startsWith("cdmi")) { + if (key.matches("cdmi_acl")) { + String[] cdmi_acl_array = value.toString().split("[{}]"); + for (int i = 0; i < cdmi_acl_array.length; i++) { + if (!(cdmi_acl_array[i].startsWith("[") || cdmi_acl_array[i].startsWith("]") || cdmi_acl_array[i] + .startsWith(","))) { + HashMap aclMap = new HashMap(); + String[] cdmi_acl_member = cdmi_acl_array[i].split(","); + for (String s : cdmi_acl_member) { + String cdmi_acl_key = s.substring(0, s.indexOf(":")); + String cdmi_acl_value = s.substring(s.indexOf(":") + 1); + cdmi_acl_value.replace('"', ' ').trim(); + aclMap.put(cdmi_acl_key, cdmi_acl_value); + } + aclMetaDataIn.add(aclMap); + } + } + } else { + systemMetaDataIn.put(key, value.toString().replace('"', ' ').trim()); + } + } else { + userMetaDataIn.put(key, value.toString().replace('"', ' ').trim()); + } + } + } - /** - * Get User Metadata for the container object. This field includes any user - * metadata - */ - public Map getUserMetadata() { - if (userMetaDataIn == null) { - parseMetadata(); - } - return userMetaDataIn; - } + /** + * Get User Metadata for the container object. This field includes any user metadata + */ + public Map getUserMetadata() { + if (userMetaDataIn == null) { + parseMetadata(); + } + return userMetaDataIn; + } - /** - * Get System Metadata for the container object excluding ACL related - * metadata - */ - public Map getSystemMetadata() { - if (systemMetaDataIn == null) { - parseMetadata(); - } - return systemMetaDataIn; - } + /** + * Get System Metadata for the container object excluding ACL related metadata + */ + public Map getSystemMetadata() { + if (systemMetaDataIn == null) { + parseMetadata(); + } + return systemMetaDataIn; + } - /** - * Get System Metadata for the container object excluding ACL related - * metadata - */ - public List> getACLMetadata() { - if (aclMetaDataIn == null) { - parseMetadata(); - } - return aclMetaDataIn; - } + /** + * Get System Metadata for the container object excluding ACL related metadata + */ + public List> getACLMetadata() { + if (aclMetaDataIn == null) { + parseMetadata(); + } + return aclMetaDataIn; + } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - CDMIObject that = CDMIObject.class.cast(o); - return equal(this.objectID, that.objectID) - && equal(this.objectName, that.objectName) - && equal(this.objectType, that.objectType) - && equal(this.parentURI, that.parentURI) - && equal(this.metadata, that.metadata); - } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + CDMIObject that = CDMIObject.class.cast(o); + return equal(this.objectID, that.objectID) && equal(this.objectName, that.objectName) + && equal(this.objectType, that.objectType) && equal(this.parentURI, that.parentURI) + && equal(this.metadata, that.metadata); + } - public boolean clone(Object o) { - if (this == o) - return false; - if (o == null || getClass() != o.getClass()) - return false; - CDMIObject that = CDMIObject.class.cast(o); - return equal(this.objectType, that.objectType); - } + public boolean clone(Object o) { + if (this == o) + return false; + if (o == null || getClass() != o.getClass()) + return false; + CDMIObject that = CDMIObject.class.cast(o); + return equal(this.objectType, that.objectType); + } - @Override - public int hashCode() { - return Objects.hashCode(objectID, objectName, objectType, parentURI, - metadata); - } + @Override + public int hashCode() { + return Objects.hashCode(objectID, objectName, objectType, parentURI, metadata); + } - @Override - public String toString() { - return string().toString(); - } + @Override + public String toString() { + return string().toString(); + } - protected ToStringHelper string() { - return Objects.toStringHelper("").add("objectID", objectID) - .add("objectName", objectName).add("objectType", objectType) - .add("parentURI", parentURI).add("metadata", metadata); - } + protected ToStringHelper string() { + return Objects.toStringHelper("").add("objectID", objectID).add("objectName", objectName) + .add("objectType", objectType).add("parentURI", parentURI).add("metadata", metadata); + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java index 21dee5e811..852a34aa0b 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java @@ -33,87 +33,80 @@ import com.google.common.collect.ImmutableSet; */ public class Container extends CDMIObject { - public static Builder builder() { - return new ConcreteBuilder(); - } + public static Builder builder() { + return new ConcreteBuilder(); + } - @Override - public Builder toBuilder() { - return builder().fromContainer(this); - } + @Override + public Builder toBuilder() { + return builder().fromContainer(this); + } - public static class Builder> extends - CDMIObject.Builder { + public static class Builder> extends CDMIObject.Builder { - private Set children = ImmutableSet.of(); + private Set children = ImmutableSet.of(); - /** - * @see Container#getChildren() - */ - public B children(String... children) { - return children(ImmutableSet.copyOf(checkNotNull(children, - "children"))); - } + /** + * @see Container#getChildren() + */ + public B children(String... children) { + return children(ImmutableSet.copyOf(checkNotNull(children, "children"))); + } - /** - * @see Container#getChildren() - */ - public B children(Set children) { - this.children = ImmutableSet.copyOf(checkNotNull(children, - "children")); - return self(); - } + /** + * @see Container#getChildren() + */ + public B children(Set children) { + this.children = ImmutableSet.copyOf(checkNotNull(children, "children")); + return self(); + } + @Override + public Container build() { + return new Container(this); + } - @Override - public Container build() { - return new Container(this); - } + public B fromContainer(Container in) { + return fromCDMIObject(in).children(in.getChildren()); + // .metadata(in.getMetadata()); + } + } - public B fromContainer(Container in) { - return fromCDMIObject(in).children(in.getChildren()); - // .metadata(in.getMetadata()); - } - } + private static class ConcreteBuilder extends Builder { + } - private static class ConcreteBuilder extends Builder { - } + private final Set children; - private final Set children; + protected Container(Builder builder) { + super(builder); + this.children = ImmutableSet.copyOf(checkNotNull(builder.children, "children")); + } - protected Container(Builder builder) { - super(builder); - this.children = ImmutableSet.copyOf(checkNotNull(builder.children, - "children")); - } + /** + * Names of the children objects in the container object. Child container objects end with "/". + */ + public Set getChildren() { + return children; + } - /** - * Names of the children objects in the container object. Child container - * objects end with "/". - */ - public Set getChildren() { - return children; - } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Container that = Container.class.cast(o); + return super.equals(that) && equal(this.children, that.children); + } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), children); + } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Container that = Container.class.cast(o); - return super.equals(that) && equal(this.children, that.children); - } - - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), children); - } - - @Override - public ToStringHelper string() { - return super.string().add("children", children); - } + @Override + public ToStringHelper string() { + return super.string().add("children", children); + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/DataObject.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/DataObject.java index f78ac12970..855e500aaa 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/DataObject.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/DataObject.java @@ -39,161 +39,155 @@ import com.google.common.io.InputSupplier; */ public class DataObject extends CDMIObject { - public static Builder builder() { - return new ConcreteBuilder(); - } + public static Builder builder() { + return new ConcreteBuilder(); + } - @Override - public Builder toBuilder() { - return builder().fromDataObject(this); - } + @Override + public Builder toBuilder() { + return builder().fromDataObject(this); + } - public static class Builder> extends - CDMIObject.Builder { - private String mimetype = new String(); - private String value = new String(); + public static class Builder> extends CDMIObject.Builder { + private String mimetype = new String(); + private String value = new String(); - /** - * @see DataObject#getMimetype() - */ - public B mimetype(String mimetype) { - this.mimetype = mimetype; - return self(); - } + /** + * @see DataObject#getMimetype() + */ + public B mimetype(String mimetype) { + this.mimetype = mimetype; + return self(); + } - /** - * @see DataObject#getValueAsString() - */ - public B value(String value) { - this.value = value; - return self(); - } + /** + * @see DataObject#getValueAsString() + */ + public B value(String value) { + this.value = value; + return self(); + } - @Override - public DataObject build() { - return new DataObject(this); - } + @Override + public DataObject build() { + return new DataObject(this); + } - public B fromDataObject(DataObject in) { - return fromCDMIObject(in).mimetype(in.getMimetype()); - } - } + public B fromDataObject(DataObject in) { + return fromCDMIObject(in).mimetype(in.getMimetype()); + } + } - private static class ConcreteBuilder extends Builder { - } + private static class ConcreteBuilder extends Builder { + } - private final String mimetype; - private final String value; + private final String mimetype; + private final String value; - protected DataObject(Builder builder) { - super(builder); - this.mimetype = checkNotNull(builder.mimetype, "mimetype"); - this.value = checkNotNull(builder.value, "value"); - } + protected DataObject(Builder builder) { + super(builder); + this.mimetype = checkNotNull(builder.mimetype, "mimetype"); + this.value = checkNotNull(builder.value, "value"); + } - /** - * get dataObject's mimetype. - */ - public String getMimetype() { - return mimetype; - } + /** + * get dataObject's mimetype. + */ + public String getMimetype() { + return mimetype; + } - /** - * get dataObject's value as a String - */ - public String getValueAsString() { - return value; - } + /** + * get dataObject's value as a String + */ + public String getValueAsString() { + return value; + } - /** - * get dataObject's value as a InputStream value character set is - * Charsets.UTF_8 - * - * @return value - */ - public InputSupplier getValueAsInputSupplier() { - return ByteStreams.newInputStreamSupplier(value.getBytes(Charsets.UTF_8)); - } + /** + * get dataObject's value as a InputStream value character set is Charsets.UTF_8 + * + * @return value + */ + public InputSupplier getValueAsInputSupplier() { + return ByteStreams.newInputStreamSupplier(value.getBytes(Charsets.UTF_8)); + } - /** - * get dataObject's value as a InputStream - * - * @param charset - * value character set - * @return value - */ - public InputSupplier getValueAsInputSupplier(Charset charset) { - return ByteStreams.newInputStreamSupplier(value.getBytes(charset)); - } + /** + * get dataObject's value as a InputStream + * + * @param charset + * value character set + * @return value + */ + public InputSupplier getValueAsInputSupplier(Charset charset) { + return ByteStreams.newInputStreamSupplier(value.getBytes(charset)); + } - /** - * get dataObject's value as a ByteArray value character set is - * Charsets.UTF_8 - * - * @return value - */ - public byte[] getValueAsByteArray() { - return value.getBytes(Charsets.UTF_8); - } + /** + * get dataObject's value as a ByteArray value character set is Charsets.UTF_8 + * + * @return value + */ + public byte[] getValueAsByteArray() { + return value.getBytes(Charsets.UTF_8); + } - /** - * get dataObject's value as a InputStream - * - * @param charset - * value character set - * @return value - */ - public byte[] getValueAsByteArray(Charset charset) { - return value.getBytes(charset); - } + /** + * get dataObject's value as a InputStream + * + * @param charset + * value character set + * @return value + */ + public byte[] getValueAsByteArray(Charset charset) { + return value.getBytes(charset); + } - /** - * get dataObject's value as a File value character set is Charsets.UTF_8 - * - * @param destDir - * destination directory - * @return value - */ - public File getValueAsFile(File destDir) throws IOException { - File fileOut = new File(destDir, this.getObjectName()); - Files.copy(getValueAsInputSupplier(), fileOut); - return fileOut; - } - + /** + * get dataObject's value as a File value character set is Charsets.UTF_8 + * + * @param destDir + * destination directory + * @return value + */ + public File getValueAsFile(File destDir) throws IOException { + File fileOut = new File(destDir, this.getObjectName()); + Files.copy(getValueAsInputSupplier(), fileOut); + return fileOut; + } - /** - * get dataObject's value as a File - * - * @param charset - * value character set - * @return value - */ - public File getValueAsFile(File destDir, Charset charset) - throws IOException { - File fileOut = new File(destDir, this.getObjectName()); - Files.copy(getValueAsInputSupplier(charset), fileOut); - return fileOut; - } + /** + * get dataObject's value as a File + * + * @param charset + * value character set + * @return value + */ + public File getValueAsFile(File destDir, Charset charset) throws IOException { + File fileOut = new File(destDir, this.getObjectName()); + Files.copy(getValueAsInputSupplier(charset), fileOut); + return fileOut; + } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - DataObject that = DataObject.class.cast(o); - return super.equals(that) && equal(this.mimetype, that.mimetype) - && equal(this.value, that.value); - } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + DataObject that = DataObject.class.cast(o); + return super.equals(that) && equal(this.mimetype, that.mimetype) && equal(this.value, that.value); + } - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), mimetype, value); - } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), mimetype, value); + } - @Override - public ToStringHelper string() { - return super.string().add("mimetype", mimetype); - } + @Override + public ToStringHelper string() { + return super.string().add("mimetype", mimetype); + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerApi.java index 728d99c33e..fe3b1ae555 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerApi.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerApi.java @@ -35,80 +35,83 @@ import org.jclouds.snia.cdmi.v1.queryparams.ContainerQueryParams; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface ContainerApi { - /** - * get CDMI Container - * - * @param containerName - * containerName must end with a forward slash, /. - * @return Container - *

-	 *  Examples: 
-	 *  {@code
-	 *  container = getContainer("myContainer/");
-	 *  container = getContainer("parentContainer/childContainer/");
-	 *  }
-	 *  
-	 */
-	Container getContainer(String containerName);
+   /**
+    * get CDMI Container
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @return Container
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  container = get("myContainer/");
+    *  container = get("parentContainer/childContainer/");
+    * }
+    * 
+    *         
+    */
+   Container get(String containerName);
 
-	/**
-	 * get CDMI Container
-	 * 
-	 * @param containerName
-	 * @param queryParams
-	 *            enables getting only certain fields, metadata, children range
-	 * @return Container
-	 * 
-	 * Examples: 
-	 * {@code
-	 * container = getContainer("myContainer/",ContainerQueryParams.Builder.mimetype("text/plain").field("objectName"))
-	 * container = getContainer("myContainer/",ContainerQueryParams.Builder.metadata().field("objectName"))
-	 * }
-	 * 
- * @see ContainerQueryParams - */ - Container getContainer(String containerName, - ContainerQueryParams queryParams); + /** + * get CDMI Container + * + * @param containerName + * @param queryParams + * enables getting only certain fields, metadata, children range + * @return Container + * + *
+    * Examples: 
+    * {@code
+    * container = get("myContainer/",ContainerQueryParams.Builder.mimetype("text/plain").field("objectName"))
+    * container = get("myContainer/",ContainerQueryParams.Builder.metadata().field("objectName"))
+    * }
+    * 
+ * @see ContainerQueryParams + */ + Container get(String containerName, ContainerQueryParams queryParams); - /** - * Create CDMI Container - * - * @param containerName - * containerName must end with a forward slash, /. - * @return Container - *
-	 *  Examples: 
-	 *  {@code
-	 *  container = createContainer("myContainer/");
-	 *  container = createContainer("parentContainer/childContainer/");
-	 *  }
-	 *  
- */ - Container createContainer(String containerName); + /** + * Create CDMI Container + * + * @param containerName + * containerName must end with a forward slash, /. + * @return Container + * + *
+    *  Examples: 
+    *  {@code
+    *  container = create("myContainer/");
+    *  container = create("parentContainer/childContainer/");
+    *  }
+    * 
+ */ + Container create(String containerName); - /** - * Create CDMI Container - * - * @param containerName - * @param options - * enables adding metadata - * @return Container - *
-	 *  Examples: 
-	 *  {@code
-	 *  container = createContainer("myContainer/",CreateContainerOptions.Builder..metadata(metaDataIn));
-	 *  }
-	 *  
- * @see CreateContainerOptions - */ - Container createContainer(String containerName, - CreateContainerOptions... options); + /** + * Create CDMI Container + * + * @param containerName + * @param options + * enables adding metadata + * @return Container + * + *
+    *  Examples: 
+    *  {@code
+    *  container = create("myContainer/",CreateContainerOptions.Builder..metadata(metaDataIn));
+    *  }
+    * 
+ * @see CreateContainerOptions + */ + Container create(String containerName, CreateContainerOptions... options); - /** - * Delete CDMI Container - * - * @param containerName - */ - void deleteContainer(String containerName); + /** + * Delete CDMI Container + * + * @param containerName + */ + void delete(String containerName); } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncApi.java index 84cec5f6be..8e9c0763c6 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncApi.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncApi.java @@ -26,6 +26,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; + import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.Headers; @@ -39,6 +40,7 @@ import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId; import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader; import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions; import org.jclouds.snia.cdmi.v1.queryparams.ContainerQueryParams; + import com.google.common.util.concurrent.ListenableFuture; /** @@ -49,115 +51,111 @@ import com.google.common.util.concurrent.ListenableFuture; * @see api doc */ @SkipEncoding({ '/', '=' }) -@RequestFilters({ BasicAuthenticationAndTenantId.class, - StripExtraAcceptHeader.class }) +@RequestFilters({ BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class }) @Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}") public interface ContainerAsyncApi { - /** - * get CDMI Container - * - * @param containerName - * containerName must end with a forward slash, /. - * @return Container - * - *
-	 *  Examples: 
-	 *  {@code
-	 *  container = getContainer("myContainer/");
-	 *  container = getContainer("parentContainer/childContainer/");
-	 * }
-	 * 
-	 * 
-	 */
-	@GET
-	@Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}")
-	ListenableFuture getContainer(
-			@PathParam("containerName") String containerName);
+   /**
+    * get CDMI Container
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @return Container
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  container = get("myContainer/");
+    *  container = get("parentContainer/childContainer/");
+    * }
+    * 
+    *         
+    */
+   @GET
+   @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{containerName}")
+   ListenableFuture get(@PathParam("containerName") String containerName);
 
-	/**
-	 * get CDMI Container
-	 * 
-	 * @param containerName
-	 * @param queryParams
-	 *            enables getting only certain fields, metadata, children range
-	 * @return Container
-	 * 
-	 * 
-	 * Examples: 
-	 * {@code
-	 * container = getContainer("myContainer/",ContainerQueryParams.Builder.field("parentURI").field("objectName"))
-	 * container = getContainer("myContainer/",ContainerQueryParams.Builder.metadata().field("objectName"))
-	 * }
-	 * 
- * @see ContainerQueryParams - */ - @GET - @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("/{containerName}") - ListenableFuture getContainer( - @PathParam("containerName") String containerName, - @BinderParam(BindQueryParmsToSuffix.class) ContainerQueryParams queryParams); + /** + * get CDMI Container + * + * @param containerName + * @param queryParams + * enables getting only certain fields, metadata, children range + * @return Container + * + *
+    * Examples: 
+    * {@code
+    * container = get("myContainer/",ContainerQueryParams.Builder.field("parentURI").field("objectName"))
+    * container = get("myContainer/",ContainerQueryParams.Builder.metadata().field("objectName"))
+    * }
+    * 
+ * @see ContainerQueryParams + */ + @GET + @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("/{containerName}") + ListenableFuture get(@PathParam("containerName") String containerName, + @BinderParam(BindQueryParmsToSuffix.class) ContainerQueryParams queryParams); - /** - * Create CDMI Container - * - * @param containerName - * containerName must end with a forward slash, /. - * @return Container - *
-	 *  Examples: 
-	 *  {@code
-	 *  container = createContainer("myContainer/");
-	 *  container = createContainer("parentContainer/childContainer/");
-	 *  }
-	 *  
- */ - @PUT - @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) - @Produces({ ObjectTypes.CONTAINER }) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("/{containerName}") - ListenableFuture createContainer( - @PathParam("containerName") String containerName); + /** + * Create CDMI Container + * + * @param containerName + * containerName must end with a forward slash, /. + * @return Container + * + *
+    *  Examples: 
+    *  {@code
+    *  container = create("myContainer/");
+    *  container = create("parentContainer/childContainer/");
+    *  }
+    * 
+ */ + @PUT + @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) + @Produces({ ObjectTypes.CONTAINER }) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("/{containerName}") + ListenableFuture create(@PathParam("containerName") String containerName); - /** - * Create CDMI Container - * - * @param containerName - * @param options - * enables adding metadata - * @return Container - *
-	 *  Examples: 
-	 *  {@code
-	 *  container = createContainer("myContainer/",CreateContainerOptions.Builder..metadata(metaDataIn));
-	 *  }
-	 *  
- * @see CreateContainerOptions - */ - @PUT - @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) - @Produces({ ObjectTypes.CONTAINER }) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("/{containerName}") - ListenableFuture createContainer( - @PathParam("containerName") String containerName, - CreateContainerOptions... options); + /** + * Create CDMI Container + * + * @param containerName + * @param options + * enables adding metadata + * @return Container + * + *
+    *  Examples: 
+    *  {@code
+    *  container = create("myContainer/",CreateContainerOptions.Builder..metadata(metaDataIn));
+    *  }
+    * 
+ * @see CreateContainerOptions + */ + @PUT + @Consumes({ ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) + @Produces({ ObjectTypes.CONTAINER }) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("/{containerName}") + ListenableFuture create(@PathParam("containerName") String containerName, + CreateContainerOptions... options); - /** - * Delete Container - * - * @param containerName - */ - @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("/{containerName}") - ListenableFuture deleteContainer( - @PathParam("containerName") String containerName); + /** + * Delete Container + * + * @param containerName + */ + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("/{containerName}") + ListenableFuture delete(@PathParam("containerName") String containerName); } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataApi.java index c85a945240..935047ee07 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataApi.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataApi.java @@ -19,6 +19,7 @@ package org.jclouds.snia.cdmi.v1.features; import java.util.concurrent.TimeUnit; + import org.jclouds.concurrent.Timeout; import org.jclouds.snia.cdmi.v1.domain.DataObject; import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions; @@ -33,83 +34,86 @@ import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams; */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface DataApi { - /** - * get CDMI Data object - * - * @param containerName - * containerName must end with a forward slash, /. - * @param dataObjectName - * dataObjectName must not end with a forward slash, /. - * @return DataObject - *
-	 *  Examples: 
-	 *  {@code
-	 *  dataObject = getDataObject("myContainer/","myDataObject");
-	 *  dataObject = getDataObject("parentContainer/childContainer/","myDataObject");
-	 *  }
-	 *  
-	 */
-	DataObject getDataObject(String containerName, String dataObjectName);
-	/**
-	 * get CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /. 
-	 * @param queryParams 
-	 *            enables getting only certain fields, metadata, value range
-	 * @return DataObject
-	 *  
-	 *  Examples: 
-	 *  {@code
-	 *  dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.field("parentURI").field("objectName"));
-	 *  dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.value(0,10));
-	 *  }
-	 *  
-	 */
-	DataObject getDataObject(String containerName, String dataObjectName,
-			DataObjectQueryParams queryParams);
+   /**
+    * get CDMI Data object
+    * 
+    * 
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @return DataObject
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  dataObject = get("myDataObject");
+    *  dataObject = get("parentContainer/childContainer","myDataObject");
+    * }
+    * 
+    *         
+    */
+   DataObject get(String dataObjectName);
 
-	/**
-	 * create CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /. 
-	 * @param options 
-	 *            enables defining the body i.e. metadata, mimetype, value
-	 * @return DataObject
-	 *  
-	 *  Examples: 
-	 *  {@code
-	 *  dataObject = createDataObject("myContainer/",
-	 *                                "myDataObject",
-	 *                                CreateDataObjectOptions.Builder
-	 *                                                    .value(value)
-	 *                                                    .mimetype("text/plain")
-	 *                                                    .metadata(pDataObjectMetaDataIn);
-	 *  }
-	 *  
-	 */	
-	DataObject createDataObject(String containerName, String dataObjectName,
-			CreateDataObjectOptions... options);
+   /**
+    * get CDMI Data object
+    * 
+    * 
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param queryParams
+    *           enables getting only certain fields, metadata, value range
+    * @return DataObject
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  dataObject = get("myDataObject",ContainerQueryParams.Builder.field("parentURI").field("objectName"));
+    *  dataObject = get("myDataObject",ContainerQueryParams.Builder.value(0,10));
+    * }
+    * 
+    *         
+    */
+   DataObject get(String dataObjectName, DataObjectQueryParams queryParams);
 
-	/**
-	 * delete CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param  dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.           
-	 *  
-	 *  Examples: 
-	 *  {@code
-	 *  deleteDataObject("myContainer/","myDataObject");
-	 *  }
-	 *  
-	 */
-	void deleteDataObject(String containerName, String dataObjectName);
+   /**
+    * create CDMI Data object
+    * 
+    * 
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param options
+    *           enables defining the body i.e. metadata, mimetype, value
+    * @return DataObject
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  dataObject = create(
+    *                                "myDataObject",
+    *                                CreateDataObjectOptions.Builder
+    *                                                    .value(value)
+    *                                                    .mimetype("text/plain")
+    *                                                    .metadata(pDataObjectMetaDataIn);
+    * }
+    * 
+    *         
+    */
+   DataObject create(String dataObjectName, CreateDataObjectOptions... options);
+
+   /**
+    * delete CDMI Data object
+    * 
+    * 
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * 
+    *           
+    *  Examples: 
+    *  {@code
+    *  delete("myDataObject");
+    * }
+    * 
+    *           
+    */
+   void delete(String dataObjectName);
 
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncApi.java
index 7ae1216935..6fe8841bca 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncApi.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncApi.java
@@ -51,60 +51,48 @@ import com.google.common.util.concurrent.ListenableFuture;
  * @see api doc
  */
 @SkipEncoding({ '/', '=' })
-@RequestFilters({ BasicAuthenticationAndTenantId.class,
-		StripExtraAcceptHeader.class })
+@RequestFilters({ BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class })
 @Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
 public interface DataAsyncApi {
-	/**
-	 * @see DataApi#getDataObject(String containerName, String dataObjectName)
-	 */
-	@GET
-	@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture getDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName);
+   /**
+    * @see DataApi#get(String dataObjectName)
+    */
+   @GET
+   @Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture get(@PathParam("dataObjectName") String dataObjectName);
 
-	/**
-	 * @see DataApi#getDataObject(String containerName, String dataObjectName,
-	 *      DataObjectQueryParams queryParams)
-	 */
-	@GET
-	@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture getDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			@BinderParam(BindQueryParmsToSuffix.class) DataObjectQueryParams queryParams);
+   /**
+    * @see DataApi#get(String dataObjectName, DataObjectQueryParams queryParams)
+    */
+   @GET
+   @Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture get(@PathParam("dataObjectName") String dataObjectName,
+            @BinderParam(BindQueryParmsToSuffix.class) DataObjectQueryParams queryParams);
 
-	/**
-	 * @see DataApi#createDataObject(String containerName, String
-	 *      dataObjectName, CreateDataObjectOptions... options)
-	 */
-	@PUT
-	@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
-	@Produces({ ObjectTypes.DATAOBJECT })
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture createDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			CreateDataObjectOptions... options);
+   /**
+    * @see DataApi#create(String dataObjectName, CreateDataObjectOptions... options)
+    */
+   @PUT
+   @Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
+   @Produces({ ObjectTypes.DATAOBJECT })
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture create(@PathParam("dataObjectName") String dataObjectName,
+            CreateDataObjectOptions... options);
 
-	/**
-	 * @see DataApi#deleteDataObject(String containerName, String
-	 *      dataObjectName)
-	 */
-	@DELETE
-	@Consumes(MediaType.TEXT_PLAIN)
-	// note: MediaType.APPLICATION_JSON work also, however without consumes
-	// jclouds throws null exception
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture deleteDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName);
+   /**
+    * @see DataApi#delete(String dataObjectName)
+    */
+   @DELETE
+   @Consumes(MediaType.TEXT_PLAIN)
+   // note: MediaType.APPLICATION_JSON work also, however without consumes
+   // jclouds throws null exception
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture delete(@PathParam("dataObjectName") String dataObjectName);
 
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApi.java
index 91b797fe4f..593565e2c2 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApi.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApi.java
@@ -19,6 +19,7 @@
 package org.jclouds.snia.cdmi.v1.features;
 
 import java.util.concurrent.TimeUnit;
+
 import org.jclouds.concurrent.Timeout;
 import org.jclouds.io.Payload;
 import org.jclouds.snia.cdmi.v1.domain.DataObject;
@@ -33,172 +34,163 @@ import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
  */
 @Timeout(duration = 600, timeUnit = TimeUnit.SECONDS)
 public interface DataNonCDMIContentTypeApi {
-	/**
-	 * get CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * @return DataObjectNonCDMIContentType
-	 * 
-	 *         
-	 *  Examples: 
-	 *  {@code
-	 *  dataObject = getDataObject("myContainer/","myDataObject");
-	 *  dataObject = getDataObject("parentContainer/childContainer/","myDataObject");
-	 * }
-	 * 
-	 * 
-	 * @see DataNonCDMIContentTypeAsyncApi#getDataObjectValue(String containerName, String dataObjectName)
-	 */
-	Payload getDataObjectValue(String containerName, String dataObjectName);
+   /**
+    * get CDMI Data object
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @return DataObjectNonCDMIContentType
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  dataObject = get("myDataObject");
+    *  dataObject = get("parentContainer/childContainer/","myDataObject");
+    * }
+    * 
+    * 
+    * @see DataNonCDMIContentTypeAsyncApi#getValue(String dataObjectName)
+    */
+   Payload getValue(String dataObjectName);
 
-	/**
-	 * get CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * @param range
-	 *            a valid ranges-specifier (see RFC2616 Section 14.35.1)
-	 * @return DataObjectNonCDMIContentType
-	 * 
-	 *         
-	 *  Examples: 
-	 *  {@code
-	 *  dataObject = getDataObject("myContainer/","myDataObject","bytes=0-10");
-	 * }
-	 * 
-	 *         
-	 */
-	Payload getDataObjectValue(String containerName, String dataObjectName,
-			String range);
+   /**
+    * get CDMI Data object
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param range
+    *           a valid ranges-specifier (see RFC2616 Section 14.35.1)
+    * @return DataObjectNonCDMIContentType
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  dataObject = get("myDataObject","bytes=0-10");
+    * }
+    * 
+    *         
+    */
+   Payload getValue(String dataObjectName, String range);
 
-	/**
-	 * get CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * @param queryParams
-	 *            enables getting only certain fields, metadata, value range
-	 * @return DataObject
-	 * 
-	 *         
-	 *  Examples: 
-	 *  {@code
-	 *  dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.field("parentURI").field("objectName"));
-	 *  dataObject = getContainer("myContainer/","myDataObject",ContainerQueryParams.Builder.value(0,10));
-	 * }
-	 * 
-	 *         
-	 */
-	DataObject getDataObject(String containerName, String dataObjectName,
-			DataObjectQueryParams queryParams);
+   /**
+    * get CDMI Data object
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param queryParams
+    *           enables getting only certain fields, metadata, value range
+    * @return DataObject
+    * 
+    *         
+    *  Examples: 
+    *  {@code
+    *  dataObject = get("myDataObject",ContainerQueryParams.Builder.field("parentURI").field("objectName"));
+    *  dataObject = get("myDataObject",ContainerQueryParams.Builder.value(0,10));
+    * }
+    * 
+    *         
+    */
+   DataObject get(String dataObjectName, DataObjectQueryParams queryParams);
 
-	/**
-	 * create CDMI Data object Non CDMI Content Type
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * @param payload
-	 *            enables defining the body's payload i.e. file, inputStream,
-	 *            String, ByteArray
-	 * 
-	 *            
-	 *  Examples: 
-	 *  {@code
-	 *  createDataObject("myContainer/","myDataObject",new StringPayload("value");
-	 *  createDataObject("myContainer/","myDataObject",new ByteArrayPayload(bytes);
-	 *  createDataObject("myContainer/","myDataObject",new FilePayload(myFileIn);
-	 *  createDataObject("myContainer/","myDataObject",new InputStreamPayload(is);
-	 *  
-	 *  File f = new File("yellow-flowers.jpg");
-	 *  payloadIn = new InputStreamPayload(new FileInputStream(f));
-	 *  payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(
-	 *            payloadIn.getContentMetadata().toBuilder()
-	 *            .contentType(MediaType.JPEG.toString())
-	 *            .contentLength(new Long(inFile.length()))
-	 *            .build()));
-	 *  dataNonCDMIContentTypeApi.createDataObject(containerName, f.getName(),
-	 * 					payloadIn);
-	 * }
-	 * 
-	 *            
-	 */
-	void createDataObject(String containerName, String dataObjectName,
-			Payload payload);
+   /**
+    * create CDMI Data object Non CDMI Content Type
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param payload
+    *           enables defining the body's payload i.e. file, inputStream, String, ByteArray
+    * 
+    *           
+    *  Examples: 
+    *  {@code
+    *  create("myDataObject",new StringPayload("value");
+    *  create("myDataObject",new ByteArrayPayload(bytes);
+    *  create("myDataObject",new FilePayload(myFileIn);
+    *  create("myDataObject",new InputStreamPayload(is);
+    *  
+    *  File f = new File("yellow-flowers.jpg");
+    *  payloadIn = new InputStreamPayload(new FileInputStream(f));
+    *  payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(
+    *            payloadIn.getContentMetadata().toBuilder()
+    *            .contentType(MediaType.JPEG.toString())
+    *            .contentLength(new Long(inFile.length()))
+    *            .build()));
+    *  dataNonCDMIContentTypeApi.create(containerName, f.getName(),
+    * 					payloadIn);
+    * }
+    * 
+    *           
+    */
+   void create(String dataObjectName, Payload payload);
 
-	/**
-	 * create CDMI Data object partial Non CDMI Content Type Only part of the
-	 * object is contained in the payload and the X-CDMI-Partial header flag is
-	 * set to true
-	 * 
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * @param payload
-	 *            enables defining the body's payload i.e. file, inputStream,
-	 *            String, ByteArray
-	 * 
-	 *            
-	 *  Examples: 
-	 *  {@code
-	 *  createDataObjectPartial("myContainer/","myDataObject",new StringPayload("value");
-	 *  createDataObjectPartial("myContainer/","myDataObject",new ByteArrayPayload(bytes);
-	 *  createDataObjectPartial("myContainer/","myDataObject",new FilePayload(myFileIn);
-	 *  createDataObjectPartial("myContainer/","myDataObject",new InputStreamPayload(is);
-	 * }
-	 * 
-	 *            
-	 */
-	void createDataObjectPartial(String containerName, String dataObjectName,
-			Payload payload);
+   /**
+    * create CDMI Data object partial Non CDMI Content Type Only part of the object is contained in
+    * the payload and the X-CDMI-Partial header flag is set to true
+    * 
+    * 
+    * 
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param payload
+    *           enables defining the body's payload i.e. file, inputStream, String, ByteArray
+    * 
+    *           
+    *  Examples: 
+    *  {@code
+    *  createPartial("myDataObject",new StringPayload("value");
+    *  createPartial("myDataObject",new ByteArrayPayload(bytes);
+    *  createPartial("myDataObject",new FilePayload(myFileIn);
+    *  createPartial("myDataObject",new InputStreamPayload(is);
+    * }
+    * 
+    *           
+    */
+   void createPartial(String dataObjectName, Payload payload);
 
-	/**
-	 * create CDMI Data object Non CDMI Content Type
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * @param inputString
-	 *            simple string input
-	 * 
-	 *            
-	 *  Examples: 
-	 *  {@code
-	 *  createDataObject("myContainer/","myDataObject",new String("value");
-	 * }
-	 * 
-	 *            
-	 */
-	void createDataObject(String containerName, String dataObjectName,
-			String inputString);
+   /**
+    * create CDMI Data object Non CDMI Content Type
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * @param inputString
+    *           simple string input
+    * 
+    *           
+    *  Examples: 
+    *  {@code
+    *  create("myDataObject",new String("value");
+    * }
+    * 
+    *           
+    */
+   void create(String dataObjectName, String inputString);
 
-	/**
-	 * delete CDMI Data object
-	 * 
-	 * @param containerName
-	 *            containerName must end with a forward slash, /.
-	 * @param dataObjectName
-	 *            dataObjectName must not end with a forward slash, /.
-	 * 
-	 *            
-	 *  Examples: 
-	 *  {@code
-	 *  deleteDataObject("myContainer/","myDataObject");
-	 * }
-	 * 
-	 *            
-	 */
-	void deleteDataObject(String containerName, String dataObjectName);
+   /**
+    * delete CDMI Data object
+    * 
+    * @param containerName
+    *           containerName must end with a forward slash, /.
+    * @param dataObjectName
+    *           dataObjectName must not end with a forward slash, /.
+    * 
+    *           
+    *  Examples: 
+    *  {@code
+    *  delete("myDataObject");
+    * }
+    * 
+    *           
+    */
+   void delete(String dataObjectName);
 
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeAsyncApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeAsyncApi.java
index f44630d713..b58f80b472 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeAsyncApi.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeAsyncApi.java
@@ -21,15 +21,17 @@ package org.jclouds.snia.cdmi.v1.features;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
-import javax.ws.rs.HeaderParam;
 import javax.ws.rs.core.MediaType;
+
 import org.jclouds.rest.annotations.BinderParam;
 import org.jclouds.rest.annotations.ExceptionParser;
 import org.jclouds.rest.annotations.Headers;
+import org.jclouds.rest.annotations.Payload;
 import org.jclouds.rest.annotations.PayloadParam;
 import org.jclouds.rest.annotations.RequestFilters;
 import org.jclouds.rest.annotations.ResponseParser;
@@ -39,10 +41,10 @@ import org.jclouds.snia.cdmi.v1.binders.BindQueryParmsToSuffix;
 import org.jclouds.snia.cdmi.v1.domain.DataObject;
 import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
 import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
-import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
 import org.jclouds.snia.cdmi.v1.functions.ParseObjectFromHeadersAndHttpContent;
+import org.jclouds.snia.cdmi.v1.queryparams.DataObjectQueryParams;
+
 import com.google.common.util.concurrent.ListenableFuture;
-import org.jclouds.rest.annotations.Payload;
 
 /**
  * Non CDMI Content Type Data Object Resource Operations
@@ -53,103 +55,79 @@ import org.jclouds.rest.annotations.Payload;
  * @see api doc
  */
 @SkipEncoding({ '/', '=' })
-@RequestFilters({ BasicAuthenticationAndTenantId.class,
-		StripExtraAcceptHeader.class })
+@RequestFilters({ BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class })
 public interface DataNonCDMIContentTypeAsyncApi {
-	/**
-	 * @see DataNonCDMIContentTypeApi#getDataObjectValue(String containerName,
-	 *      String dataObjectName)
-	 */
-	@GET
-	@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
-	@ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture getDataObjectValue(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName);
+   /**
+    * @see DataNonCDMIContentTypeApi#getValue(String dataObjectName)
+    */
+   @GET
+   @Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+   @ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture getValue(@PathParam("dataObjectName") String dataObjectName);
 
-	/**
-	 * @see DataNonCDMIContentTypeApi#getDataObjectValue(String containerName,
-	 *      String dataObjectName, String range )
-	 */
+   /**
+    * @see DataNonCDMIContentTypeApi#getValue(String dataObjectName, String range )
+    */
 
-	@GET
-	@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
-	@ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture getDataObjectValue(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			@HeaderParam("Range") String range);
+   @GET
+   @Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+   @ResponseParser(ParseObjectFromHeadersAndHttpContent.class)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture getValue(@PathParam("dataObjectName") String dataObjectName,
+            @HeaderParam("Range") String range);
 
-	/**
-	 * @see DataNonCDMIContentTypeApi#getDataObject(String containerName, String
-	 *      dataObjectName, DataObjectQueryParams queryParams )
-	 */
-	@GET
-	@Consumes(MediaType.APPLICATION_JSON)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture getDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			@BinderParam(BindQueryParmsToSuffix.class) DataObjectQueryParams queryParams);
+   /**
+    * @see DataNonCDMIContentTypeApi#get(String dataObjectName, DataObjectQueryParams queryParams )
+    */
+   @GET
+   @Consumes(MediaType.APPLICATION_JSON)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture get(@PathParam("dataObjectName") String dataObjectName,
+            @BinderParam(BindQueryParmsToSuffix.class) DataObjectQueryParams queryParams);
 
-	/**
-	 * @see DataNonCDMIContentTypeApi#createDataObject(String containerName,
-	 *      String dataObjectName, org.jclouds.io.Payload payload )
-	 */
-	@PUT
-	@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture createDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			org.jclouds.io.Payload payload);
+   /**
+    * @see DataNonCDMIContentTypeApi#create(String dataObjectName, org.jclouds.io.Payload payload )
+    */
+   @PUT
+   @Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture create(@PathParam("dataObjectName") String dataObjectName, org.jclouds.io.Payload payload);
 
-	/**
-	 * @see DataNonCDMIContentTypeApi#createDataObjectPartial(String
-	 *      containerName, String dataObjectName, org.jclouds.io.Payload payload
-	 *      )
-	 */
-	@PUT
-	@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	@Headers(keys = "X-CDMI-Partial", values = "true")
-	ListenableFuture createDataObjectPartial(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			org.jclouds.io.Payload payload);
+   /**
+    * @see DataNonCDMIContentTypeApi#createPartial(String dataObjectName, org.jclouds.io.Payload
+    *      payload )
+    */
+   @PUT
+   @Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   @Headers(keys = "X-CDMI-Partial", values = "true")
+   ListenableFuture createPartial(@PathParam("dataObjectName") String dataObjectName,
+            org.jclouds.io.Payload payload);
 
-	/**
-	 * @see DataNonCDMIContentTypeApi#createDataObject(String containerName,
-	 *      String dataObjectName, String input )
-	 */
-	@PUT
-	@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
-	@Produces(MediaType.TEXT_PLAIN)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	@Payload("{input}")
-	ListenableFuture createDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName,
-			@PayloadParam("input") String input);
+   /**
+    * @see DataNonCDMIContentTypeApi#create(String dataObjectName, String input )
+    */
+   @PUT
+   @Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+   @Produces(MediaType.TEXT_PLAIN)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   @Payload("{input}")
+   ListenableFuture create(@PathParam("dataObjectName") String dataObjectName, @PayloadParam("input") String input);
 
-	/**
-	 * @see DataNonCDMIContentTypeApi#deleteDataObject(String containerName,
-	 *      String dataObjectName)
-	 */
-	@DELETE
-	@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
-	@ExceptionParser(ReturnNullOnNotFoundOr404.class)
-	@Path("/{containerName}{dataObjectName}")
-	ListenableFuture deleteDataObject(
-			@PathParam("containerName") String containerName,
-			@PathParam("dataObjectName") String dataObjectName);
+   /**
+    * @see DataNonCDMIContentTypeApi#delete(String dataObjectName)
+    */
+   @DELETE
+   @Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+   @ExceptionParser(ReturnNullOnNotFoundOr404.class)
+   @Path("/{dataObjectName}")
+   ListenableFuture delete(@PathParam("dataObjectName") String dataObjectName);
 
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainApi.java
index e224e0f7ea..f3e671a260 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainApi.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainApi.java
@@ -32,5 +32,4 @@ import org.jclouds.concurrent.Timeout;
 @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
 public interface DomainApi {
 
-
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncApi.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncApi.java
index 257a93c06d..78c93fd4c8 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncApi.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncApi.java
@@ -31,10 +31,9 @@ import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
  * @author Adrian Cole
  * @see api doc
  */
-@SkipEncoding( { '/', '=' })
-@RequestFilters( { BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class })
-@Headers(keys="X-CDMI-Specification-Version", values = "{jclouds.api-version}")
+@SkipEncoding({ '/', '=' })
+@RequestFilters({ BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class })
+@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
 public interface DomainAsyncApi {
 
-
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java
index 332ff0f4ff..7380d17768 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java
@@ -34,7 +34,7 @@ import org.jclouds.http.HttpRequestFilter;
  */
 @Singleton
 public class StripExtraAcceptHeader implements HttpRequestFilter {
- 
+
    @Override
    public HttpRequest filter(HttpRequest request) throws HttpException {
       return request.toBuilder().replaceHeader("Accept", request.getFirstHeaderOrNull("Accept")).build();
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/functions/ParseObjectFromHeadersAndHttpContent.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/functions/ParseObjectFromHeadersAndHttpContent.java
index 631b5849c8..21b52e3853 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/functions/ParseObjectFromHeadersAndHttpContent.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/functions/ParseObjectFromHeadersAndHttpContent.java
@@ -30,17 +30,16 @@ import com.google.common.base.Function;
  * 
  * @author Kenneth Nagin
  */
-public class ParseObjectFromHeadersAndHttpContent implements
-		Function,
-		InvocationContext {
+public class ParseObjectFromHeadersAndHttpContent implements Function,
+         InvocationContext {
 
-	public Payload apply(HttpResponse from) {
-		Payload object = from.getPayload();
-		return object;
-	}
+   public Payload apply(HttpResponse from) {
+      Payload object = from.getPayload();
+      return object;
+   }
 
-	@Override
-	public ParseObjectFromHeadersAndHttpContent setContext(HttpRequest request) {
-		return this;
-	}
+   @Override
+   public ParseObjectFromHeadersAndHttpContent setContext(HttpRequest request) {
+      return this;
+   }
 }
diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateCDMIObjectOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateCDMIObjectOptions.java
index 47ca431c86..7fcdfc37b3 100644
--- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateCDMIObjectOptions.java
+++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateCDMIObjectOptions.java
@@ -8,34 +8,32 @@ import org.jclouds.http.options.BaseHttpRequestOptions;
 import com.google.gson.JsonObject;
 
 /**
- * Contains options supported in the REST API for the CREATE container
- * operation. 

+ * Contains options supported in the REST API for the CREATE container operation.

* * @author Kenneth Nagin */ public class CreateCDMIObjectOptions extends BaseHttpRequestOptions { - protected JsonObject jsonObjectBody = new JsonObject(); - /** - * A name-value pair to associate with the container as metadata. - */ - public CreateCDMIObjectOptions metadata(Map metadata) { - JsonObject jsonObjectMetadata = new JsonObject(); - if (metadata != null) { - for (Entry entry : metadata.entrySet()) { - jsonObjectMetadata - .addProperty(entry.getKey(), entry.getValue()); - } - } - jsonObjectBody.add("metadata", jsonObjectMetadata); - this.payload = jsonObjectBody.toString(); - return this; - } + protected JsonObject jsonObjectBody = new JsonObject(); - public static class Builder { - public static CreateCDMIObjectOptions withMetadata( - Map metadata) { - CreateCDMIObjectOptions options = new CreateCDMIObjectOptions(); - return (CreateCDMIObjectOptions) options.metadata(metadata); - } - } + /** + * A name-value pair to associate with the container as metadata. + */ + public CreateCDMIObjectOptions metadata(Map metadata) { + JsonObject jsonObjectMetadata = new JsonObject(); + if (metadata != null) { + for (Entry entry : metadata.entrySet()) { + jsonObjectMetadata.addProperty(entry.getKey(), entry.getValue()); + } + } + jsonObjectBody.add("metadata", jsonObjectMetadata); + this.payload = jsonObjectBody.toString(); + return this; + } + + public static class Builder { + public static CreateCDMIObjectOptions withMetadata(Map metadata) { + CreateCDMIObjectOptions options = new CreateCDMIObjectOptions(); + return (CreateCDMIObjectOptions) options.metadata(metadata); + } + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateContainerOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateContainerOptions.java index 39d60c7d0f..de76fe4461 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateContainerOptions.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateContainerOptions.java @@ -8,19 +8,19 @@ import java.util.Map; * @author Kenneth Nagin */ public class CreateContainerOptions extends CreateCDMIObjectOptions { - /** - * A name-value pair to associate with the container as metadata. - */ - public CreateContainerOptions metadata(Map metadata) { - super.metadata(metadata); - return this; - - } - public static class Builder { - public static CreateContainerOptions metadata( - Map metadata) { - CreateContainerOptions options = new CreateContainerOptions(); - return (CreateContainerOptions) options.metadata(metadata); - } - } + /** + * A name-value pair to associate with the container as metadata. + */ + public CreateContainerOptions metadata(Map metadata) { + super.metadata(metadata); + return this; + + } + + public static class Builder { + public static CreateContainerOptions metadata(Map metadata) { + CreateContainerOptions options = new CreateContainerOptions(); + return (CreateContainerOptions) options.metadata(metadata); + } + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectNonCDMIOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectNonCDMIOptions.java index 5ca397f403..2e0575072f 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectNonCDMIOptions.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectNonCDMIOptions.java @@ -3,30 +3,24 @@ package org.jclouds.snia.cdmi.v1.options; import org.jclouds.http.options.BaseHttpRequestOptions; /** - * Contains options supported in the REST API for the CREATE container - * operation.

+ * Contains options supported in the REST API for the CREATE container operation.

* * @author Kenneth Nagin */ public class CreateDataObjectNonCDMIOptions extends BaseHttpRequestOptions { - /** - * A name-value pair to associate with the container as metadata. - */ - public CreateDataObjectNonCDMIOptions withStringPayload(String value) { - this.payload = value; - return this; - } - + /** + * A name-value pair to associate with the container as metadata. + */ + public CreateDataObjectNonCDMIOptions withStringPayload(String value) { + this.payload = value; + return this; + } - + public static class Builder { + public static CreateDataObjectNonCDMIOptions withStringPayload(String value) { + CreateDataObjectNonCDMIOptions options = new CreateDataObjectNonCDMIOptions(); + return (CreateDataObjectNonCDMIOptions) options.withStringPayload(value); + } - public static class Builder { - public static CreateDataObjectNonCDMIOptions withStringPayload( - String value) { - CreateDataObjectNonCDMIOptions options = new CreateDataObjectNonCDMIOptions(); - return (CreateDataObjectNonCDMIOptions) options.withStringPayload(value); - } - - - } + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectOptions.java index b0738fba9c..3461db7a01 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectOptions.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/CreateDataObjectOptions.java @@ -3,208 +3,192 @@ package org.jclouds.snia.cdmi.v1.options; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.IOException; -import java.util.Map; -import com.google.common.base.Charsets; import java.nio.charset.Charset; +import java.util.Map; + +import com.google.common.base.Charsets; import com.google.common.io.CharStreams; import com.google.common.io.Files; /** - * CreateDataObjectOptions options supported in the REST API for the CREATE CDMI - * Data Object operation.

+ * CreateDataObjectOptions options supported in the REST API for the CREATE CDMI Data Object + * operation.

* * @author Kenneth Nagin */ public class CreateDataObjectOptions extends CreateCDMIObjectOptions { - public CreateDataObjectOptions() { - jsonObjectBody.addProperty("value", new String()); - } + public CreateDataObjectOptions() { + jsonObjectBody.addProperty("value", new String()); + } - /** - * Create CDMI data object with metadata - * - * @param metadata - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions metadata(Map metadata) { - super.metadata(metadata); - return this; - } + /** + * Create CDMI data object with metadata + * + * @param metadata + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions metadata(Map metadata) { + super.metadata(metadata); + return this; + } - /** - * Create CDMI data object with mimetype - * - * @param mimetype - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions mimetype(String mimetype) { - jsonObjectBody.addProperty("mimetype", mimetype); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with mimetype + * + * @param mimetype + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions mimetype(String mimetype) { + jsonObjectBody.addProperty("mimetype", mimetype); + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with value equal to empty string - * - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value() { - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with value equal to empty string + * + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value() { + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with String value - * - * @param value - * String value - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value(String value) { - jsonObjectBody.addProperty("value", (value == null) ? new String() - : value); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with String value + * + * @param value + * String value + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value(String value) { + jsonObjectBody.addProperty("value", (value == null) ? new String() : value); + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with byte array value - * - * @param value - * byte array value byte array is converted to a String value - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value(byte[] value) throws IOException { - jsonObjectBody.addProperty("value", - (value == null) ? new String() : new DataInputStream( - new ByteArrayInputStream(value)).readUTF()); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with byte array value + * + * @param value + * byte array value byte array is converted to a String value + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value(byte[] value) throws IOException { + jsonObjectBody.addProperty("value", (value == null) ? new String() : new DataInputStream( + new ByteArrayInputStream(value)).readUTF()); + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with file value - * - * @param value - * File File is converted to a String value with charset UTF_8 - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value(File value) throws IOException { - jsonObjectBody.addProperty("value", (value == null) ? new String() - : Files.toString(value, Charsets.UTF_8)); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with file value + * + * @param value + * File File is converted to a String value with charset UTF_8 + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value(File value) throws IOException { + jsonObjectBody.addProperty("value", (value == null) ? new String() : Files.toString(value, Charsets.UTF_8)); + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with file value - * - * @param value - * File - * @param charset - * character set of file File is converted to a String value - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value(File value, Charset charset) - throws IOException { - jsonObjectBody.addProperty("value", (value == null) ? new String() - : Files.toString(value, charset)); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with file value + * + * @param value + * File + * @param charset + * character set of file File is converted to a String value + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value(File value, Charset charset) throws IOException { + jsonObjectBody.addProperty("value", (value == null) ? new String() : Files.toString(value, charset)); + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with InputStream value - * - * @param value - * InputSteam InputSteam is converted to a String value with - * charset UTF_8 - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value(InputStream value) throws IOException { - jsonObjectBody - .addProperty( - "value", - (value == null) ? new String() : CharStreams - .toString(new InputStreamReader(value, - Charsets.UTF_8))); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with InputStream value + * + * @param value + * InputSteam InputSteam is converted to a String value with charset UTF_8 + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value(InputStream value) throws IOException { + jsonObjectBody.addProperty("value", + (value == null) ? new String() : CharStreams.toString(new InputStreamReader(value, Charsets.UTF_8))); + this.payload = jsonObjectBody.toString(); + return this; + } - /** - * Create CDMI data object with InputStream value - * - * @param value - * InputSteam - * @param charset - * character set of input stream InputSteam is converted to a - * String value with charset UTF_8 - * @return CreateDataObjectOptions - */ - public CreateDataObjectOptions value(InputStream value, Charset charset) - throws IOException { - jsonObjectBody.addProperty("value", (value == null) ? new String() - : CharStreams.toString(new InputStreamReader(value, charset))); - this.payload = jsonObjectBody.toString(); - return this; - } + /** + * Create CDMI data object with InputStream value + * + * @param value + * InputSteam + * @param charset + * character set of input stream InputSteam is converted to a String value with charset + * UTF_8 + * @return CreateDataObjectOptions + */ + public CreateDataObjectOptions value(InputStream value, Charset charset) throws IOException { + jsonObjectBody.addProperty("value", + (value == null) ? new String() : CharStreams.toString(new InputStreamReader(value, charset))); + this.payload = jsonObjectBody.toString(); + return this; + } - public static class Builder { - public static CreateDataObjectOptions metadata( - Map metadata) { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.metadata(metadata); - } + public static class Builder { + public static CreateDataObjectOptions metadata(Map metadata) { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.metadata(metadata); + } - public static CreateDataObjectOptions mimetype(String mimetype) { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.mimetype(mimetype); - } + public static CreateDataObjectOptions mimetype(String mimetype) { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.mimetype(mimetype); + } - public static CreateDataObjectOptions value() { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(); - } + public static CreateDataObjectOptions value() { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(); + } - public static CreateDataObjectOptions value(String value) { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(value); - } + public static CreateDataObjectOptions value(String value) { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(value); + } - public static CreateDataObjectOptions value(byte[] value) - throws IOException { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(value); - } + public static CreateDataObjectOptions value(byte[] value) throws IOException { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(value); + } - public static CreateDataObjectOptions value(File value) - throws IOException { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(value); - } + public static CreateDataObjectOptions value(File value) throws IOException { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(value); + } - public static CreateDataObjectOptions value(File value, Charset charset) - throws IOException { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(value, charset); - } + public static CreateDataObjectOptions value(File value, Charset charset) throws IOException { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(value, charset); + } - public static CreateDataObjectOptions value(InputStream value) - throws IOException { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(value); - } + public static CreateDataObjectOptions value(InputStream value) throws IOException { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(value); + } - public static CreateDataObjectOptions value(InputStream value, - Charset charset) throws IOException { - CreateDataObjectOptions options = new CreateDataObjectOptions(); - return (CreateDataObjectOptions) options.value(value, charset); - } + public static CreateDataObjectOptions value(InputStream value, Charset charset) throws IOException { + CreateDataObjectOptions options = new CreateDataObjectOptions(); + return (CreateDataObjectOptions) options.value(value, charset); + } - } + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetCDMIObjectOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetCDMIObjectOptions.java index 0a36e15508..01d5f68b26 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetCDMIObjectOptions.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetCDMIObjectOptions.java @@ -3,80 +3,77 @@ package org.jclouds.snia.cdmi.v1.options; import org.jclouds.http.options.BaseHttpRequestOptions; /** - * Optional get CDMI object options Note: We use - * BaseHttpRequestOptions.pathSuffix to include the CDMI query parameters rather - * than queryParam or MatrixParam because the CDMI specification is not - * following the standard usage. This is the summary of the CDMI specification: - * To read one or more requested fields from an existing CDMI container object, - * one of the following requests shall be performed: - * GET ///?;;... - * GET ///?children:;... - * GET ///?metadata:;... + * Optional get CDMI object options Note: We use BaseHttpRequestOptions.pathSuffix to include the + * CDMI query parameters rather than queryParam or MatrixParam because the CDMI specification is not + * following the standard usage. This is the summary of the CDMI specification: To read one or more + * requested fields from an existing CDMI container object, one of the following requests shall be + * performed: GET ///?;;... GET + * ///?children:;... GET ///?metadata:;... * - * For example: GET /MyContainer/?parentURI;children HTTP/1.1 - * GET /MyContainer/?childrenrange;children:0-2 HTTP/1.1 + * For example: GET /MyContainer/?parentURI;children HTTP/1.1 GET + * /MyContainer/?childrenrange;children:0-2 HTTP/1.1 * - * To read one or more requested fields from an existing data object, one of the - * following requests shall be performed: - * GET //?;;... - * GET //?value:;... - * GET //?metadata:;... + * To read one or more requested fields from an existing data object, one of the following requests + * shall be performed: GET //?;;... + * GET //?value:;... GET //?metadata:;... * * @author Kenneth Nagin */ public class GetCDMIObjectOptions extends BaseHttpRequestOptions { - public GetCDMIObjectOptions() { - this.pathSuffix = "?"; - } + public GetCDMIObjectOptions() { + this.pathSuffix = "?"; + } - /** - * Get CDMI data object's field - * - * @param fieldname - * @return this - */ - public GetCDMIObjectOptions field(String fieldname) { - this.pathSuffix = this.pathSuffix + fieldname + ";"; - return this; - } + /** + * Get CDMI data object's field + * + * @param fieldname + * @return this + */ + public GetCDMIObjectOptions field(String fieldname) { + this.pathSuffix = this.pathSuffix + fieldname + ";"; + return this; + } - /** - * Get CDMI data object's metadata - * - * @return this - */ - public GetCDMIObjectOptions metadata() { - this.pathSuffix = this.pathSuffix + "metadata;"; - return this; - } + /** + * Get CDMI data object's metadata + * + * @return this + */ + public GetCDMIObjectOptions metadata() { + this.pathSuffix = this.pathSuffix + "metadata;"; + return this; + } - /** - * Get CDMI data object's metadata - * - * @param prefix - * @return this - */ - public GetCDMIObjectOptions metadata(String prefix) { - this.pathSuffix = this.pathSuffix + "metadata:" + prefix + ";"; - return this; - } + /** + * Get CDMI data object's metadata + * + * @param prefix + * @return this + */ + public GetCDMIObjectOptions metadata(String prefix) { + this.pathSuffix = this.pathSuffix + "metadata:" + prefix + ";"; + return this; + } - public static class Builder { - public static GetCDMIObjectOptions field(String fieldname) { - GetCDMIObjectOptions options = new GetCDMIObjectOptions(); - return (GetCDMIObjectOptions) options.field(fieldname); - } + public static class Builder { + public static GetCDMIObjectOptions field(String fieldname) { + GetCDMIObjectOptions options = new GetCDMIObjectOptions(); + return (GetCDMIObjectOptions) options.field(fieldname); + } - public static GetCDMIObjectOptions metadata() { - GetCDMIObjectOptions options = new GetCDMIObjectOptions(); - return (GetCDMIObjectOptions) options.metadata(); - } + public static GetCDMIObjectOptions metadata() { + GetCDMIObjectOptions options = new GetCDMIObjectOptions(); + return (GetCDMIObjectOptions) options.metadata(); + } - public static GetCDMIObjectOptions metadata(String prefix) { - GetCDMIObjectOptions options = new GetCDMIObjectOptions(); - return (GetCDMIObjectOptions) options.metadata(prefix); - } + public static GetCDMIObjectOptions metadata(String prefix) { + GetCDMIObjectOptions options = new GetCDMIObjectOptions(); + return (GetCDMIObjectOptions) options.metadata(prefix); + } - } + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetContainerOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetContainerOptions.java index 105ffc193e..ab96e678e3 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetContainerOptions.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/GetContainerOptions.java @@ -1,6 +1,5 @@ package org.jclouds.snia.cdmi.v1.options; - /** * Optional get CDMI container operations * @@ -8,89 +7,89 @@ package org.jclouds.snia.cdmi.v1.options; */ public class GetContainerOptions extends GetCDMIObjectOptions { - public GetContainerOptions() { - super(); - } + public GetContainerOptions() { + super(); + } - /** - * Get CDMI container's field - * - * @param fieldname - * @return this - */ - public GetContainerOptions field(String fieldname) { - super.field(fieldname); - return this; - } + /** + * Get CDMI container's field + * + * @param fieldname + * @return this + */ + public GetContainerOptions field(String fieldname) { + super.field(fieldname); + return this; + } - /** - * Get CDMI container's metadata - * - * @return this - */ - public GetContainerOptions metadata() { - super.metadata(); - return this; - } + /** + * Get CDMI container's metadata + * + * @return this + */ + public GetContainerOptions metadata() { + super.metadata(); + return this; + } - /** - * Get CDMI container's metadata - * - * @param prefix - * @return this - */ - public GetContainerOptions metadata(String prefix) { - super.metadata(prefix); - return this; - } + /** + * Get CDMI container's metadata + * + * @param prefix + * @return this + */ + public GetContainerOptions metadata(String prefix) { + super.metadata(prefix); + return this; + } - /** - * Get CDMI container's children - * - * @return this - */ - public GetContainerOptions children() { - this.pathSuffix = this.pathSuffix + "children;"; - return this; - } + /** + * Get CDMI container's children + * + * @return this + */ + public GetContainerOptions children() { + this.pathSuffix = this.pathSuffix + "children;"; + return this; + } - /** - * Get CDMI container's children in range - * - * @param from - * @param to - * @return this - */ - public GetContainerOptions children(int from, int to) { - this.pathSuffix = this.pathSuffix + "children:" + from + "-" + to + ";"; - return this; - } + /** + * Get CDMI container's children in range + * + * @param from + * @param to + * @return this + */ + public GetContainerOptions children(int from, int to) { + this.pathSuffix = this.pathSuffix + "children:" + from + "-" + to + ";"; + return this; + } - public static class Builder { - public static GetContainerOptions field(String fieldname) { - GetContainerOptions options = new GetContainerOptions(); - return (GetContainerOptions) options.field(fieldname); - } + public static class Builder { + public static GetContainerOptions field(String fieldname) { + GetContainerOptions options = new GetContainerOptions(); + return (GetContainerOptions) options.field(fieldname); + } - public static GetContainerOptions metadata() { - GetContainerOptions options = new GetContainerOptions(); - return (GetContainerOptions) options.metadata(); - } + public static GetContainerOptions metadata() { + GetContainerOptions options = new GetContainerOptions(); + return (GetContainerOptions) options.metadata(); + } - public static GetContainerOptions metadata(String prefix) { - GetContainerOptions options = new GetContainerOptions(); - return (GetContainerOptions) options.metadata(prefix); - } + public static GetContainerOptions metadata(String prefix) { + GetContainerOptions options = new GetContainerOptions(); + return (GetContainerOptions) options.metadata(prefix); + } - public static GetContainerOptions children() { - GetContainerOptions options = new GetContainerOptions(); - return (GetContainerOptions) options.children(); - } + public static GetContainerOptions children() { + GetContainerOptions options = new GetContainerOptions(); + return (GetContainerOptions) options.children(); + } - public static GetContainerOptions children(int from, int to) { - GetContainerOptions options = new GetContainerOptions(); - return (GetContainerOptions) options.children(from, to); - } + public static GetContainerOptions children(int from, int to) { + GetContainerOptions options = new GetContainerOptions(); + return (GetContainerOptions) options.children(from, to); + } - } + } } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/CDMIObjectQueryParams.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/CDMIObjectQueryParams.java index c55bc594d0..cfd9f9b153 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/CDMIObjectQueryParams.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/CDMIObjectQueryParams.java @@ -1,80 +1,68 @@ package org.jclouds.snia.cdmi.v1.queryparams; - - -import java.util.HashMap; - -import org.jclouds.http.options.BaseHttpRequestOptions; - -import com.google.common.collect.Multimap; - /** - * Generate CDMI object query parameters - * Note: The preferred implementation would use jax-rs queryParam. - * However, the CDMI query parameters specification does not conform to - * jax-rs queryParam of key=value separated by &. - * Rather it follows the form: - * ?;;.... - * ?metadata:;... - * ?children:-;... - * ?value:-;... + * Generate CDMI object query parameters Note: The preferred implementation would use jax-rs + * queryParam. However, the CDMI query parameters specification does not conform to jax-rs + * queryParam of key=value separated by &. Rather it follows the form: ?;;.... + * ?metadata:;... ?children:-;... ?value:-;... * * @author Kenneth Nagin */ -public class CDMIObjectQueryParams { - - protected String queryParams = ""; - - public CDMIObjectQueryParams() { - super(); - } +public class CDMIObjectQueryParams { - /** - * Get CDMI data object's field value - * @param fieldname - * @return this - */ - public CDMIObjectQueryParams field(String fieldname) { - queryParams = queryParams + fieldname + ";"; - return this; - } - - /** - * Get CDMI data object's metadata - * @return this - */ - public CDMIObjectQueryParams metadata() { - queryParams = queryParams + "metadata;"; - return this; - } + protected String queryParams = ""; - /** - * Get CDMI data object's metadata associated with prefix - * @param prefix - * @return this - */ - public CDMIObjectQueryParams metadata(String prefix) { - queryParams = queryParams + "metadata:"+prefix+";"; - return this; - } - + public CDMIObjectQueryParams() { + super(); + } - public static class Builder { - public static CDMIObjectQueryParams field( - String fieldname) { - CDMIObjectQueryParams options = new CDMIObjectQueryParams(); - return (CDMIObjectQueryParams) options.field(fieldname); - } - public static CDMIObjectQueryParams metadata( - String prefix) { - CDMIObjectQueryParams options = new CDMIObjectQueryParams(); - return (CDMIObjectQueryParams) options.metadata(prefix); - } + /** + * Get CDMI data object's field value + * + * @param fieldname + * @return this + */ + public CDMIObjectQueryParams field(String fieldname) { + queryParams = queryParams + fieldname + ";"; + return this; + } + + /** + * Get CDMI data object's metadata + * + * @return this + */ + public CDMIObjectQueryParams metadata() { + queryParams = queryParams + "metadata;"; + return this; + } + + /** + * Get CDMI data object's metadata associated with prefix + * + * @param prefix + * @return this + */ + public CDMIObjectQueryParams metadata(String prefix) { + queryParams = queryParams + "metadata:" + prefix + ";"; + return this; + } + + public static class Builder { + public static CDMIObjectQueryParams field(String fieldname) { + CDMIObjectQueryParams options = new CDMIObjectQueryParams(); + return (CDMIObjectQueryParams) options.field(fieldname); + } + + public static CDMIObjectQueryParams metadata(String prefix) { + CDMIObjectQueryParams options = new CDMIObjectQueryParams(); + return (CDMIObjectQueryParams) options.metadata(prefix); + } + + } + + public String toString() { + return queryParams; + } - } - - public String toString () { - return queryParams; - } - } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/ContainerQueryParams.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/ContainerQueryParams.java index 0501940552..fe7a1f045e 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/ContainerQueryParams.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/ContainerQueryParams.java @@ -1,96 +1,98 @@ package org.jclouds.snia.cdmi.v1.queryparams; /** - * Generate CDMI container query parameters - * Example: - * container = containerApi.getContainer(containerName,ContainerQueryParams.Builder.field("parentURI")); - * container = containerApi.getContainer(containerName,ContainerQueryParams.Builder.children(0,3)); + * Generate CDMI container query parameters Example: container = + * containerApi.get(containerName,ContainerQueryParams.Builder.field("parentURI")); container = + * containerApi.get(containerName,ContainerQueryParams.Builder.children(0,3)); * * @author Kenneth Nagin */ -public class ContainerQueryParams extends CDMIObjectQueryParams { +public class ContainerQueryParams extends CDMIObjectQueryParams { - public ContainerQueryParams() { - super(); - } + public ContainerQueryParams() { + super(); + } - /** - * Get CDMI container's field value - * @param fieldname - * @return this - */ - public ContainerQueryParams field(String fieldname) { - super.field(fieldname); - return this; - } - - /** - * Get CDMI container's metadata - * @return this - */ - public ContainerQueryParams metadata() { - super.metadata(); - return this; - } + /** + * Get CDMI container's field value + * + * @param fieldname + * @return this + */ + public ContainerQueryParams field(String fieldname) { + super.field(fieldname); + return this; + } - /** - * Get CDMI container's metadata associated with prefix - * @param prefix - * @return this - */ - public ContainerQueryParams metadata(String prefix) { - super.metadata(prefix); - return this; - } - - /** - * Get CDMI container's children - * @return this - */ - public ContainerQueryParams children() { - queryParams = queryParams + "children;"; - return this; - } - - - /** - * Get CDMI container's children within range - * @param from - * @param to - * @return this - */ - public ContainerQueryParams children(int from, int to) { - queryParams = queryParams + "children:"+from+"-"+to+";"; - return this; - } + /** + * Get CDMI container's metadata + * + * @return this + */ + public ContainerQueryParams metadata() { + super.metadata(); + return this; + } + /** + * Get CDMI container's metadata associated with prefix + * + * @param prefix + * @return this + */ + public ContainerQueryParams metadata(String prefix) { + super.metadata(prefix); + return this; + } - public static class Builder { - public static ContainerQueryParams field( - String fieldname) { - ContainerQueryParams options = new ContainerQueryParams(); - return (ContainerQueryParams) options.field(fieldname); - } - public static ContainerQueryParams metadata() { - ContainerQueryParams options = new ContainerQueryParams(); - return (ContainerQueryParams) options.metadata(); - } - - public static ContainerQueryParams metadata( - String prefix) { - ContainerQueryParams options = new ContainerQueryParams(); - return (ContainerQueryParams) options.metadata(prefix); - } - public static ContainerQueryParams children() { - ContainerQueryParams options = new ContainerQueryParams(); - return (ContainerQueryParams) options.children(); - } - public static ContainerQueryParams children( - int from, int to) { - ContainerQueryParams options = new ContainerQueryParams(); - return (ContainerQueryParams) options.children(from,to); - } + /** + * Get CDMI container's children + * + * @return this + */ + public ContainerQueryParams children() { + queryParams = queryParams + "children;"; + return this; + } + + /** + * Get CDMI container's children within range + * + * @param from + * @param to + * @return this + */ + public ContainerQueryParams children(int from, int to) { + queryParams = queryParams + "children:" + from + "-" + to + ";"; + return this; + } + + public static class Builder { + public static ContainerQueryParams field(String fieldname) { + ContainerQueryParams options = new ContainerQueryParams(); + return (ContainerQueryParams) options.field(fieldname); + } + + public static ContainerQueryParams metadata() { + ContainerQueryParams options = new ContainerQueryParams(); + return (ContainerQueryParams) options.metadata(); + } + + public static ContainerQueryParams metadata(String prefix) { + ContainerQueryParams options = new ContainerQueryParams(); + return (ContainerQueryParams) options.metadata(prefix); + } + + public static ContainerQueryParams children() { + ContainerQueryParams options = new ContainerQueryParams(); + return (ContainerQueryParams) options.children(); + } + + public static ContainerQueryParams children(int from, int to) { + ContainerQueryParams options = new ContainerQueryParams(); + return (ContainerQueryParams) options.children(from, to); + } + + } - } - } diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/DataObjectQueryParams.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/DataObjectQueryParams.java index e70107f2e1..f7e8fa1823 100644 --- a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/DataObjectQueryParams.java +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/queryparams/DataObjectQueryParams.java @@ -1,103 +1,98 @@ package org.jclouds.snia.cdmi.v1.queryparams; - - -import java.util.HashMap; - -import org.jclouds.http.options.BaseHttpRequestOptions; - -import com.google.common.collect.Multimap; - /** - * Generate CDMI data object query parameters - * Example: - * dataObject = dataApi.getDataObject(containerName,dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI")); - * dataObject = dataApi.getDataObject(containerName,dataObjectNameIn,DataObjectQueryParams.Builder.value()); + * Generate CDMI data object query parameters Example: dataObject = + * dataApi.get(containerName,dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI")); + * dataObject = dataApi.get(containerName,dataObjectNameIn,DataObjectQueryParams.Builder.value()); * * @author Kenneth Nagin */ -public class DataObjectQueryParams extends CDMIObjectQueryParams { +public class DataObjectQueryParams extends CDMIObjectQueryParams { - public DataObjectQueryParams() { - super(); - } + public DataObjectQueryParams() { + super(); + } - /** - * Get CDMI data object's field value - * @param fieldname - * @return this - */ - public DataObjectQueryParams field(String fieldname) { - super.field(fieldname); - return this; - } - - /** - * Get CDMI data object's metadata - * @return this - */ - public DataObjectQueryParams metadata() { - super.metadata(); - return this; - } + /** + * Get CDMI data object's field value + * + * @param fieldname + * @return this + */ + public DataObjectQueryParams field(String fieldname) { + super.field(fieldname); + return this; + } - /** - * Get CDMI data object's metadata associated with prefix - * @param prefix - * @return this - */ - public DataObjectQueryParams metadata(String prefix) { - super.metadata(prefix); - return this; - } - - /** - * Get CDMI data object's value with range - * @return this - */ - public DataObjectQueryParams value() { - queryParams = queryParams + "value;"; - return this; - } - - - /** - * Get CDMI data object's value within range - * @param from - * @param to - * @return this - */ - public DataObjectQueryParams value(int from, int to) { - queryParams = queryParams + "value:"+from+"-"+to+";"; - return this; - } + /** + * Get CDMI data object's metadata + * + * @return this + */ + public DataObjectQueryParams metadata() { + super.metadata(); + return this; + } + /** + * Get CDMI data object's metadata associated with prefix + * + * @param prefix + * @return this + */ + public DataObjectQueryParams metadata(String prefix) { + super.metadata(prefix); + return this; + } - public static class Builder { - public static DataObjectQueryParams field( - String fieldname) { - DataObjectQueryParams options = new DataObjectQueryParams(); - return (DataObjectQueryParams) options.field(fieldname); - } - public static DataObjectQueryParams metadata() { - DataObjectQueryParams options = new DataObjectQueryParams(); - return (DataObjectQueryParams) options.metadata(); - } - public static DataObjectQueryParams metadata( - String prefix) { - DataObjectQueryParams options = new DataObjectQueryParams(); - return (DataObjectQueryParams) options.metadata(prefix); - } - public static DataObjectQueryParams value() { - DataObjectQueryParams options = new DataObjectQueryParams(); - return (DataObjectQueryParams) options.value(); - } - public static DataObjectQueryParams value( - int from, int to) { - DataObjectQueryParams options = new DataObjectQueryParams(); - return (DataObjectQueryParams) options.value(from,to); - } + /** + * Get CDMI data object's value with range + * + * @return this + */ + public DataObjectQueryParams value() { + queryParams = queryParams + "value;"; + return this; + } + + /** + * Get CDMI data object's value within range + * + * @param from + * @param to + * @return this + */ + public DataObjectQueryParams value(int from, int to) { + queryParams = queryParams + "value:" + from + "-" + to + ";"; + return this; + } + + public static class Builder { + public static DataObjectQueryParams field(String fieldname) { + DataObjectQueryParams options = new DataObjectQueryParams(); + return (DataObjectQueryParams) options.field(fieldname); + } + + public static DataObjectQueryParams metadata() { + DataObjectQueryParams options = new DataObjectQueryParams(); + return (DataObjectQueryParams) options.metadata(); + } + + public static DataObjectQueryParams metadata(String prefix) { + DataObjectQueryParams options = new DataObjectQueryParams(); + return (DataObjectQueryParams) options.metadata(prefix); + } + + public static DataObjectQueryParams value() { + DataObjectQueryParams options = new DataObjectQueryParams(); + return (DataObjectQueryParams) options.value(); + } + + public static DataObjectQueryParams value(int from, int to) { + DataObjectQueryParams options = new DataObjectQueryParams(); + return (DataObjectQueryParams) options.value(from, to); + } + + } - } - } diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java index 1e470d603a..6f8acbce5c 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java @@ -44,29 +44,30 @@ public class CDMIErrorHandlerTest { @Test public void test404SetsKeyNotFoundExceptionMosso() { - assertCodeMakes("HEAD", URI - .create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), 404, - "Not Found", "", KeyNotFoundException.class); + assertCodeMakes("HEAD", + URI.create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), + 404, "Not Found", "", KeyNotFoundException.class); } @Test public void test404SetsKeyNotFoundExceptionCDMI() { - assertCodeMakes("HEAD", URI - .create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), + assertCodeMakes( + "HEAD", + URI.create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), 404, "Not Found", "", KeyNotFoundException.class); } @Test public void test404SetsContainerNotFoundExceptionMosso() { - assertCodeMakes("HEAD", URI - .create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), 404, + assertCodeMakes("HEAD", + URI.create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), 404, "Not Found", "", ContainerNotFoundException.class); } @Test public void test404SetsContainerNotFoundExceptionCDMI() { - assertCodeMakes("HEAD", URI - .create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), + assertCodeMakes("HEAD", + URI.create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), 404, "Not Found", "", ContainerNotFoundException.class); } diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiExpectTest.java index 82a23c9405..72057425cf 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiExpectTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiExpectTest.java @@ -36,30 +36,24 @@ import com.google.common.collect.ImmutableMultimap; */ @Test(groups = "unit", testName = "ContainerAsyncApiTest") public class ContainerApiExpectTest extends BaseCDMIApiExpectTest { - + public void testGetContainerWhenResponseIs2xx() throws Exception { - HttpRequest getContainer = HttpRequest.builder() - .method("GET") - .endpoint("http://localhost:8080/MyContainer/") - .headers(ImmutableMultimap. builder() - .put("X-CDMI-Specification-Version", "1.0.1") + HttpRequest get = HttpRequest + .builder() + .method("GET") + .endpoint("http://localhost:8080/MyContainer/") + .headers(ImmutableMultimap. builder().put("X-CDMI-Specification-Version", "1.0.1") .put("TID", "tenantId") .put("Authorization", "Basic " + CryptoStreams.base64("username:password".getBytes())) - .put("Accept", "application/cdmi-container") - .build()) - .build(); - - HttpResponse getContainerResponse = HttpResponse.builder() - .statusCode(200) - .payload(payloadFromResource("/container.json")) - .build(); + .put("Accept", "application/cdmi-container").build()).build(); - CDMIApi apiWhenContainersExist = requestSendsResponse(getContainer, getContainerResponse); + HttpResponse getResponse = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/container.json")) + .build(); - assertEquals( - apiWhenContainersExist.getContainerApi().getContainer("MyContainer/"), - new ParseContainerTest().expected()); + CDMIApi apiWhenContainersExist = requestSendsResponse(get, getResponse); + + assertEquals(apiWhenContainersExist.getApi().get("MyContainer/"), new ParseContainerTest().expected()); } - + } diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiLiveTest.java index 53bfe159dd..7ad4537acc 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiLiveTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerApiLiveTest.java @@ -43,247 +43,224 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "ContainerApiLiveTest") public class ContainerApiLiveTest extends BaseCDMIApiLiveTest { - @Test - public void testCreateContainer() throws Exception { - String pContainerName = "MyContainer" + System.currentTimeMillis() + "/"; - Map pContainerMetaDataIn = new HashMap(); - Iterator keys; - pContainerMetaDataIn.put("containerkey1", "value1"); - pContainerMetaDataIn.put("containerkey2", "value2"); - pContainerMetaDataIn.put("containerkey3", "value3"); + @Test + public void testCreateContainer() throws Exception { + String pContainerName = "MyContainer" + System.currentTimeMillis() + "/"; + Map pContainerMetaDataIn = new HashMap(); + Iterator keys; + pContainerMetaDataIn.put("containerkey1", "value1"); + pContainerMetaDataIn.put("containerkey2", "value2"); + pContainerMetaDataIn.put("containerkey3", "value3"); - CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder - .metadata(pContainerMetaDataIn); - ContainerApi api = cdmiContext.getApi().getContainerApi(); + CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn); + ContainerApi api = cdmiContext.getApi().getApi(); - Logger.getAnonymousLogger().info("createContainer: " + pContainerName); + Logger.getAnonymousLogger().info("create: " + pContainerName); - Container container = api.createContainer(pContainerName, - pCreateContainerOptions); - assertNotNull(container); - try { - System.out.println(container); - Logger.getAnonymousLogger().info("getContainer: " + pContainerName); - container = api.getContainer(pContainerName); - assertNotNull(container); - System.out.println(container); - assertEquals(container.getObjectType(), ObjectTypes.CONTAINER); - assertNotNull(container.getObjectID()); - assertNotNull(container.getObjectName()); - assertEquals(container.getObjectName(), pContainerName); - assertEquals(container.getParentURI(), "/"); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().isEmpty(), true); - System.out.println("Children: " + container.getChildren()); - assertNotNull(container.getMetadata()); - System.out.println("Raw metadata: " + container.getMetadata()); - keys = container.getMetadata().keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - JsonBall value = container.getMetadata().get(key); - System.out.println(key + ":" + value); - } - assertNotNull(container.getUserMetadata()); - Map pContainerMetaDataOut = container - .getUserMetadata(); - keys = pContainerMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(pContainerMetaDataOut.containsKey(key), true); - assertEquals(pContainerMetaDataOut.get(key), - pContainerMetaDataIn.get(key)); - } - System.out.println("UserMetaData: " + container.getUserMetadata()); - assertNotNull(container.getSystemMetadata()); - System.out.println("SystemMetaData: " - + container.getSystemMetadata()); - assertNotNull(container.getACLMetadata()); - assertEquals(container.getACLMetadata().size(),3); - List> aclMetadataOut = container - .getACLMetadata(); - System.out.println("ACLMetaData: "); - for (Map aclMap : aclMetadataOut) { - System.out.println(aclMap); - } - container = api.getContainer("/"); - System.out.println("root container: " + container); - assertEquals( - container.getChildren().contains(pContainerName), - true); - System.out.println("adding containers to container"); - String firstParentURI = api.getContainer(pContainerName).getObjectName(); - for(int i=0;i<10;i++) { -// container = api.createContainer(firstParentURI+"childcontainer"+i+"/"); - container = api.createContainer(pContainerName+"childcontainer"+i+"/"); - assertNotNull(container); - System.out.println(container); - assertEquals(container.getParentURI(),pContainerName); - assertEquals(container.getObjectName(),"childcontainer"+i+"/"); - container = api.createContainer(container.getParentURI()+container.getObjectName()+"grandchild/"); - assertEquals(container.getParentURI(),pContainerName+"childcontainer"+i+"/"); - assertEquals(container.getObjectName(),"grandchild/"); - System.out.println(container); - } - container = api.getContainer(pContainerName); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().size(), 10); - - } finally { - Logger.getAnonymousLogger().info( - "deleteContainer: " + pContainerName); - api.deleteContainer(pContainerName); - container = api.getContainer("/"); - System.out.println("root container: " + container); - assertEquals( - container.getChildren().contains(pContainerName), - false); - } + Container container = api.create(pContainerName, pCreateContainerOptions); + assertNotNull(container); + try { + System.out.println(container); + Logger.getAnonymousLogger().info("get: " + pContainerName); + container = api.get(pContainerName); + assertNotNull(container); + System.out.println(container); + assertEquals(container.getObjectType(), ObjectTypes.CONTAINER); + assertNotNull(container.getObjectID()); + assertNotNull(container.getObjectName()); + assertEquals(container.getObjectName(), pContainerName); + assertEquals(container.getParentURI(), "/"); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().isEmpty(), true); + System.out.println("Children: " + container.getChildren()); + assertNotNull(container.getMetadata()); + System.out.println("Raw metadata: " + container.getMetadata()); + keys = container.getMetadata().keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + JsonBall value = container.getMetadata().get(key); + System.out.println(key + ":" + value); + } + assertNotNull(container.getUserMetadata()); + Map pContainerMetaDataOut = container.getUserMetadata(); + keys = pContainerMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(pContainerMetaDataOut.containsKey(key), true); + assertEquals(pContainerMetaDataOut.get(key), pContainerMetaDataIn.get(key)); + } + System.out.println("UserMetaData: " + container.getUserMetadata()); + assertNotNull(container.getSystemMetadata()); + System.out.println("SystemMetaData: " + container.getSystemMetadata()); + assertNotNull(container.getACLMetadata()); + assertEquals(container.getACLMetadata().size(), 3); + List> aclMetadataOut = container.getACLMetadata(); + System.out.println("ACLMetaData: "); + for (Map aclMap : aclMetadataOut) { + System.out.println(aclMap); + } + container = api.get("/"); + System.out.println("root container: " + container); + assertEquals(container.getChildren().contains(pContainerName), true); + System.out.println("adding containers to container"); + String firstParentURI = api.get(pContainerName).getObjectName(); + for (int i = 0; i < 10; i++) { + // container = api.create(firstParentURI+"childcontainer"+i+"/"); + container = api.create(pContainerName + "childcontainer" + i + "/"); + assertNotNull(container); + System.out.println(container); + assertEquals(container.getParentURI(), pContainerName); + assertEquals(container.getObjectName(), "childcontainer" + i + "/"); + container = api.create(container.getParentURI() + container.getObjectName() + "grandchild/"); + assertEquals(container.getParentURI(), pContainerName + "childcontainer" + i + "/"); + assertEquals(container.getObjectName(), "grandchild/"); + System.out.println(container); + } + container = api.get(pContainerName); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().size(), 10); - } - - @Test - public void testGetContainer() throws Exception { - String pContainerName = "MyContainer" + System.currentTimeMillis() + "/"; - Map pContainerMetaDataIn = new HashMap(); - Iterator keys; - pContainerMetaDataIn.put("containerkey1", "value1"); - pContainerMetaDataIn.put("containerkey2", "value2"); - pContainerMetaDataIn.put("containerkey3", "value3"); - CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder - .metadata(pContainerMetaDataIn); - ContainerApi api = cdmiContext.getApi().getContainerApi(); + } finally { + Logger.getAnonymousLogger().info("delete: " + pContainerName); + api.delete(pContainerName); + container = api.get("/"); + System.out.println("root container: " + container); + assertEquals(container.getChildren().contains(pContainerName), false); + } - Logger.getAnonymousLogger().info("createContainer: " + pContainerName); + } - Container container = api.createContainer(pContainerName, - pCreateContainerOptions); - assertNotNull(container); - try { - System.out.println(container); - Logger.getAnonymousLogger().info("getContainer: " + pContainerName); - container = api.getContainer(pContainerName); - assertNotNull(container); - System.out.println(container); - assertEquals(container.getObjectType(), ObjectTypes.CONTAINER); - assertNotNull(container.getObjectID()); - assertNotNull(container.getObjectName()); - assertEquals(container.getObjectName(), pContainerName); - assertEquals(container.getParentURI(), "/"); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().isEmpty(), true); - System.out.println("Children: " + container.getChildren()); - assertNotNull(container.getMetadata()); - System.out.println("Raw metadata: " + container.getMetadata()); - keys = container.getMetadata().keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - JsonBall value = container.getMetadata().get(key); - System.out.println(key + ":" + value); - } - assertNotNull(container.getUserMetadata()); - Map pContainerMetaDataOut = container - .getUserMetadata(); - keys = pContainerMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(pContainerMetaDataOut.containsKey(key), true); - assertEquals(pContainerMetaDataOut.get(key), - pContainerMetaDataIn.get(key)); - } - System.out.println("UserMetaData: " + container.getUserMetadata()); - assertNotNull(container.getSystemMetadata()); - System.out.println("SystemMetaData: " - + container.getSystemMetadata()); - assertNotNull(container.getACLMetadata()); - List> aclMetadataOut = container - .getACLMetadata(); - System.out.println("ACLMetaData: "); - for (Map aclMap : aclMetadataOut) { - System.out.println(aclMap); - } - container = api.getContainer("/"); - System.out.println("root container: " + container); - assertEquals( - container.getChildren().contains(pContainerName), - true); - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.field("parentURI")); - assertNotNull(container); - assertEquals(container.getParentURI(),"/"); - System.out.println(container); - - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.field("parentURI").field("objectName")); - assertNotNull(container); - assertEquals(container.getParentURI(),"/"); - assertEquals(container.getObjectName(),pContainerName); + @Test + public void testGetContainer() throws Exception { + String pContainerName = "MyContainer" + System.currentTimeMillis() + "/"; + Map pContainerMetaDataIn = new HashMap(); + Iterator keys; + pContainerMetaDataIn.put("containerkey1", "value1"); + pContainerMetaDataIn.put("containerkey2", "value2"); + pContainerMetaDataIn.put("containerkey3", "value3"); + CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn); + ContainerApi api = cdmiContext.getApi().getApi(); - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.metadata()); - assertNotNull(container); - pContainerMetaDataOut = container.getUserMetadata(); - keys = pContainerMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(pContainerMetaDataOut.containsKey(key), true); - assertEquals(pContainerMetaDataOut.get(key), - pContainerMetaDataIn.get(key)); - } - System.out.println(container); - - System.out.println("GetContainerOptions.Builder.metadata(cdmi_acl)"); - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.metadata("cdmi_acl")); - assertNotNull(container); - System.out.println(container); - assertNotNull(container.getACLMetadata()); - assertEquals(container.getACLMetadata().size(),3); + Logger.getAnonymousLogger().info("create: " + pContainerName); - - System.out.println("adding containers to container"); - String firstParentURI = api.getContainer(pContainerName).getObjectName(); - for(int i=0;i<10;i++) { - container = api.createContainer(firstParentURI+"childcontainer"+i+"/"); - assertNotNull(container); - assertEquals(container.getParentURI(),pContainerName); - assertEquals(container.getObjectName(),"childcontainer"+i+"/"); - container = api.createContainer(container.getParentURI()+container.getObjectName()+"grandchild/",pCreateContainerOptions); - assertEquals(container.getParentURI(),pContainerName+"childcontainer"+i+"/"); - assertEquals(container.getObjectName(),"grandchild"+"/"); - container = api.getContainer(container.getParentURI(),ContainerQueryParams.Builder.children()); - assertEquals(container.getChildren().contains("grandchild"+"/"),true); - } - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.children()); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().size(), 10); - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.children(0,3)); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().size(), 4); - - container = api.getContainer(pContainerName,ContainerQueryParams.Builder.field("parentURI").field("objectName").children().metadata()); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().size(), 10); - assertEquals(container.getParentURI(),"/"); - assertEquals(container.getObjectName(),pContainerName); - assertEquals(container.getParentURI(),"/"); - assertEquals(container.getACLMetadata().size(),3); - for(String childName: container.getChildren()){ - api.deleteContainer(container.getObjectName()+ childName); - } - assertEquals(api.getContainer(pContainerName,ContainerQueryParams.Builder.children()).getChildren().isEmpty(),true); - - } finally { - Logger.getAnonymousLogger().info( - "deleteContainer: " + pContainerName); - api.deleteContainer(pContainerName); - container = api.getContainer("/"); - System.out.println("root container: " + container); - assertEquals( - container.getChildren().contains(pContainerName), - false); - } + Container container = api.create(pContainerName, pCreateContainerOptions); + assertNotNull(container); + try { + System.out.println(container); + Logger.getAnonymousLogger().info("get: " + pContainerName); + container = api.get(pContainerName); + assertNotNull(container); + System.out.println(container); + assertEquals(container.getObjectType(), ObjectTypes.CONTAINER); + assertNotNull(container.getObjectID()); + assertNotNull(container.getObjectName()); + assertEquals(container.getObjectName(), pContainerName); + assertEquals(container.getParentURI(), "/"); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().isEmpty(), true); + System.out.println("Children: " + container.getChildren()); + assertNotNull(container.getMetadata()); + System.out.println("Raw metadata: " + container.getMetadata()); + keys = container.getMetadata().keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + JsonBall value = container.getMetadata().get(key); + System.out.println(key + ":" + value); + } + assertNotNull(container.getUserMetadata()); + Map pContainerMetaDataOut = container.getUserMetadata(); + keys = pContainerMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(pContainerMetaDataOut.containsKey(key), true); + assertEquals(pContainerMetaDataOut.get(key), pContainerMetaDataIn.get(key)); + } + System.out.println("UserMetaData: " + container.getUserMetadata()); + assertNotNull(container.getSystemMetadata()); + System.out.println("SystemMetaData: " + container.getSystemMetadata()); + assertNotNull(container.getACLMetadata()); + List> aclMetadataOut = container.getACLMetadata(); + System.out.println("ACLMetaData: "); + for (Map aclMap : aclMetadataOut) { + System.out.println(aclMap); + } + container = api.get("/"); + System.out.println("root container: " + container); + assertEquals(container.getChildren().contains(pContainerName), true); + container = api.get(pContainerName, ContainerQueryParams.Builder.field("parentURI")); + assertNotNull(container); + assertEquals(container.getParentURI(), "/"); + System.out.println(container); - } + container = api.get(pContainerName, ContainerQueryParams.Builder.field("parentURI").field("objectName")); + assertNotNull(container); + assertEquals(container.getParentURI(), "/"); + assertEquals(container.getObjectName(), pContainerName); + container = api.get(pContainerName, ContainerQueryParams.Builder.metadata()); + assertNotNull(container); + pContainerMetaDataOut = container.getUserMetadata(); + keys = pContainerMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(pContainerMetaDataOut.containsKey(key), true); + assertEquals(pContainerMetaDataOut.get(key), pContainerMetaDataIn.get(key)); + } + System.out.println(container); + + System.out.println("GetContainerOptions.Builder.metadata(cdmi_acl)"); + container = api.get(pContainerName, ContainerQueryParams.Builder.metadata("cdmi_acl")); + assertNotNull(container); + System.out.println(container); + assertNotNull(container.getACLMetadata()); + assertEquals(container.getACLMetadata().size(), 3); + + System.out.println("adding containers to container"); + String firstParentURI = api.get(pContainerName).getObjectName(); + for (int i = 0; i < 10; i++) { + container = api.create(firstParentURI + "childcontainer" + i + "/"); + assertNotNull(container); + assertEquals(container.getParentURI(), pContainerName); + assertEquals(container.getObjectName(), "childcontainer" + i + "/"); + container = api.create(container.getParentURI() + container.getObjectName() + "grandchild/", + pCreateContainerOptions); + assertEquals(container.getParentURI(), pContainerName + "childcontainer" + i + "/"); + assertEquals(container.getObjectName(), "grandchild" + "/"); + container = api.get(container.getParentURI(), ContainerQueryParams.Builder.children()); + assertEquals(container.getChildren().contains("grandchild" + "/"), true); + } + container = api.get(pContainerName, ContainerQueryParams.Builder.children()); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().size(), 10); + container = api.get(pContainerName, ContainerQueryParams.Builder.children(0, 3)); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().size(), 4); + + container = api.get(pContainerName, ContainerQueryParams.Builder.field("parentURI").field("objectName") + .children().metadata()); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().size(), 10); + assertEquals(container.getParentURI(), "/"); + assertEquals(container.getObjectName(), pContainerName); + assertEquals(container.getParentURI(), "/"); + assertEquals(container.getACLMetadata().size(), 3); + for (String childName : container.getChildren()) { + api.delete(container.getObjectName() + childName); + } + assertEquals(api.get(pContainerName, ContainerQueryParams.Builder.children()).getChildren().isEmpty(), true); + + } finally { + Logger.getAnonymousLogger().info("delete: " + pContainerName); + api.delete(pContainerName); + container = api.get("/"); + System.out.println("root container: " + container); + assertEquals(container.getChildren().contains(pContainerName), false); + } + + } } diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataApiLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataApiLiveTest.java index 91200d7262..6eec612c47 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataApiLiveTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataApiLiveTest.java @@ -50,686 +50,553 @@ import com.google.common.io.Files; */ @Test(groups = "live", testName = "DataApiLiveTest") public class DataApiLiveTest extends BaseCDMIApiLiveTest { - @Test - public void testCreateDataObjects() throws Exception { + @Test + public void testCreateDataObjects() throws Exception { - String containerName = "MyContainer" + System.currentTimeMillis() + "/"; - String dataObjectNameIn = "dataobject08121.txt"; - File tmpFileIn = new File("temp.txt"); - String value; - InputStream is; - File tmpFileOut; - File inFile; - Files.touch(tmpFileIn); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(bos); - byte[] bytes; - - CreateDataObjectOptions pCreateDataObjectOptions; - DataObject dataObject; - Iterator keys; - Map dataObjectMetaDataOut; - Map pContainerMetaDataIn = new HashMap(); - Map pDataObjectMetaDataIn = new LinkedHashMap(); - pDataObjectMetaDataIn.put("dataObjectkey1", "value1"); - pDataObjectMetaDataIn.put("dataObjectkey2", "value2"); - pDataObjectMetaDataIn.put("dataObjectkey3", "value3"); + String containerName = "MyContainer" + System.currentTimeMillis() + "/"; + String dataObjectNameIn = "dataobject08121.txt"; + File tmpFileIn = new File("temp.txt"); + String value; + InputStream is; + File tmpFileOut; + File inFile; + Files.touch(tmpFileIn); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(bos); + byte[] bytes; - CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder - .metadata(pContainerMetaDataIn); - ContainerApi containerApi = cdmiContext.getApi() - .getContainerApi(); - DataApi dataApi = cdmiContext.getApi().getDataApi(); - Logger.getAnonymousLogger().info("createContainer: " + containerName); - Container container = containerApi.createContainer(containerName, - pCreateContainerOptions); - try { - assertNotNull(container); - System.out.println(container); - container = containerApi.getContainer(containerName); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().isEmpty(), true); - - // exercise create data object with value mimetype and metadata - value = "Hello CDMI data object with value mimetype and metadata"; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(value).mimetype("text/plain") - .metadata(pDataObjectMetaDataIn); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(), "text/plain"); - assertEquals(dataObject.getValueAsString(), value); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - keys = pDataObjectMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(dataObjectMetaDataOut.containsKey(key), true); - assertEquals(dataObjectMetaDataOut.get(key), - pDataObjectMetaDataIn.get(key)); - } - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName ); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + CreateDataObjectOptions pCreateDataObjectOptions; + DataObject dataObject; + Iterator keys; + Map dataObjectMetaDataOut; + Map pContainerMetaDataIn = new HashMap(); + Map pDataObjectMetaDataIn = new LinkedHashMap(); + pDataObjectMetaDataIn.put("dataObjectkey1", "value1"); + pDataObjectMetaDataIn.put("dataObjectkey2", "value2"); + pDataObjectMetaDataIn.put("dataObjectkey3", "value3"); - // verify that options order does not matter - value = "Hello CDMI World3"; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .metadata(pDataObjectMetaDataIn).mimetype("text/plain") - .value(value); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(), "text/plain"); - assertEquals(dataObject.getValueAsString(), value); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - keys = pDataObjectMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(dataObjectMetaDataOut.containsKey(key), true); - assertEquals(dataObjectMetaDataOut.get(key), - pDataObjectMetaDataIn.get(key)); - } - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn); + ContainerApi containerApi = cdmiContext.getApi().getApi(); + DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName); + Logger.getAnonymousLogger().info("create: " + containerName); + Container container = containerApi.create(containerName, pCreateContainerOptions); + try { + assertNotNull(container); + System.out.println(container); + container = containerApi.get(containerName); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().isEmpty(), true); - // exercise create data object with empty metadata - value = "Hello CDMI World4"; - pDataObjectMetaDataIn.clear(); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(value).mimetype("text/plain") - .metadata(pDataObjectMetaDataIn); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(), "text/plain"); - assertEquals(dataObject.getValueAsString(), value); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - assertEquals(dataObjectMetaDataOut.isEmpty(),true); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with value mimetype and metadata + value = "Hello CDMI data object with value mimetype and metadata"; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain") + .metadata(pDataObjectMetaDataIn); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + assertEquals(dataObject.getValueAsString(), value); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + keys = pDataObjectMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(dataObjectMetaDataOut.containsKey(key), true); + assertEquals(dataObjectMetaDataOut.get(key), pDataObjectMetaDataIn.get(key)); + } + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); - // exercise create data object with null metadata - value = "Hello CDMI World5"; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value( - value).mimetype("text/plain"); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(), "text/plain"); - assertEquals(dataObject.getValueAsString(), value); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - assertEquals(true, dataObjectMetaDataOut.isEmpty()); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with only value - value = "Hello CDMI World6"; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(value); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - assertEquals(dataObjectMetaDataOut.isEmpty(),true); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // verify that options order does not matter + value = "Hello CDMI World3"; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.metadata(pDataObjectMetaDataIn) + .mimetype("text/plain").value(value); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + assertEquals(dataObject.getValueAsString(), value); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + keys = pDataObjectMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(dataObjectMetaDataOut.containsKey(key), true); + assertEquals(dataObjectMetaDataOut.get(key), pDataObjectMetaDataIn.get(key)); + } + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with empty mimetype only - value = ""; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .mimetype(new String()); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - //assertEquals(dataObject.getMimetype(), ""); - assertEquals(dataObject.getValueAsString(), ""); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - //assertEquals(dataObjectMetaDataOut.isEmpty(),true); + // exercise create data object with empty metadata + value = "Hello CDMI World4"; + pDataObjectMetaDataIn.clear(); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain") + .metadata(pDataObjectMetaDataIn); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + assertEquals(dataObject.getValueAsString(), value); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + assertEquals(dataObjectMetaDataOut.isEmpty(), true); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - dataApi.deleteDataObject(containerName, dataObjectNameIn); + // exercise create data object with null metadata + value = "Hello CDMI World5"; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain"); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + assertEquals(dataObject.getValueAsString(), value); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + assertEquals(true, dataObjectMetaDataOut.isEmpty()); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with no value - value = ""; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), ""); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - assertEquals(dataObjectMetaDataOut.isEmpty(),true); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with only value + value = "Hello CDMI World6"; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + assertEquals(dataObjectMetaDataOut.isEmpty(), true); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with byte array - value = "Hello CDMI World 7"; - out.writeUTF(value); - out.close(); - bytes = bos.toByteArray(); - // String.getBytes causes an exception CreateDataObjectOptions need to investigate byte arrays - //bytes = value.getBytes("UTF-8"); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(bytes); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - assertEquals(new String(dataObject.getValueAsByteArray()), value); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with empty mimetype only + value = ""; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.mimetype(new String()); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + // assertEquals(dataObject.getMimetype(), ""); + assertEquals(dataObject.getValueAsString(), ""); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + // assertEquals(dataObjectMetaDataOut.isEmpty(),true); - // exercise create data object with an existing file - inFile = new File(System.getProperty("user.dir") - + "/src/test/resources/container.json"); - assertEquals(true, inFile.isFile()); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(inFile); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, inFile)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), - Files.toString(inFile, Charsets.UTF_8).length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + dataApi.delete(dataObjectNameIn); - // exercise create data object with a temporary file that we create - // on the fly - // with default Charset - value = "Hello CDMI World 10"; - Files.write(value, tmpFileIn, Charsets.UTF_8); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(tmpFileIn); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with no value + value = ""; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), ""); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + assertEquals(dataObjectMetaDataOut.isEmpty(), true); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with a temporary file that we create - // on the fly - // specify charset UTF_8 - Files.write(value, tmpFileIn, Charsets.UTF_8); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value( - tmpFileIn, Charsets.UTF_8); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with byte array + value = "Hello CDMI World 7"; + out.writeUTF(value); + out.close(); + bytes = bos.toByteArray(); + // String.getBytes causes an exception CreateDataObjectOptions need to investigate byte + // arrays + // bytes = value.getBytes("UTF-8"); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(bytes); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + assertEquals(new String(dataObject.getValueAsByteArray()), value); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with a temporary file that we create - // on the fly - // specify charset US_ASCII - Files.write(value, tmpFileIn, Charsets.US_ASCII); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value( - tmpFileIn, Charsets.US_ASCII); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with an existing file + inFile = new File(System.getProperty("user.dir") + "/src/test/resources/container.json"); + assertEquals(true, inFile.isFile()); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(inFile); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, inFile)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), + Files.toString(inFile, Charsets.UTF_8).length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with a temporary file with multiple - // lines - // with default Charset - Files.write("line1", tmpFileIn, Charsets.UTF_8); - Files.append("\nline2", tmpFileIn, Charsets.UTF_8); - Files.append("\nline3", tmpFileIn, Charsets.UTF_8); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(tmpFileIn); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3"); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), - Files.toString(tmpFileIn, Charsets.UTF_8).length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with a temporary file that we create + // on the fly + // with default Charset + value = "Hello CDMI World 10"; + Files.write(value, tmpFileIn, Charsets.UTF_8); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with a temporary file with multiple - // lines - // with Charset UTF_8 - Files.write("line1", tmpFileIn, Charsets.UTF_8); - Files.append("\nline2", tmpFileIn, Charsets.UTF_8); - Files.append("\nline3", tmpFileIn, Charsets.UTF_8); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(new FileInputStream(tmpFileIn)); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3"); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), - Files.toString(tmpFileIn, Charsets.UTF_8).length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with a temporary file that we create + // on the fly + // specify charset UTF_8 + Files.write(value, tmpFileIn, Charsets.UTF_8); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn, Charsets.UTF_8); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with a temporary file with multiple - // lines - // with Charset ISO_8859_1 - Files.write("line1", tmpFileIn, Charsets.ISO_8859_1); - Files.append("\nline2", tmpFileIn, Charsets.ISO_8859_1); - Files.append("\nline3", tmpFileIn, Charsets.ISO_8859_1); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value( - new FileInputStream(tmpFileIn), Charsets.ISO_8859_1); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3"); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), - Files.toString(tmpFileIn, Charsets.ISO_8859_1).length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with a temporary file that we create + // on the fly + // specify charset US_ASCII + Files.write(value, tmpFileIn, Charsets.US_ASCII); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn, Charsets.US_ASCII); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with an inputstream - is = new ByteArrayInputStream(value.getBytes()); - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(is); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - assertNotNull(dataObject.getValueAsInputSupplier()); - assertEquals(CharStreams.toString(CharStreams.newReaderSupplier(dataObject - .getValueAsInputSupplier(Charsets.UTF_8),Charsets.UTF_8)), value); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); - } finally { - tmpFileIn.delete(); - containerApi.deleteContainer(containerName); + // exercise create data object with a temporary file with multiple + // lines + // with default Charset + Files.write("line1", tmpFileIn, Charsets.UTF_8); + Files.append("\nline2", tmpFileIn, Charsets.UTF_8); + Files.append("\nline3", tmpFileIn, Charsets.UTF_8); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3"); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), + Files.toString(tmpFileIn, Charsets.UTF_8).length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - } + // exercise create data object with a temporary file with multiple + // lines + // with Charset UTF_8 + Files.write("line1", tmpFileIn, Charsets.UTF_8); + Files.append("\nline2", tmpFileIn, Charsets.UTF_8); + Files.append("\nline3", tmpFileIn, Charsets.UTF_8); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(new FileInputStream(tmpFileIn)); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3"); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), + Files.toString(tmpFileIn, Charsets.UTF_8).length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - } - - @Test - public void testGetDataObjects() throws Exception { + // exercise create data object with a temporary file with multiple + // lines + // with Charset ISO_8859_1 + Files.write("line1", tmpFileIn, Charsets.ISO_8859_1); + Files.append("\nline2", tmpFileIn, Charsets.ISO_8859_1); + Files.append("\nline3", tmpFileIn, Charsets.ISO_8859_1); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(new FileInputStream(tmpFileIn), + Charsets.ISO_8859_1); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3"); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), + Files.toString(tmpFileIn, Charsets.ISO_8859_1).length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - String containerName = "MyContainer" + System.currentTimeMillis() + "/"; - String dataObjectNameIn = "dataobject08121.txt"; - File tmpFileIn = new File("temp.txt"); - String value; - Files.touch(tmpFileIn); - - CreateDataObjectOptions pCreateDataObjectOptions; - DataObject dataObject; - Iterator keys; - Map dataObjectMetaDataOut; - Map pContainerMetaDataIn = new HashMap(); - Map pDataObjectMetaDataIn = new LinkedHashMap(); - pDataObjectMetaDataIn.put("dataObjectkey1", "value1"); - pDataObjectMetaDataIn.put("dataObjectkey2", "value2"); - pDataObjectMetaDataIn.put("dataObjectkey3", "value3"); + // exercise create data object with an inputstream + is = new ByteArrayInputStream(value.getBytes()); + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(is); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + assertNotNull(dataObject.getValueAsInputSupplier()); + assertEquals(CharStreams.toString(CharStreams.newReaderSupplier( + dataObject.getValueAsInputSupplier(Charsets.UTF_8), Charsets.UTF_8)), value); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); + } finally { + tmpFileIn.delete(); + containerApi.delete(containerName); - CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder - .metadata(pContainerMetaDataIn); - ContainerApi containerApi = cdmiContext.getApi() - .getContainerApi(); - DataApi dataApi = cdmiContext.getApi().getDataApi(); - Logger.getAnonymousLogger().info("createContainer: " + containerName); - Container container = containerApi.createContainer(containerName, - pCreateContainerOptions); - try { - assertNotNull(container); - System.out.println(container); - container = containerApi.getContainer(containerName); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().isEmpty(), true); - - // exercise create data object with value mimetype and metadata - value = "Hello CDMI data object with value mimetype and metadata"; - pCreateDataObjectOptions = CreateDataObjectOptions.Builder - .value(value).mimetype("text/plain") - .metadata(pDataObjectMetaDataIn); - dataObject = dataApi.createDataObject(containerName, - dataObjectNameIn, pCreateDataObjectOptions); - assertNotNull(dataObject); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(), "text/plain"); - assertEquals(dataObject.getValueAsString(), value); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - keys = pDataObjectMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(dataObjectMetaDataOut.containsKey(key), true); - assertEquals(dataObjectMetaDataOut.get(key), - pDataObjectMetaDataIn.get(key)); - } - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI")); - assertNotNull(dataObject); - System.out.println(dataObject); - assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName()); - - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI").field("objectName")); - assertNotNull(dataObject); - System.out.println(dataObject); - assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName()); - assertEquals(dataObject.getObjectName(),dataObjectNameIn); + } - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI").field("objectName").field("mimetype")); - assertNotNull(dataObject); - System.out.println(dataObject); - assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName()); - assertEquals(dataObject.getObjectName(),dataObjectNameIn); - assertEquals(dataObject.getMimetype(),"text/plain"); + } - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.field("parentURI").field("objectName").field("mimetype").metadata()); - assertNotNull(dataObject); - System.out.println(dataObject); - assertEquals(dataObject.getParentURI(),container.getParentURI()+container.getObjectName()); - assertEquals(dataObject.getObjectName(),dataObjectNameIn); - assertEquals(dataObject.getMimetype(),"text/plain"); - dataObjectMetaDataOut = dataObject.getUserMetadata(); - assertNotNull(dataObjectMetaDataOut); - keys = pDataObjectMetaDataIn.keySet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - assertEquals(dataObjectMetaDataOut.containsKey(key), true); - assertEquals(dataObjectMetaDataOut.get(key), - pDataObjectMetaDataIn.get(key)); - } - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.metadata("cdmi_size")); - assertNotNull(dataObject); - System.out.println(dataObject); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); + @Test + public void testGetDataObjects() throws Exception { - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.field("mimetype").value()); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println(dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(),"text/plain"); - assertEquals(dataObject.getValueAsString(),value); - - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn,DataObjectQueryParams.Builder.field("mimetype").value(0,3)); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println(dataObject.getValueAsString()); - assertEquals(dataObject.getMimetype(),"text/plain"); - //value is SGVsbA==. This needs investigating to determine if this - //is problem with CDMI server or the jcloud client or must understanding of spec + String containerName = "MyContainer" + System.currentTimeMillis() + "/"; + String dataObjectNameIn = "dataobject08121.txt"; + File tmpFileIn = new File("temp.txt"); + String value; + Files.touch(tmpFileIn); + CreateDataObjectOptions pCreateDataObjectOptions; + DataObject dataObject; + Iterator keys; + Map dataObjectMetaDataOut; + Map pContainerMetaDataIn = new HashMap(); + Map pDataObjectMetaDataIn = new LinkedHashMap(); + pDataObjectMetaDataIn.put("dataObjectkey1", "value1"); + pDataObjectMetaDataIn.put("dataObjectkey2", "value2"); + pDataObjectMetaDataIn.put("dataObjectkey3", "value3"); - dataApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); - } finally { - tmpFileIn.delete(); - containerApi.deleteContainer(containerName); + CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn); + ContainerApi containerApi = cdmiContext.getApi().getApi(); + DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName); + Logger.getAnonymousLogger().info("create: " + containerName); + Container container = containerApi.create(containerName, pCreateContainerOptions); + try { + assertNotNull(container); + System.out.println(container); + container = containerApi.get(containerName); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().isEmpty(), true); - } + // exercise create data object with value mimetype and metadata + value = "Hello CDMI data object with value mimetype and metadata"; + pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain") + .metadata(pDataObjectMetaDataIn); + dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions); + assertNotNull(dataObject); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + assertEquals(dataObject.getValueAsString(), value); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + keys = pDataObjectMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(dataObjectMetaDataOut.containsKey(key), true); + assertEquals(dataObjectMetaDataOut.get(key), pDataObjectMetaDataIn.get(key)); + } + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); - } + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")); + assertNotNull(dataObject); + System.out.println(dataObject); + assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName()); + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI") + .field("objectName")); + assertNotNull(dataObject); + System.out.println(dataObject); + assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI") + .field("objectName").field("mimetype")); + assertNotNull(dataObject); + System.out.println(dataObject); + assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getMimetype(), "text/plain"); + + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI") + .field("objectName").field("mimetype").metadata()); + assertNotNull(dataObject); + System.out.println(dataObject); + assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getMimetype(), "text/plain"); + dataObjectMetaDataOut = dataObject.getUserMetadata(); + assertNotNull(dataObjectMetaDataOut); + keys = pDataObjectMetaDataIn.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + assertEquals(dataObjectMetaDataOut.containsKey(key), true); + assertEquals(dataObjectMetaDataOut.get(key), pDataObjectMetaDataIn.get(key)); + } + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.metadata("cdmi_size")); + assertNotNull(dataObject); + System.out.println(dataObject); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("mimetype").value()); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println(dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + assertEquals(dataObject.getValueAsString(), value); + + dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("mimetype").value(0, 3)); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println(dataObject.getValueAsString()); + assertEquals(dataObject.getMimetype(), "text/plain"); + // value is SGVsbA==. This needs investigating to determine if this + // is problem with CDMI server or the jcloud client or must understanding of spec + + dataApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); + } finally { + tmpFileIn.delete(); + containerApi.delete(containerName); + + } + + } } diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApiLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApiLiveTest.java index 649b32c1fd..570345c0f3 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApiLiveTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataNonCDMIContentTypeApiLiveTest.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.logging.Logger; + import org.jclouds.io.Payload; import org.jclouds.io.payloads.BaseMutableContentMetadata; import org.jclouds.io.payloads.ByteArrayPayload; @@ -55,367 +56,300 @@ import com.google.common.net.MediaType; */ @Test(groups = "live", testName = "DataNonCDMIContentTypeApiLiveTest") public class DataNonCDMIContentTypeApiLiveTest extends BaseCDMIApiLiveTest { - @Test - public void testCreateDataObjectsNonCDMI() throws Exception { + @Test + public void testCreateDataObjectsNonCDMI() throws Exception { - String containerName = "MyContainer" + System.currentTimeMillis() + "/"; - String dataObjectNameIn = "dataobject.txt"; - File tmpFileIn = new File("temp.txt"); - String value; - InputStream is; - File tmpFileOut; - File inFile; - Files.touch(tmpFileIn); - byte[] bytes; - DataObject dataObject; - Map pContainerMetaDataIn = new HashMap(); - Map pDataObjectMetaDataIn = new LinkedHashMap(); - pDataObjectMetaDataIn.put("dataObjectkey1", "value1"); - pDataObjectMetaDataIn.put("dataObjectkey2", "value2"); - pDataObjectMetaDataIn.put("dataObjectkey3", "value3"); - - Payload payloadIn; - Payload payloadOut; - FileOutputStream fos; - + String containerName = "MyContainer" + System.currentTimeMillis() + "/"; + String dataObjectNameIn = "dataobject.txt"; + File tmpFileIn = new File("temp.txt"); + String value; + InputStream is; + File tmpFileOut; + File inFile; + Files.touch(tmpFileIn); + byte[] bytes; + DataObject dataObject; + Map pContainerMetaDataIn = new HashMap(); + Map pDataObjectMetaDataIn = new LinkedHashMap(); + pDataObjectMetaDataIn.put("dataObjectkey1", "value1"); + pDataObjectMetaDataIn.put("dataObjectkey2", "value2"); + pDataObjectMetaDataIn.put("dataObjectkey3", "value3"); - CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder - .metadata(pContainerMetaDataIn); - ContainerApi containerApi = cdmiContext.getApi() - .getContainerApi(); - DataApi dataApi = cdmiContext.getApi().getDataApi(); - DataNonCDMIContentTypeApi dataNonCDMIContentTypeApi = cdmiContext.getApi().getDataNonCDMIContentTypeApi(); - Logger.getAnonymousLogger().info("createContainer: " + containerName); - Container container = containerApi.createContainer(containerName, - pCreateContainerOptions); - try { - - assertNotNull(container); - System.out.println(container); - container = containerApi.getContainer(containerName); - assertNotNull(container); - assertNotNull(container.getChildren()); - assertEquals(container.getChildren().isEmpty(), true); - - // exercise create data object with none cdmi put with payload string. - value = "Hello CDMI World non-cdmi String"; - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - value); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value); - - payloadIn = new StringPayload(value); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) - .build())); - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - payloadIn); + Payload payloadIn; + Payload payloadOut; + FileOutputStream fos; - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value); - - dataObject = dataNonCDMIContentTypeApi.getDataObject(containerName, dataObjectNameIn, - DataObjectQueryParams.Builder.field("parentURI")); - assertNotNull(dataObject); - System.out.println(dataObject); - assertEquals(dataObject.getParentURI(), "/" + containerName); - dataObject = dataNonCDMIContentTypeApi.getDataObject(containerName, dataObjectNameIn, - DataObjectQueryParams.Builder.metadata() - .field("parentURI") - .field("objectName") - .field("objectType") - .field("mimetype")); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(dataObject.getMimetype(),MediaType.PLAIN_TEXT_UTF_8.toString()); - + CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn); + ContainerApi containerApi = cdmiContext.getApi().getApi(); + DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName); + DataNonCDMIContentTypeApi dataNonCDMIContentTypeApi = cdmiContext.getApi() + .getDataNonCDMIContentTypeApiForContainer(containerName); + Logger.getAnonymousLogger().info("create: " + containerName); + Container container = containerApi.create(containerName, pCreateContainerOptions); + try { - - dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + assertNotNull(container); + System.out.println(container); + container = containerApi.get(containerName); + assertNotNull(container); + assertNotNull(container.getChildren()); + assertEquals(container.getChildren().isEmpty(), true); - // exercise create data object with none cdmi put with payload byte array. - value = "Hello CDMI World non-cdmi byte array"; - bytes = value.getBytes("UTF-8"); - payloadIn = new ByteArrayPayload(bytes); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) - .build())); - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - payloadIn); - System.out.println(containerApi.getContainer(containerName)); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - assertEquals(new String(dataObject.getValueAsByteArray()), value); - assertEquals(dataObject.getUserMetadata().isEmpty(), true); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value); + // exercise create data object with none cdmi put with payload string. + value = "Hello CDMI World non-cdmi String"; + dataNonCDMIContentTypeApi.create(dataObjectNameIn, value); + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")), value); - - - dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); - - - + payloadIn = new StringPayload(value); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build())); + dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn); - // exercise create data object with none cdmi put with payload file. - value = "Hello CDMI World non-cdmi File"; - Files.write(value, tmpFileIn, Charsets.UTF_8); - payloadIn = new FilePayload(tmpFileIn); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) - .build())); - - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - payloadIn); - System.out.println(containerApi.getContainer(containerName)); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); - tmpFileOut.delete(); - assertEquals(dataObject.getUserMetadata().isEmpty(), true); - System.out.println("My Metadata: "+dataObject.getUserMetadata()); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - //assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value); - //byte[] _bytes = ByteStreams.toByteArray(payloadOut.getInput()); - tmpFileOut = new File(Files.createTempDir(),"temp.txt"); - fos = new FileOutputStream(tmpFileOut); - ByteStreams.copy(payloadOut.getInput(), fos); - fos.flush(); - fos.close(); - assertEquals(Files.equal(tmpFileOut, tmpFileIn),true); - tmpFileOut.delete(); - - dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")), value); - // exercise create data object with none cdmi put with text file payload file. - inFile = new File(System.getProperty("user.dir") - + "/src/test/resources/container.json"); - assertEquals(true, inFile.isFile()); - payloadIn = new FilePayload(inFile); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.JSON_UTF_8.toString()) - .build())); - - dataNonCDMIContentTypeApi.createDataObject(containerName, inFile.getName(), - payloadIn); - System.out.println(containerApi.getContainer(containerName)); - dataObject = dataApi.getDataObject(containerName, - inFile.getName()); - assertNotNull(dataObject); - System.out.println(dataObject); - //System.out.println("value: " + dataObject.getValueAsString()); - //assertEquals(dataObject.getValueAsString(), value); - tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); - assertEquals(true, Files.equal(tmpFileOut, inFile)); - tmpFileOut.delete(); - assertEquals(dataObject.getUserMetadata().isEmpty(), true); - //System.out.println("My Metadata: "+dataObject.getUserMetadata()); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), inFile.length()); - assertEquals(dataObject.getObjectName(), inFile.getName()); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(inFile.getName()), true); - dataApi.deleteDataObject(containerName, inFile.getName()); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); - - // exercise create data object with none cdmi put with text file payload file. - //inFile = new File(System.getProperty("user.dir") - // + "/src/test/resources/Jellyfish.jpg"); // takes too long when working from home - inFile = new File(System.getProperty("user.dir") - + "/src/test/resources/yellow-flowers.jpg"); - assertEquals(true, inFile.isFile()); - payloadIn = new FilePayload(inFile); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.JPEG.toString()) - .build())); - dataNonCDMIContentTypeApi.createDataObject(containerName, inFile.getName(), - payloadIn); - System.out.println(containerApi.getContainer(containerName)); - //note dataApi.getDataObject when the data object is not a string - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, inFile.getName()); - assertNotNull(payloadOut); - tmpFileOut = new File(Files.createTempDir(),"temp.jpg"); - fos = new FileOutputStream(tmpFileOut); - ByteStreams.copy(payloadOut.getInput(), fos); - fos.flush(); - fos.close(); - assertEquals(Files.equal(tmpFileOut, inFile),true); - tmpFileOut.delete(); - - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(inFile.getName()), true); - dataApi.deleteDataObject(containerName, inFile.getName()); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(inFile.getName()), false); - + dataObject = dataNonCDMIContentTypeApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")); + assertNotNull(dataObject); + System.out.println(dataObject); + assertEquals(dataObject.getParentURI(), "/" + containerName); + dataObject = dataNonCDMIContentTypeApi.get(dataObjectNameIn, + DataObjectQueryParams.Builder.metadata().field("parentURI").field("objectName").field("objectType") + .field("mimetype")); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(dataObject.getMimetype(), MediaType.PLAIN_TEXT_UTF_8.toString()); - // exercise create data object with none cdmi put with payload inputStream riginating from string. - value = "Hello CDMI World non-cdmi inputStream originating from string"; - is = new ByteArrayInputStream(value.getBytes()); - payloadIn = new InputStreamPayload(is); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) - .contentLength(new Long(value.length())) - .build())); - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - payloadIn); - System.out.println(containerApi.getContainer(containerName)); - dataObject = dataApi.getDataObject(containerName, - dataObjectNameIn); - assertNotNull(dataObject); - System.out.println(dataObject); - System.out.println("value: " + dataObject.getValueAsString()); - assertEquals(dataObject.getValueAsString(), value); - assertNotNull(dataObject.getValueAsInputSupplier()); - assertEquals(CharStreams.toString(CharStreams.newReaderSupplier(dataObject - .getValueAsInputSupplier(Charsets.UTF_8),Charsets.UTF_8)), value); - assertEquals(dataObject.getUserMetadata().isEmpty(), true); - System.out.println("My Metadata: "+dataObject.getUserMetadata()); - assertEquals( - Integer.parseInt(dataObject.getSystemMetadata().get( - "cdmi_size")), value.length()); - assertEquals(dataObject.getObjectName(), dataObjectNameIn); - assertEquals(dataObject.getObjectType(), "application/cdmi-object"); - assertEquals(dataObject.getParentURI(), "/" + containerName); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), true); - dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + dataNonCDMIContentTypeApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - // exercise create data object with none cdmi put with payload inputStream originating from jpeg file. - inFile = new File(System.getProperty("user.dir") - + "/src/test/resources/yellow-flowers.jpg"); - assertEquals(true, inFile.isFile()); - FileInputStream fileInputStream = new FileInputStream(inFile); - payloadIn = new InputStreamPayload(fileInputStream); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.JPEG.toString()) - .contentLength(new Long(inFile.length())) - .build())); - dataNonCDMIContentTypeApi.createDataObject(containerName, inFile.getName(), - payloadIn); - System.out.println(containerApi.getContainer(containerName)); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, inFile.getName()); - assertNotNull(payloadOut); - tmpFileOut = new File(Files.createTempDir(),"temp.jpg"); - fos = new FileOutputStream(tmpFileOut); - ByteStreams.copy(payloadOut.getInput(), fos); - fos.flush(); - fos.close(); - assertEquals(Files.equal(tmpFileOut, inFile),true); - tmpFileOut.delete(); - - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(inFile.getName()), true); - dataApi.deleteDataObject(containerName, inFile.getName()); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(inFile.getName()), false); + // exercise create data object with none cdmi put with payload byte array. + value = "Hello CDMI World non-cdmi byte array"; + bytes = value.getBytes("UTF-8"); + payloadIn = new ByteArrayPayload(bytes); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build())); + dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn); + System.out.println(containerApi.get(containerName)); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + assertEquals(new String(dataObject.getValueAsByteArray()), value); + assertEquals(dataObject.getUserMetadata().isEmpty(), true); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")), value); - // exercise get with none cdmi get range. - value = "Hello CDMI World non-cdmi String"; - payloadIn = new StringPayload(value); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) - .build())); - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - payloadIn); + dataNonCDMIContentTypeApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn, "bytes=0-10"); - assertNotNull(payloadOut); - assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value.substring(0, 11)); - assertEquals(payloadOut.getContentMetadata().getContentLength(),new Long(11)); - - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn, "bytes=11-20"); - assertNotNull(payloadOut); - assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")),value.substring(11, 21)); - assertEquals(payloadOut.getContentMetadata().getContentLength(),new Long(10)); - - dataNonCDMIContentTypeApi.deleteDataObject(containerName, dataObjectNameIn); - assertEquals(containerApi.getContainer(containerName) - .getChildren().contains(dataObjectNameIn), false); + // exercise create data object with none cdmi put with payload file. + value = "Hello CDMI World non-cdmi File"; + Files.write(value, tmpFileIn, Charsets.UTF_8); + payloadIn = new FilePayload(tmpFileIn); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build())); - // exercise create data object with none cdmi partial. - // server does not actually support cdmi partial but - // trace allows me to see that request was constructed properly - value = "Hello CDMI World non-cdmi String"; - payloadIn = new StringPayload(value); - payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata().toBuilder() - .contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) - .build())); - dataNonCDMIContentTypeApi.createDataObjectPartial(containerName, dataObjectNameIn, - payloadIn); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - System.out.println("payload "+payloadOut); - - dataNonCDMIContentTypeApi.createDataObjectPartial(containerName, dataObjectNameIn, - payloadIn); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - System.out.println("payload "+payloadOut); + dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn); + System.out.println(containerApi.get(containerName)); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, tmpFileIn)); + tmpFileOut.delete(); + assertEquals(dataObject.getUserMetadata().isEmpty(), true); + System.out.println("My Metadata: " + dataObject.getUserMetadata()); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); - - - dataNonCDMIContentTypeApi.createDataObject(containerName, dataObjectNameIn, - payloadIn); + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + // assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), + // "UTF-8")),value); + // byte[] _bytes = ByteStreams.toByteArray(payloadOut.getInput()); + tmpFileOut = new File(Files.createTempDir(), "temp.txt"); + fos = new FileOutputStream(tmpFileOut); + ByteStreams.copy(payloadOut.getInput(), fos); + fos.flush(); + fos.close(); + assertEquals(Files.equal(tmpFileOut, tmpFileIn), true); + tmpFileOut.delete(); + dataNonCDMIContentTypeApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - payloadOut = dataNonCDMIContentTypeApi.getDataObjectValue(containerName, dataObjectNameIn); - assertNotNull(payloadOut); - System.out.println("payload "+payloadOut); - - - } finally { - tmpFileIn.delete(); - containerApi.deleteContainer(containerName); + // exercise create data object with none cdmi put with text file payload file. + inFile = new File(System.getProperty("user.dir") + "/src/test/resources/container.json"); + assertEquals(true, inFile.isFile()); + payloadIn = new FilePayload(inFile); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.JSON_UTF_8.toString()).build())); - } + dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn); + System.out.println(containerApi.get(containerName)); + dataObject = dataApi.get(inFile.getName()); + assertNotNull(dataObject); + System.out.println(dataObject); + // System.out.println("value: " + dataObject.getValueAsString()); + // assertEquals(dataObject.getValueAsString(), value); + tmpFileOut = dataObject.getValueAsFile(Files.createTempDir()); + assertEquals(true, Files.equal(tmpFileOut, inFile)); + tmpFileOut.delete(); + assertEquals(dataObject.getUserMetadata().isEmpty(), true); + // System.out.println("My Metadata: "+dataObject.getUserMetadata()); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), inFile.length()); + assertEquals(dataObject.getObjectName(), inFile.getName()); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), true); + dataApi.delete(inFile.getName()); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); - } + // exercise create data object with none cdmi put with text file payload file. + // inFile = new File(System.getProperty("user.dir") + // + "/src/test/resources/Jellyfish.jpg"); // takes too long when working from home + inFile = new File(System.getProperty("user.dir") + "/src/test/resources/yellow-flowers.jpg"); + assertEquals(true, inFile.isFile()); + payloadIn = new FilePayload(inFile); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.JPEG.toString()).build())); + dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn); + System.out.println(containerApi.get(containerName)); + // note dataApi.get when the data object is not a string + payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName()); + assertNotNull(payloadOut); + tmpFileOut = new File(Files.createTempDir(), "temp.jpg"); + fos = new FileOutputStream(tmpFileOut); + ByteStreams.copy(payloadOut.getInput(), fos); + fos.flush(); + fos.close(); + assertEquals(Files.equal(tmpFileOut, inFile), true); + tmpFileOut.delete(); + + assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), true); + dataApi.delete(inFile.getName()); + assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), false); + + // exercise create data object with none cdmi put with payload inputStream riginating from + // string. + value = "Hello CDMI World non-cdmi inputStream originating from string"; + is = new ByteArrayInputStream(value.getBytes()); + payloadIn = new InputStreamPayload(is); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()) + .contentLength(new Long(value.length())).build())); + dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn); + System.out.println(containerApi.get(containerName)); + dataObject = dataApi.get(dataObjectNameIn); + assertNotNull(dataObject); + System.out.println(dataObject); + System.out.println("value: " + dataObject.getValueAsString()); + assertEquals(dataObject.getValueAsString(), value); + assertNotNull(dataObject.getValueAsInputSupplier()); + assertEquals(CharStreams.toString(CharStreams.newReaderSupplier( + dataObject.getValueAsInputSupplier(Charsets.UTF_8), Charsets.UTF_8)), value); + assertEquals(dataObject.getUserMetadata().isEmpty(), true); + System.out.println("My Metadata: " + dataObject.getUserMetadata()); + assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length()); + assertEquals(dataObject.getObjectName(), dataObjectNameIn); + assertEquals(dataObject.getObjectType(), "application/cdmi-object"); + assertEquals(dataObject.getParentURI(), "/" + containerName); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true); + dataNonCDMIContentTypeApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); + + // exercise create data object with none cdmi put with payload inputStream originating from + // jpeg file. + inFile = new File(System.getProperty("user.dir") + "/src/test/resources/yellow-flowers.jpg"); + assertEquals(true, inFile.isFile()); + FileInputStream fileInputStream = new FileInputStream(inFile); + payloadIn = new InputStreamPayload(fileInputStream); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.JPEG.toString()).contentLength(new Long(inFile.length())).build())); + dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn); + System.out.println(containerApi.get(containerName)); + payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName()); + assertNotNull(payloadOut); + tmpFileOut = new File(Files.createTempDir(), "temp.jpg"); + fos = new FileOutputStream(tmpFileOut); + ByteStreams.copy(payloadOut.getInput(), fos); + fos.flush(); + fos.close(); + assertEquals(Files.equal(tmpFileOut, inFile), true); + tmpFileOut.delete(); + + assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), true); + dataApi.delete(inFile.getName()); + assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), false); + + // exercise get with none cdmi get range. + value = "Hello CDMI World non-cdmi String"; + payloadIn = new StringPayload(value); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build())); + dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn); + + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn, "bytes=0-10"); + assertNotNull(payloadOut); + assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")), + value.substring(0, 11)); + assertEquals(payloadOut.getContentMetadata().getContentLength(), new Long(11)); + + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn, "bytes=11-20"); + assertNotNull(payloadOut); + assertEquals(CharStreams.toString(new InputStreamReader(payloadOut.getInput(), "UTF-8")), + value.substring(11, 21)); + assertEquals(payloadOut.getContentMetadata().getContentLength(), new Long(10)); + + dataNonCDMIContentTypeApi.delete(dataObjectNameIn); + assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false); + + // exercise create data object with none cdmi partial. + // server does not actually support cdmi partial but + // trace allows me to see that request was constructed properly + value = "Hello CDMI World non-cdmi String"; + payloadIn = new StringPayload(value); + payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata() + .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build())); + dataNonCDMIContentTypeApi.createPartial(dataObjectNameIn, payloadIn); + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + System.out.println("payload " + payloadOut); + + dataNonCDMIContentTypeApi.createPartial(dataObjectNameIn, payloadIn); + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + System.out.println("payload " + payloadOut); + + dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn); + + payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn); + assertNotNull(payloadOut); + System.out.println("payload " + payloadOut); + + } finally { + tmpFileIn.delete(); + containerApi.delete(containerName); + + } + + } } diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIApiLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIApiLiveTest.java index c7afe80d70..1c3e412632 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIApiLiveTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIApiLiveTest.java @@ -20,9 +20,9 @@ package org.jclouds.snia.cdmi.v1.internal; import org.jclouds.apis.BaseContextLiveTest; import org.jclouds.rest.RestContext; +import org.jclouds.snia.cdmi.v1.CDMIApi; import org.jclouds.snia.cdmi.v1.CDMIApiMetadata; import org.jclouds.snia.cdmi.v1.CDMIAsyncApi; -import org.jclouds.snia.cdmi.v1.CDMIApi; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java index 7753483dda..48aba90774 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java @@ -40,6 +40,7 @@ public class ListContainersOptionsTest { assert HttpRequestOptions.class.isAssignableFrom(ListContainersOptions.class); assert !String.class.isAssignableFrom(ListContainersOptions.class); } + @Test public void testNoOptionsQueryString() { HttpRequestOptions options = new ListContainersOptions(); diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java index bdb4f8bd3b..af43df3fd3 100644 --- a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java @@ -44,17 +44,9 @@ public class ParseContainerTest extends BaseItemParserTest { @Override @Consumes(MediaType.APPLICATION_JSON) public Container expected() { - return Container.builder() - .objectType("application/cdmi-container") - .objectID("00007E7F00102E230ED82694DAA975D2") - .objectName("MyContainer/") - .parentURI("/") - .metadata(ImmutableMap.builder() - .put("cdmi_size", new JsonBall("\"83\"")) - .build()) - .children(ImmutableSet.builder() - .add("MyDataObject.txt") - .build()) - .build(); + return Container.builder().objectType("application/cdmi-container").objectID("00007E7F00102E230ED82694DAA975D2") + .objectName("MyContainer/").parentURI("/") + .metadata(ImmutableMap. builder().put("cdmi_size", new JsonBall("\"83\"")).build()) + .children(ImmutableSet. builder().add("MyDataObject.txt").build()).build(); } } From b951276ec354f8a01c937111bd184a0270c20f15 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 23:47:44 -0700 Subject: [PATCH 29/60] cleaned up aws apis --- .../domain/GetMetricStatisticsResponse.java | 14 ++++++------- .../cloudwatch/features/MetricApi.java | 1 + .../cloudwatch/features/MetricAsyncApi.java | 5 +++++ .../features/MetricApiExpectTest.java | 5 ++--- .../org/jclouds/sqs/features/MessageApi.java | 6 +++--- .../jclouds/sqs/features/MessageAsyncApi.java | 6 +++--- .../org/jclouds/sqs/features/QueueApi.java | 7 ++++--- .../jclouds/sqs/features/QueueAsyncApi.java | 6 +++--- .../xml/ReceiveMessageResponseHandler.java | 9 ++++----- .../xml/RegexListQueuesResponseHandler.java | 6 +++--- .../xml/internal/BaseRegexQueueHandler.java | 6 +++--- .../sqs/features/BulkMessageApiLiveTest.java | 2 +- .../sqs/features/QueueApiLiveTest.java | 4 ++-- .../sqs/internal/BaseSQSApiLiveTest.java | 5 +++-- .../sqs/parse/ReceiveMessageResponseTest.java | 12 +++++------ .../jclouds/elb/features/LoadBalancerApi.java | 8 ++++---- .../elb/features/LoadBalancerAsyncApi.java | 20 +++++++++++-------- .../strategy/ELBLoadBalanceNodesStrategy.java | 2 +- .../features/LoadBalancerApiExpectTest.java | 7 +++---- .../compute/AWSEC2ComputeServiceLiveTest.java | 4 ++-- 20 files changed, 72 insertions(+), 63 deletions(-) diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatisticsResponse.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatisticsResponse.java index 146de9c569..d455908f39 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatisticsResponse.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/GetMetricStatisticsResponse.java @@ -18,12 +18,12 @@ */ package org.jclouds.cloudwatch.domain; -import java.util.Set; +import java.util.Iterator; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.collect.ForwardingSet; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; /** @@ -33,12 +33,12 @@ import com.google.common.collect.ImmutableSet; * * @author Jeremy Whitlock */ -public class GetMetricStatisticsResponse extends ForwardingSet { +public class GetMetricStatisticsResponse extends FluentIterable { - private final Set datapoints; + private final Iterable datapoints; private final String label; - public GetMetricStatisticsResponse(@Nullable Set datapoints, String label) { + public GetMetricStatisticsResponse(@Nullable Iterable datapoints, String label) { // Default to an empty set if (datapoints == null) { this.datapoints = ImmutableSet.of(); @@ -90,8 +90,8 @@ public class GetMetricStatisticsResponse extends ForwardingSet { } @Override - protected Set delegate() { - return datapoints; + public Iterator iterator() { + return datapoints.iterator(); } } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricApi.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricApi.java index 9e5deabc37..a573656440 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricApi.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricApi.java @@ -34,6 +34,7 @@ import org.jclouds.concurrent.Timeout; * Provides access to Amazon CloudWatch via the Query API *

* + * @see MetricAsyncApi * @see * @author Jeremy Whitlock */ diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncApi.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncApi.java index 3e739b5234..3e813809db 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncApi.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncApi.java @@ -37,11 +37,14 @@ import org.jclouds.cloudwatch.xml.ListMetricsResponseHandler; import org.jclouds.collect.IterableWithMarker; import org.jclouds.collect.PagedIterable; import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnEmptyIterableWithMarkerOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -64,6 +67,7 @@ public interface MetricAsyncApi { @XMLResponseParser(ListMetricsResponseHandler.class) @Transform(MetricsToPagedIterable.class) @FormParams(keys = "Action", values = "ListMetrics") + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) ListenableFuture> list(); /** @@ -73,6 +77,7 @@ public interface MetricAsyncApi { @Path("/") @XMLResponseParser(ListMetricsResponseHandler.class) @FormParams(keys = "Action", values = "ListMetrics") + @ExceptionParser(ReturnEmptyIterableWithMarkerOnNotFoundOr404.class) ListenableFuture> list(ListMetricsOptions options); /** diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricApiExpectTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricApiExpectTest.java index 25cae952fe..90ff95865c 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricApiExpectTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricApiExpectTest.java @@ -33,6 +33,7 @@ import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.cloudwatch.internal.BaseCloudWatchApiExpectTest; import org.jclouds.cloudwatch.options.GetMetricStatisticsOptions; import org.jclouds.cloudwatch.options.ListMetricsOptions; +import org.jclouds.collect.IterableWithMarkers; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.ResourceNotFoundException; @@ -76,8 +77,6 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest { "[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}]"); } - // TODO: this should really be an empty set - @Test(expectedExceptions = ResourceNotFoundException.class) public void testListMetricsWhenResponseIs404() throws Exception { HttpResponse listMetricsResponse = HttpResponse.builder().statusCode(404).build(); @@ -85,7 +84,7 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest { CloudWatchApi apiWhenMetricsDontExist = requestSendsResponse( listMetrics, listMetricsResponse); - apiWhenMetricsDontExist.getMetricApiForRegion(null).list().get(0); + assertEquals(apiWhenMetricsDontExist.getMetricApiForRegion(null).list().get(0), IterableWithMarkers.EMPTY); } public void testListMetrics2PagesWhenResponseIs2xx() throws Exception { diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java index fa4b96ae4a..1ff505b034 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageApi.java @@ -19,7 +19,6 @@ package org.jclouds.sqs.features; import java.net.URI; -import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -30,6 +29,7 @@ import org.jclouds.sqs.domain.MessageIdAndMD5; import org.jclouds.sqs.options.ReceiveMessageOptions; import org.jclouds.sqs.options.SendMessageOptions; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Table; /** @@ -402,7 +402,7 @@ public interface MessageApi { * maximum messages to receive, current limit is 10 * @see #receive(URI) */ - List receive(int max); + FluentIterable receive(int max); /** * same as {@link #receive(URI, int)} except you can provide options like @@ -415,5 +415,5 @@ public interface MessageApi { * options such as VisibilityTimeout * @see #receive(URI, int) */ - List receive(int max, ReceiveMessageOptions options); + FluentIterable receive(int max, ReceiveMessageOptions options); } diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java index 6eb9db388d..6438e7b9c8 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/features/MessageAsyncApi.java @@ -21,7 +21,6 @@ package org.jclouds.sqs.features; import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.jclouds.sqs.reference.SQSParameters.VERSION; -import java.util.List; import java.util.Map; import javax.ws.rs.FormParam; @@ -56,6 +55,7 @@ import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; import org.jclouds.sqs.xml.SendMessageBatchResponseHandler; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Table; import com.google.common.util.concurrent.ListenableFuture; @@ -260,7 +260,7 @@ public interface MessageAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ReceiveMessage") @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max); + ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max); /** * @see MessageApi#receive(int, ReceiveMessageOptions) @@ -269,7 +269,7 @@ public interface MessageAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ReceiveMessage") @XMLResponseParser(ReceiveMessageResponseHandler.class) - ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max, + ListenableFuture> receive(@FormParam("MaxNumberOfMessages") int max, ReceiveMessageOptions options); } diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java index ccd6dbec67..7f208bf388 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueApi.java @@ -20,7 +20,6 @@ package org.jclouds.sqs.features; import java.net.URI; import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -28,6 +27,8 @@ import org.jclouds.sqs.domain.QueueAttributes; import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.ListQueuesOptions; +import com.google.common.collect.FluentIterable; + /** * Provides access to SQS via their REST API. *

@@ -53,9 +54,9 @@ public interface QueueApi { * "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html" * /> */ - Set list(); + FluentIterable list(); - Set list(ListQueuesOptions options); + FluentIterable list(ListQueuesOptions options); /** * The CreateQueue action creates a new queue. diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java b/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java index 251cc9dec1..c0a839060c 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/features/QueueAsyncApi.java @@ -23,7 +23,6 @@ import static org.jclouds.sqs.reference.SQSParameters.VERSION; import java.net.URI; import java.util.Map; -import java.util.Set; import javax.ws.rs.FormParam; import javax.ws.rs.POST; @@ -52,6 +51,7 @@ import org.jclouds.sqs.xml.RegexListQueuesResponseHandler; import org.jclouds.sqs.xml.RegexQueueHandler; import org.jclouds.sqs.xml.ValueHandler; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -72,7 +72,7 @@ public interface QueueAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ListQueues") @ResponseParser(RegexListQueuesResponseHandler.class) - ListenableFuture> list(); + ListenableFuture> list(); /** * @see QueueApi#list(ListQueuesOptions) @@ -81,7 +81,7 @@ public interface QueueAsyncApi { @Path("/") @FormParams(keys = ACTION, values = "ListQueues") @ResponseParser(RegexListQueuesResponseHandler.class) - ListenableFuture> list(ListQueuesOptions options); + ListenableFuture> list(ListQueuesOptions options); /** * @see QueueApi#create diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java index 76c5551add..e30c82b607 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/xml/ReceiveMessageResponseHandler.java @@ -20,13 +20,12 @@ package org.jclouds.sqs.xml; import static org.jclouds.util.SaxUtils.equalsOrSuffix; -import java.util.List; - import org.jclouds.http.functions.ParseSax; import org.jclouds.sqs.domain.Message; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import com.google.inject.Inject; @@ -38,7 +37,7 @@ import com.google.inject.Inject; * * @author Adrian Cole */ -public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { +public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { private final MessageHandler messageHandler; @@ -52,8 +51,8 @@ public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedR } @Override - public List getResult() { - return messages.build(); + public FluentIterable getResult() { + return FluentIterable.from(messages.build()); } @Override diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java index 58b580f9d1..dfcccc0b00 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/xml/RegexListQueuesResponseHandler.java @@ -19,7 +19,6 @@ package org.jclouds.sqs.xml; import java.net.URI; -import java.util.Set; import javax.inject.Inject; import javax.inject.Singleton; @@ -29,6 +28,7 @@ import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler; import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; /** * @@ -38,7 +38,7 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements Function> { +public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements Function> { private final ReturnStringIf2xx returnStringIf200; @Inject @@ -47,7 +47,7 @@ public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implem } @Override - public Set apply(HttpResponse response) { + public FluentIterable apply(HttpResponse response) { return parse(returnStringIf200.apply(response)); } diff --git a/apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java b/apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java index a2c7a5f464..e191f44cac 100644 --- a/apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java +++ b/apis/sqs/src/main/java/org/jclouds/sqs/xml/internal/BaseRegexQueueHandler.java @@ -19,13 +19,13 @@ package org.jclouds.sqs.xml.internal; import java.net.URI; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.inject.Singleton; import com.google.common.base.Strings; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableSet.Builder; public class BaseRegexQueueHandler { protected final Pattern pattern = Pattern.compile("(https://[\\S&&[^<]]+)"); - public Set parse(String in) { + public FluentIterable parse(String in) { Builder queues = ImmutableSet. builder(); Matcher matcher = pattern.matcher(in); while (matcher.find()) { @@ -48,7 +48,7 @@ public class BaseRegexQueueHandler { if (!Strings.isNullOrEmpty(uriText)) queues.add(URI.create(uriText)); } - return queues.build(); + return FluentIterable.from(queues.build()); } } diff --git a/apis/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java index 7bb8376b7e..9e0fe24c8a 100644 --- a/apis/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java +++ b/apis/sqs/src/test/java/org/jclouds/sqs/features/BulkMessageApiLiveTest.java @@ -114,7 +114,7 @@ public class BulkMessageApiLiveTest extends BaseSQSApiLiveTest { // you are not guaranteed to get all messages in the same request Set messages = Sets.newLinkedHashSet(); while (messages.size() != idPayload.size()) - messages.addAll(api.receive(idPayload.size(), attribute("None").visibilityTimeout(5))); + messages.addAll(api.receive(idPayload.size(), attribute("None").visibilityTimeout(5)).toImmutableSet()); return messages; } diff --git a/apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java index d6481ece9a..799ff2d887 100644 --- a/apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java +++ b/apis/sqs/src/test/java/org/jclouds/sqs/features/QueueApiLiveTest.java @@ -24,11 +24,11 @@ import static org.testng.Assert.assertNotNull; import java.net.URI; import java.util.Map; -import java.util.Set; import org.jclouds.sqs.internal.BaseSQSApiLiveTest; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; /** @@ -48,7 +48,7 @@ public class QueueApiLiveTest extends BaseSQSApiLiveTest { } protected void listQueuesInRegion(String region) throws InterruptedException { - Set allResults = api().getQueueApiForRegion(region).list(); + FluentIterable allResults = api().getQueueApiForRegion(region).list(); assertNotNull(allResults); if (allResults.size() >= 1) { URI queue = getLast(allResults); diff --git a/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index 35799ec397..96031c8fa5 100644 --- a/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -39,6 +39,7 @@ import org.jclouds.sqs.features.QueueApi; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.Uninterruptibles; @@ -60,7 +61,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest result = api.list(queuePrefix(queueName)); + FluentIterable result = api.list(queuePrefix(queueName)); if (result.size() >= 1) { api.delete(getLast(result)); } @@ -110,7 +111,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest result = api().getQueueApiForRegion(region).list(); + FluentIterable result = api().getQueueApiForRegion(region).list(); assertNotNull(result); assert result.size() >= 1 : result; assertTrue(result.contains(finalQ), finalQ + " not in " + result); diff --git a/apis/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java index 77f50ee0b1..0afa837bf1 100644 --- a/apis/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java +++ b/apis/sqs/src/test/java/org/jclouds/sqs/parse/ReceiveMessageResponseTest.java @@ -21,7 +21,6 @@ package org.jclouds.sqs.parse; import static org.testng.Assert.assertEquals; import java.io.InputStream; -import java.util.List; import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.functions.BaseHandlerTest; @@ -29,6 +28,7 @@ import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.hash.HashCodes; @@ -43,17 +43,17 @@ public class ReceiveMessageResponseTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/messages.xml"); - List expected = expected(); + FluentIterable expected = expected(); ReceiveMessageResponseHandler handler = injector.getInstance(ReceiveMessageResponseHandler.class); - List result = factory.create(handler).parse(is); + FluentIterable result = factory.create(handler).parse(is); assertEquals(result.toString(), expected.toString()); } - public List expected() { - return ImmutableList.of(Message + public FluentIterable expected() { + return FluentIterable.from(ImmutableList.of(Message .builder() .id("5fea7756-0ea4-451a-a703-a558b933e274") .receiptHandle( @@ -63,6 +63,6 @@ public class ReceiveMessageResponseTest extends BaseHandlerTest { .addAttribute("SenderId", "195004372649") .addAttribute("SentTimestamp", "1238099229000") .addAttribute("ApproximateReceiveCount", "5") - .addAttribute("ApproximateFirstReceiveTimestamp", "1250700979248").build()); + .addAttribute("ApproximateFirstReceiveTimestamp", "1250700979248").build())); } } diff --git a/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerApi.java b/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerApi.java index 3c2f0d3379..2f31b15f2b 100644 --- a/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerApi.java +++ b/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerApi.java @@ -39,16 +39,16 @@ import org.jclouds.javax.annotation.Nullable; @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface LoadBalancerApi { - String createLoadBalancerListeningInAvailabilityZones(String name, Iterable listeners, + String createListeningInAvailabilityZones(String name, Iterable listeners, Iterable availabilityZones); - String createLoadBalancerListeningInAvailabilityZones(String name, Listener listeners, + String createListeningInAvailabilityZones(String name, Listener listeners, Iterable availabilityZones); - String createLoadBalancerListeningInSubnetAssignedToSecurityGroups(String name, String subnetId, + String createListeningInSubnetAssignedToSecurityGroups(String name, String subnetId, Iterable securityGroupIds); - String createLoadBalancerListeningInSubnetsAssignedToSecurityGroups(String name, Iterable subnetIds, + String createListeningInSubnetsAssignedToSecurityGroups(String name, Iterable subnetIds, Iterable securityGroupIds); diff --git a/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerAsyncApi.java b/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerAsyncApi.java index a38804185f..a88b74c23b 100644 --- a/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerAsyncApi.java +++ b/labs/elb/src/main/java/org/jclouds/elb/features/LoadBalancerAsyncApi.java @@ -45,6 +45,8 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnEmptyIterableWithMarkerOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; @@ -63,47 +65,47 @@ import com.google.common.util.concurrent.ListenableFuture; @VirtualHost public interface LoadBalancerAsyncApi { /** - * @see LoadBalancerApi#createLoadBalancerListeningInAvailabilityZones() + * @see LoadBalancerApi#createListeningInAvailabilityZones() */ @POST @Path("/") @XMLResponseParser(CreateLoadBalancerResponseHandler.class) @FormParams(keys = ACTION, values = "CreateLoadBalancer") - ListenableFuture createLoadBalancerListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name, + ListenableFuture createListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name, @BinderParam(BindListenersToFormParams.class) Listener listeners, @BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable availabilityZones); /** - * @see LoadBalancerApi#createLoadBalancerListeningInAvailabilityZones() + * @see LoadBalancerApi#createListeningInAvailabilityZones() */ @POST @Path("/") @XMLResponseParser(CreateLoadBalancerResponseHandler.class) @FormParams(keys = ACTION, values = "CreateLoadBalancer") - ListenableFuture createLoadBalancerListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name, + ListenableFuture createListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name, @BinderParam(BindListenersToFormParams.class) Iterable listeners, @BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable availabilityZones); /** - * @see LoadBalancerApi#createLoadBalancerListeningInSubnetAssignedToSecurityGroups() + * @see LoadBalancerApi#createListeningInSubnetAssignedToSecurityGroups() */ @POST @Path("/") @XMLResponseParser(CreateLoadBalancerResponseHandler.class) @FormParams(keys = ACTION, values = "CreateLoadBalancer") - ListenableFuture createLoadBalancerListeningInSubnetAssignedToSecurityGroups( + ListenableFuture createListeningInSubnetAssignedToSecurityGroups( @FormParam("LoadBalancerName") String name, @FormParam("Subnets.member.1") String subnetId, @BinderParam(BindSecurityGroupsToIndexedFormParams.class) Iterable securityGroupIds); /** - * @see LoadBalancerApi#createLoadBalancerListeningInSubnetsAssignedToSecurityGroups() + * @see LoadBalancerApi#createListeningInSubnetsAssignedToSecurityGroups() */ @POST @Path("/") @XMLResponseParser(CreateLoadBalancerResponseHandler.class) @FormParams(keys = ACTION, values = "CreateLoadBalancer") - ListenableFuture createLoadBalancerListeningInSubnetsAssignedToSecurityGroups( + ListenableFuture createListeningInSubnetsAssignedToSecurityGroups( @FormParam("LoadBalancerName") String name, @BinderParam(BindSubnetsToIndexedFormParams.class) Iterable subnetIds, @BinderParam(BindSecurityGroupsToIndexedFormParams.class) Iterable securityGroupIds); @@ -125,6 +127,7 @@ public interface LoadBalancerAsyncApi { @Path("/") @XMLResponseParser(DescribeLoadBalancersResultHandler.class) @Transform(LoadBalancersToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) @FormParams(keys = "Action", values = "DescribeLoadBalancers") ListenableFuture> list(); @@ -134,6 +137,7 @@ public interface LoadBalancerAsyncApi { @POST @Path("/") @XMLResponseParser(DescribeLoadBalancersResultHandler.class) + @ExceptionParser(ReturnEmptyIterableWithMarkerOnNotFoundOr404.class) @FormParams(keys = "Action", values = "DescribeLoadBalancers") ListenableFuture> list(ListLoadBalancersOptions options); diff --git a/labs/elb/src/main/java/org/jclouds/elb/loadbalancer/strategy/ELBLoadBalanceNodesStrategy.java b/labs/elb/src/main/java/org/jclouds/elb/loadbalancer/strategy/ELBLoadBalanceNodesStrategy.java index e7f901c34b..be5a952183 100644 --- a/labs/elb/src/main/java/org/jclouds/elb/loadbalancer/strategy/ELBLoadBalanceNodesStrategy.java +++ b/labs/elb/src/main/java/org/jclouds/elb/loadbalancer/strategy/ELBLoadBalanceNodesStrategy.java @@ -82,7 +82,7 @@ public class ELBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy { logger.debug(">> creating loadBalancer(%s) in zones(%s)", name, zonesDesired); try { - String dnsName = api.getLoadBalancerApiForRegion(region).createLoadBalancerListeningInAvailabilityZones( + String dnsName = api.getLoadBalancerApiForRegion(region).createListeningInAvailabilityZones( name, ImmutableSet.of(Listener.builder().port(loadBalancerPort).instancePort(instancePort) .protocol(Protocol.valueOf(protocol)).build()), zonesDesired); diff --git a/labs/elb/src/test/java/org/jclouds/elb/features/LoadBalancerApiExpectTest.java b/labs/elb/src/test/java/org/jclouds/elb/features/LoadBalancerApiExpectTest.java index ab4ddb4778..f82a6eddef 100644 --- a/labs/elb/src/test/java/org/jclouds/elb/features/LoadBalancerApiExpectTest.java +++ b/labs/elb/src/test/java/org/jclouds/elb/features/LoadBalancerApiExpectTest.java @@ -24,6 +24,7 @@ import static org.testng.Assert.assertNull; import java.util.TimeZone; +import org.jclouds.collect.IterableWithMarkers; import org.jclouds.elb.ELBApi; import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.internal.BaseELBApiExpectTest; @@ -31,7 +32,6 @@ import org.jclouds.elb.parse.DescribeLoadBalancersResponseTest; import org.jclouds.elb.parse.GetLoadBalancerResponseTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -197,8 +197,6 @@ public class LoadBalancerApiExpectTest extends BaseELBApiExpectTest { assertEquals(ImmutableSet.copyOf(Iterables.concat(apiWhenExist.getLoadBalancerApiForRegion("eu-west-1").list())), ImmutableSet.of(lb1, lb2)); } - // TODO: this should really be an empty set - @Test(expectedExceptions = ResourceNotFoundException.class) public void testListWhenResponseIs404() throws Exception { HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); @@ -206,7 +204,8 @@ public class LoadBalancerApiExpectTest extends BaseELBApiExpectTest { ELBApi apiWhenDontExist = requestSendsResponse( list, listResponse); - apiWhenDontExist.getLoadBalancerApi().list(); + assertEquals(apiWhenDontExist.getLoadBalancerApi().list().get(0), IterableWithMarkers.EMPTY); + } public void testListWithOptionsWhenResponseIs2xx() throws Exception { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java index eb3a8c5ac6..5422ad9950 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java @@ -38,10 +38,10 @@ import org.jclouds.aws.ec2.domain.MonitoringState; import org.jclouds.aws.ec2.services.AWSSecurityGroupClient; import org.jclouds.cloudwatch.CloudWatchApi; import org.jclouds.cloudwatch.CloudWatchAsyncApi; -import org.jclouds.cloudwatch.domain.Datapoint; import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.EC2Constants; import org.jclouds.cloudwatch.domain.GetMetricStatistics; +import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse; import org.jclouds.cloudwatch.domain.Statistics; import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.compute.domain.ExecResponse; @@ -170,7 +170,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { .modules(setupModules()).build(); try { - Set datapoints = monitoringContext.getApi().getMetricApiForRegion(instance.getRegion()) + GetMetricStatisticsResponse datapoints = monitoringContext.getApi().getMetricApiForRegion(instance.getRegion()) .getMetricStatistics(GetMetricStatistics.builder() .dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, instance.getId())) .unit(Unit.PERCENT) From dcca748a79c26005f7e94e42ea28c37aaa92e066 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 15 Sep 2012 23:48:35 -0700 Subject: [PATCH 30/60] unused imports --- .../filesystem/FilesystemAsyncBlobStoreTest.java | 1 - .../internal/FilesystemStorageStrategyImplTest.java | 1 - .../org/jclouds/openstack/nova/domain/Resource.java | 1 - .../glesys/compute/GleSYSComputeServiceAdapter.java | 2 +- .../ParseOsFamilyVersion64BitFromImageName.java | 3 +-- .../glesys/config/GleSYSRestClientModule.java | 12 ++++++------ .../glesys/internal/BaseGleSYSApiLiveTest.java | 2 +- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java index 2aa607970c..4dfa8ccc78 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java @@ -60,7 +60,6 @@ import org.jclouds.io.payloads.PhantomPayload; import org.jclouds.io.payloads.StringPayload; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import com.google.common.io.ByteStreams; diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java index f3790c14a7..583b64481c 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java @@ -46,7 +46,6 @@ import org.jclouds.filesystem.utils.TestUtils; import org.jclouds.io.payloads.FilePayload; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import com.google.common.io.ByteStreams; diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java index 53ff322bfb..ba6c597e64 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java @@ -20,7 +20,6 @@ package org.jclouds.openstack.nova.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.beans.ConstructorProperties; import java.net.URI; import java.net.URISyntaxException; import java.util.List; diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java index 85622d3b27..05ec0d3de2 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java @@ -49,8 +49,8 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; -import org.jclouds.glesys.GleSYSAsyncApi; import org.jclouds.glesys.GleSYSApi; +import org.jclouds.glesys.GleSYSAsyncApi; import org.jclouds.glesys.compute.options.GleSYSTemplateOptions; import org.jclouds.glesys.domain.AllowedArgumentsForCreateServer; import org.jclouds.glesys.domain.OSTemplate; diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java index f9624c18a9..670dd615b6 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java @@ -74,8 +74,7 @@ public class ParseOsFamilyVersion64BitFromImageName implements Function Date: Sun, 16 Sep 2012 00:19:30 -0700 Subject: [PATCH 31/60] pagination and consistency cleanup on openstack --- .../openstack/keystone/v2_0/KeystoneApi.java | 3 - .../v2_0/config/KeystoneRestClientModule.java | 2 +- .../keystone/v2_0/domain/Access.java | 6 +- .../v2_0/domain/PaginatedCollection.java | 87 +++++++++ .../keystone/v2_0/features/TenantApi.java | 8 +- .../v2_0/features/TenantAsyncApi.java | 28 ++- .../keystone/v2_0/features/UserApi.java | 7 +- .../keystone/v2_0/features/UserAsyncApi.java | 40 +++- ...ptyPaginatedCollectionOnNotFoundOr404.java | 58 ++++++ .../v2_0/functions/internal/ParseTenants.java | 96 ++++++++++ .../v2_0/functions/internal/ParseUsers.java | 96 ++++++++++ .../jclouds/openstack/v2_0/domain/Link.java | 96 +++++----- .../openstack/v2_0/features/ExtensionApi.java | 6 +- .../v2_0/features/ExtensionAsyncApi.java | 8 +- ...istOptions.java => PaginationOptions.java} | 48 +++-- .../v2_0/predicates/LinkPredicates.java | 2 +- .../v2_0/features/TenantApiExpectTest.java | 36 +++- .../v2_0/features/TenantApiLiveTest.java | 4 +- .../v2_0/features/UserApiExpectTest.java | 43 +++-- .../v2_0/features/UserApiLiveTest.java | 11 +- ...EqualsAnyNamespaceInExtensionsSetTest.java | 3 - ...nsTest.java => PaginationOptionsTest.java} | 42 ++-- .../jclouds/openstack/nova/v2_0/NovaApi.java | 4 +- .../openstack/nova/v2_0/NovaAsyncApi.java | 4 +- .../nova/v2_0/compute/NovaComputeService.java | 23 +-- .../compute/NovaComputeServiceAdapter.java | 24 +-- .../extensions/NovaImageExtension.java | 4 +- .../AllocateAndAddFloatingIpToNode.java | 4 +- .../CreateSecurityGroupIfNeeded.java | 8 +- ...RemoveFloatingIpFromNodeAndDeallocate.java | 2 +- .../compute/loaders/CreateUniqueKeyPair.java | 2 +- .../loaders/LoadFloatingIpsForInstance.java | 3 +- .../compute/options/NovaTemplateOptions.java | 2 +- ...oneHasActiveStatusPredicateWithResult.java | 3 +- .../v2_0/config/NovaRestClientModule.java | 9 +- .../openstack/nova/v2_0/domain/Flavor.java | 2 +- .../v2_0/domain/{Quotas.java => Quota.java} | 38 ++-- .../nova/v2_0/domain/QuotaClass.java | 4 +- .../v2_0/extensions/FlavorExtraSpecsApi.java | 16 +- .../extensions/FlavorExtraSpecsAsyncApi.java | 25 ++- .../nova/v2_0/extensions/FloatingIPApi.java | 13 +- .../v2_0/extensions/FloatingIPAsyncApi.java | 25 +-- .../extensions/HostAdministrationApi.java | 23 ++- .../HostAdministrationAsyncApi.java | 47 ++--- .../v2_0/extensions/HostAggregateApi.java | 16 +- .../extensions/HostAggregateAsyncApi.java | 27 ++- .../nova/v2_0/extensions/KeyPairApi.java | 14 +- .../nova/v2_0/extensions/KeyPairAsyncApi.java | 22 ++- .../nova/v2_0/extensions/QuotaApi.java | 14 +- .../nova/v2_0/extensions/QuotaAsyncApi.java | 23 ++- .../nova/v2_0/extensions/QuotaClassApi.java | 10 +- .../v2_0/extensions/QuotaClassAsyncApi.java | 14 +- .../v2_0/extensions/SecurityGroupApi.java | 21 +- .../extensions/SecurityGroupAsyncApi.java | 35 ++-- ...minActionsApi.java => ServerAdminApi.java} | 29 +-- ...AsyncApi.java => ServerAdminAsyncApi.java} | 50 ++--- .../ServerWithSecurityGroupsApi.java | 5 +- .../ServerWithSecurityGroupsAsyncApi.java | 6 +- .../v2_0/extensions/SimpleTenantUsageApi.java | 9 +- .../extensions/SimpleTenantUsageAsyncApi.java | 17 +- .../v2_0/extensions/VirtualInterfaceApi.java | 7 +- .../extensions/VirtualInterfaceAsyncApi.java | 13 +- .../nova/v2_0/extensions/VolumeApi.java | 24 ++- .../nova/v2_0/extensions/VolumeAsyncApi.java | 33 ++-- .../nova/v2_0/extensions/VolumeTypeApi.java | 24 +-- .../v2_0/extensions/VolumeTypeAsyncApi.java | 36 ++-- .../nova/v2_0/features/FlavorApi.java | 18 +- .../nova/v2_0/features/FlavorAsyncApi.java | 62 ++++-- .../nova/v2_0/features/ImageApi.java | 16 +- .../nova/v2_0/features/ImageAsyncApi.java | 58 ++++-- .../nova/v2_0/features/ServerApi.java | 34 ++-- .../nova/v2_0/features/ServerAsyncApi.java | 94 +++++---- .../internal/ParseFlavorDetails.java | 96 ++++++++++ .../v2_0/functions/internal/ParseFlavors.java | 96 ++++++++++ .../functions/internal/ParseImageDetails.java | 96 ++++++++++ .../v2_0/functions/internal/ParseImages.java | 96 ++++++++++ .../functions/internal/ParseKeyPairs.java | 66 +++++++ .../internal/ParseServerDetails.java | 96 ++++++++++ .../v2_0/functions/internal/ParseServers.java | 96 ++++++++++ .../options/CreateBackupOfServerOptions.java | 2 +- .../v2_0/options/CreateServerOptions.java | 2 +- .../nova/v2_0/options/ListOptions.java | 26 +-- ...indSecurityGroupWithNameAndReturnTrue.java | 2 +- ...eyAndTenantIdAuthenticationExpectTest.java | 2 +- ...tNamePropertyAuthenticationExpectTest.java | 2 +- ...yAndSecretKeyAuthenticationExpectTest.java | 2 +- .../PasswordAuthenticationExpectTest.java | 2 +- ...uthenticationWithTenantNameExpectTest.java | 2 +- .../NovaComputeServiceAdapterExpectTest.java | 4 +- .../compute/NovaComputeServiceExpectTest.java | 26 +-- ...ocateAndAddFloatingIpToNodeExpectTest.java | 8 +- .../loaders/CreateUniqueKeyPairTest.java | 6 +- .../LoadFloatingIpsForInstanceTest.java | 12 +- ...veStatusPredicateWithResultExpectTest.java | 4 +- .../extensions/AdminActionsApiExpectTest.java | 96 +++++----- .../extensions/AdminActionsApiLiveTest.java | 56 +++--- .../FlavorExtraSpecsApiExpectTest.java | 16 +- .../FlavorExtraSpecsApiLiveTest.java | 30 +-- .../extensions/FloatingIPApiExpectTest.java | 32 ++-- .../extensions/FloatingIPApiLiveTest.java | 16 +- .../FloatingIPAsyncApiExpectTest.java | 32 ++-- .../HostAdministrationApiExpectTest.java | 26 +-- .../HostAdministrationApiLiveTest.java | 26 +-- .../HostAggregateApiExpectTest.java | 12 +- .../extensions/HostAggregateApiLiveTest.java | 14 +- .../v2_0/extensions/KeyPairApiExpectTest.java | 40 ++-- .../v2_0/extensions/KeyPairApiLiveTest.java | 15 +- .../v2_0/extensions/QuotaApiExpectTest.java | 18 +- .../v2_0/extensions/QuotaApiLiveTest.java | 20 +- .../extensions/QuotaClassApiExpectTest.java | 8 +- .../extensions/QuotaClassApiLiveTest.java | 8 +- .../SecurityGroupApiExpectTest.java | 76 ++++---- .../extensions/SecurityGroupApiLiveTest.java | 20 +- ...ServerWithSecurityGroupsApiExpectTest.java | 4 +- .../ServerWithSecurityGroupsApiLiveTest.java | 8 +- .../SimpleTenantUsageApiExpectTest.java | 4 +- .../SimpleTenantUsageApiLiveTest.java | 4 +- .../VirtualInterfaceApiExpectTest.java | 4 +- .../VirtualInterfaceApiLiveTest.java | 4 +- .../v2_0/extensions/VolumeApiExpectTest.java | 30 +-- .../v2_0/extensions/VolumeApiLiveTest.java | 32 ++-- .../extensions/VolumeTypeApiExpectTest.java | 24 +-- .../extensions/VolumeTypeApiLiveTest.java | 24 +-- .../v2_0/features/ExtensionApiExpectTest.java | 8 +- .../v2_0/features/ExtensionApiLiveTest.java | 6 +- .../v2_0/features/FlavorApiExpectTest.java | 8 +- .../nova/v2_0/features/FlavorApiLiveTest.java | 8 +- .../v2_0/features/ImageApiExpectTest.java | 20 +- .../nova/v2_0/features/ImageApiLiveTest.java | 8 +- .../v2_0/features/ServerApiExpectTest.java | 16 +- .../nova/v2_0/features/ServerApiLiveTest.java | 8 +- .../CreateSecurityGroupIfNeededTest.java | 16 +- ...yGroupWithNameAndReturnTrueExpectTest.java | 16 +- .../v2_0/internal/BaseNovaApiLiveTest.java | 12 +- ...seNovaComputeServiceContextExpectTest.java | 4 +- .../nova/v2_0/parse/ParseKeyPairListTest.java | 26 +-- .../openstack/glance/v1_0/GlanceApi.java | 16 +- .../glance/v1_0/GlanceApiMetadata.java | 4 +- .../openstack/glance/v1_0/GlanceAsyncApi.java | 16 +- .../v1_0/config/GlanceRestClientModule.java | 2 +- .../glance/v1_0/features/ImageApi.java | 29 ++- .../glance/v1_0/features/ImageAsyncApi.java | 55 ++++-- .../functions/internal/ParseImageDetails.java | 96 ++++++++++ .../v1_0/functions/internal/ParseImages.java | 96 ++++++++++ .../glance/v1_0/options/ListImageOptions.java | 44 ++--- .../v1_0/features/ImageApiExpectTest.java | 68 +++---- .../v1_0/features/ImageApiLiveTest.java | 28 +-- .../openstack/quantum/v1_0/QuantumApi.java | 17 +- .../quantum/v1_0/QuantumApiMetadata.java | 4 +- .../quantum/v1_0/QuantumAsyncApi.java | 18 +- .../v1_0/config/QuantumRestClientModule.java | 3 +- .../quantum/v1_0/features/NetworkApi.java | 7 +- .../v1_0/features/NetworkAsyncApi.java | 13 +- .../quantum/v1_0/features/PortApi.java | 7 +- .../quantum/v1_0/features/PortAsyncApi.java | 13 +- .../v1_0/features/NetworkApiExpectTest.java | 32 ++-- .../v1_0/features/NetworkApiLiveTest.java | 10 +- .../v1_0/features/PortApiExpectTest.java | 40 ++-- .../v1_0/features/PortApiLiveTest.java | 24 +-- .../v1/config/SwiftRestClientModule.java | 3 +- .../{AccountMetadata.java => Account.java} | 18 +- ...{ContainerMetadata.java => Container.java} | 24 +-- .../swift/v1/features/AccountApi.java | 23 +-- .../swift/v1/features/AccountAsyncApi.java | 35 +--- .../swift/v1/features/ContainerApi.java | 19 ++ .../swift/v1/features/ContainerAsyncApi.java | 32 ++++ ...rseAccountMetadataResponseFromHeaders.java | 12 +- .../v1/PasswordAuthenticationExpectTest.java | 8 +- .../v1/features/AccountApiExpectTest.java | 53 +---- .../swift/v1/features/AccountApiLiveTest.java | 20 +- .../v1/features/ContainerApiExpectTest.java | 45 +++++ .../v1/features/ContainerApiLiveTest.java | 19 ++ .../v1/parse/ParseContainerListTest.java | 10 +- ...ient.java => HPCloudObjectStorageApi.java} | 18 +- .../HPCloudObjectStorageApiMetadata.java | 4 +- ...java => HPCloudObjectStorageAsyncApi.java} | 19 +- .../HPCloudObjectStorageAsyncBlobStore.java | 14 +- ...HPCloudObjectStorageBlobRequestSigner.java | 12 +- .../HPCloudObjectStorageBlobStore.java | 12 +- ...udObjectStorageBlobStoreContextModule.java | 16 +- .../functions/EnableCDNAndCache.java | 12 +- .../HPCloudObjectStorageRestClientModule.java | 18 +- ...inerCDNMetadata.java => CDNContainer.java} | 181 ++++++++---------- ...oudCDNClient.java => CDNContainerApi.java} | 40 ++-- ...cClient.java => CDNContainerAsyncApi.java} | 66 ++++--- ...java => ParseCDNContainerFromHeaders.java} | 14 +- .../HPCloudObjectStorageClientLiveTest.java | 51 ++--- ...erCDNMetadataListFromJsonResponseTest.java | 68 ------- .../parse/CDNContainersTest.java | 55 ++++++ 189 files changed, 3166 insertions(+), 1742 deletions(-) create mode 100644 apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PaginatedCollection.java create mode 100644 apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/ReturnEmptyPaginatedCollectionOnNotFoundOr404.java create mode 100644 apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseTenants.java create mode 100644 apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseUsers.java rename apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/{BaseListOptions.java => PaginationOptions.java} (59%) rename apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/{BaseListOptionsTest.java => PaginationOptionsTest.java} (56%) rename apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/{Quotas.java => Quota.java} (90%) rename apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/{AdminActionsApi.java => ServerAdminApi.java} (79%) rename apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/{AdminActionsAsyncApi.java => ServerAdminAsyncApi.java} (76%) create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavorDetails.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavors.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImageDetails.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImages.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseKeyPairs.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServerDetails.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServers.java create mode 100644 labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImageDetails.java create mode 100644 labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImages.java rename labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/{AccountMetadata.java => Account.java} (82%) rename labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/{ContainerMetadata.java => Container.java} (81%) rename providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/{HPCloudObjectStorageClient.java => HPCloudObjectStorageApi.java} (79%) rename providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/{HPCloudObjectStorageAsyncClient.java => HPCloudObjectStorageAsyncApi.java} (85%) rename providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/{ContainerCDNMetadata.java => CDNContainer.java} (54%) rename providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/{HPCloudCDNClient.java => CDNContainerApi.java} (74%) rename providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/{HPCloudCDNAsyncClient.java => CDNContainerAsyncApi.java} (60%) rename providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/{ParseContainerCDNMetadataFromHeaders.java => ParseCDNContainerFromHeaders.java} (81%) delete mode 100644 providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java create mode 100644 providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/parse/CDNContainersTest.java diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneApi.java index 125b9ec155..2e83b5afb2 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneApi.java @@ -21,8 +21,6 @@ package org.jclouds.openstack.keystone.v2_0; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata; import org.jclouds.openstack.keystone.v2_0.features.ServiceApi; import org.jclouds.openstack.keystone.v2_0.features.TenantApi; @@ -30,7 +28,6 @@ import org.jclouds.openstack.keystone.v2_0.features.TokenApi; import org.jclouds.openstack.keystone.v2_0.features.UserApi; import org.jclouds.openstack.v2_0.features.ExtensionApi; import org.jclouds.rest.annotations.Delegate; -import org.jclouds.rest.annotations.EndpointParam; import com.google.common.base.Optional; diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java index f473be2466..ac8d3433dd 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java @@ -143,7 +143,7 @@ public class KeystoneRestClientModule>() { @Override public Set get() { - return keystoneApi.get().getExtensionApi().listExtensions(); + return keystoneApi.get().getExtensionApi().list(); } }))); } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java index ca5745afc2..c4baf00dd0 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Set; +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; @@ -105,10 +107,10 @@ public class Access implements Comparable { @ConstructorProperties({ "token", "user", "serviceCatalog" }) - protected Access(Token token, User user, Set serviceCatalog) { + protected Access(Token token, User user, @Nullable Set serviceCatalog) { this.token = checkNotNull(token, "token"); this.user = checkNotNull(user, "user"); - this.serviceCatalog = ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog")); + this.serviceCatalog = serviceCatalog == null ? ImmutableSet.of() : ImmutableSet.copyOf(serviceCatalog); } /** diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PaginatedCollection.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PaginatedCollection.java new file mode 100644 index 0000000000..2d8758025d --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PaginatedCollection.java @@ -0,0 +1,87 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.keystone.v2_0.domain; + +import static org.jclouds.http.utils.Queries.parseQueryToMap; + +import java.util.Collection; +import java.util.Iterator; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * base class for a paginated collection in openstack + * + * @see + * docs + * @author Adrian Cole + */ +@Beta +public class PaginatedCollection extends IterableWithMarker { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static final PaginatedCollection EMPTY = new PaginatedCollection(ImmutableSet.of(), ImmutableSet.of()); + + private Iterable resources; + private Iterable links; + + protected PaginatedCollection(Iterable resources, Iterable links) { + this.resources = resources != null ? resources : ImmutableSet. of(); + this.links = links != null ? links : ImmutableSet. of(); + } + + @Override + public Iterator iterator() { + return resources.iterator(); + } + + /** + * links that relate to this collection + */ + public Iterable getLinks() { + return links; + } + + @Override + public Optional nextMarker() { + return FluentIterable.from(getLinks()).filter(new Predicate() { + @Override + public boolean apply(Link link) { + return Link.Relation.NEXT == link.getRelation(); + } + }).transform(new Function>() { + @Override + public Optional apply(Link link) { + Collection markers = parseQueryToMap(link.getHref().getRawQuery()).get("marker"); + return Optional. fromNullable(markers == null ? null : Iterables.get(markers, 0)); + } + }).first().or(Optional.absent()); + } + +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantApi.java index 68a0118f43..813826155c 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantApi.java @@ -18,11 +18,13 @@ */ package org.jclouds.openstack.keystone.v2_0.features; -import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.domain.Tenant; +import org.jclouds.openstack.v2_0.options.PaginationOptions; /** * Provides synchronous access to the KeyStone Tenant API. @@ -40,7 +42,9 @@ public interface TenantApi { /** * The operation returns a list of tenants which the current token provides access to. */ - Set list(); + PagedIterable list(); + + PaginatedCollection list(PaginationOptions options); /** * Retrieve information about a tenant, by tenant ID diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncApi.java index 43b1ebefe9..b2476cebe9 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.keystone.v2_0.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -27,14 +25,22 @@ import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.jclouds.collect.PagedIterable; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.domain.Tenant; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; +import org.jclouds.openstack.keystone.v2_0.functions.internal.ParseTenants; +import org.jclouds.openstack.keystone.v2_0.functions.internal.ParseTenants.ToPagedIterable; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.openstack.v2_0.services.Identity; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -57,12 +63,22 @@ public interface TenantAsyncApi { * @see TenantApi#list() */ @GET - @SelectJson("tenants") @Consumes(MediaType.APPLICATION_JSON) @Path("/tenants") @RequestFilters(AuthenticateRequest.class) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> list(); + @ResponseParser(ParseTenants.class) + @Transform(ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** @see TenantApi#list(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/tenants") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseTenants.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> list(PaginationOptions options); /** @see TenantApi#get(String) */ @GET diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserApi.java index 619ecf0153..ff7499914d 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserApi.java @@ -21,9 +21,12 @@ package org.jclouds.openstack.keystone.v2_0.features; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.domain.Role; import org.jclouds.openstack.keystone.v2_0.domain.User; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import com.google.common.annotations.Beta; @@ -48,7 +51,9 @@ public interface UserApi { * * @return the list of users */ - Set list(); + PagedIterable list(); + + PaginatedCollection list(PaginationOptions options); /** * Retrieve information about a user, by user ID diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncApi.java index d7ba6a8bcb..f91d61f3b1 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncApi.java @@ -27,14 +27,23 @@ import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.jclouds.collect.PagedIterable; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.domain.Role; import org.jclouds.openstack.keystone.v2_0.domain.User; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; +import org.jclouds.openstack.keystone.v2_0.functions.internal.ParseUsers; +import org.jclouds.openstack.keystone.v2_0.functions.internal.ParseUsers.ToPagedIterable; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.openstack.v2_0.services.Identity; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -43,10 +52,10 @@ import com.google.common.util.concurrent.ListenableFuture; /** * Provides asynchronous access to User via their REST API. *

- * + * * @see UserApi * @see * @author Adam Lowe */ @@ -54,14 +63,26 @@ import com.google.common.util.concurrent.ListenableFuture; @SkipEncoding({ '/', '=' }) public interface UserAsyncApi { - /** @see UserApi#list() */ + /** + * @see UserApi#list() + */ @GET - @SelectJson("users") @Consumes(MediaType.APPLICATION_JSON) @Path("/users") @RequestFilters(AuthenticateRequest.class) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> list(); + @ResponseParser(ParseUsers.class) + @Transform(ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** @see UserApi#list(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/users") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseUsers.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> list(PaginationOptions options); /** @see UserApi#get(String) */ @GET @@ -71,7 +92,7 @@ public interface UserAsyncApi { @RequestFilters(AuthenticateRequest.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture get(@PathParam("userId") String userId); - + /** @see UserApi#getByName(String) */ @GET @SelectJson("user") @@ -80,7 +101,7 @@ public interface UserAsyncApi { @RequestFilters(AuthenticateRequest.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getByName(@QueryParam("name") String userName); - + /** @see UserApi#listRolesOfUser(String) */ @GET @SelectJson("roles") @@ -97,5 +118,6 @@ public interface UserAsyncApi { @Path("/tenants/{tenantId}/users/{userId}/roles") @RequestFilters(AuthenticateRequest.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listRolesOfUserOnTenant(@PathParam("userId") String userId, @PathParam("tenantId") String tenantId); + ListenableFuture> listRolesOfUserOnTenant(@PathParam("userId") String userId, + @PathParam("tenantId") String tenantId); } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/ReturnEmptyPaginatedCollectionOnNotFoundOr404.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/ReturnEmptyPaginatedCollectionOnNotFoundOr404.java new file mode 100644 index 0000000000..e454d20ea3 --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/ReturnEmptyPaginatedCollectionOnNotFoundOr404.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.keystone.v2_0.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.functions.ReturnTrueOn404; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Function; +import com.google.common.base.Throwables; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ReturnEmptyPaginatedCollectionOnNotFoundOr404 implements Function { + private final ReturnTrueOn404 rto404; + + @Inject + private ReturnEmptyPaginatedCollectionOnNotFoundOr404(ReturnTrueOn404 rto404) { + this.rto404 = checkNotNull(rto404, "rto404"); + } + + public Object apply(Exception from) { + Iterable throwables = Iterables.filter(Throwables.getCausalChain(from), + ResourceNotFoundException.class); + if (Iterables.size(throwables) >= 1) { + return PaginatedCollection.EMPTY; + } else if (rto404.apply(from)) { + return PaginatedCollection.EMPTY; + } + throw Throwables.propagate(from); + } + +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseTenants.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseTenants.java new file mode 100644 index 0000000000..bd1f867961 --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseTenants.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.keystone.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.KeystoneApi; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.keystone.v2_0.domain.Tenant; +import org.jclouds.openstack.keystone.v2_0.features.TenantApi; +import org.jclouds.openstack.keystone.v2_0.functions.internal.ParseTenants.Tenants; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseTenants extends ParseJson> { + static class Tenants extends PaginatedCollection { + + @ConstructorProperties({ "tenants", "tenants_links" }) + protected Tenants(Iterable tenants, Iterable tenants_links) { + super(tenants, tenants_links); + } + + } + + @Inject + public ParseTenants(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final KeystoneApi api; + + @Inject + protected ToPagedIterable(KeystoneApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String ignored) { + final TenantApi tenantApi = api.getTenantApi().get(); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(tenantApi.list(marker(input.toString()))); + } + + @Override + public String toString() { + return "listTenants()"; + } + }; + } + + } + +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseUsers.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseUsers.java new file mode 100644 index 0000000000..ad4dfb3041 --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/ParseUsers.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.keystone.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.KeystoneApi; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.keystone.v2_0.domain.User; +import org.jclouds.openstack.keystone.v2_0.features.UserApi; +import org.jclouds.openstack.keystone.v2_0.functions.internal.ParseUsers.Users; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseUsers extends ParseJson> { + static class Users extends PaginatedCollection { + + @ConstructorProperties({ "users", "users_links" }) + protected Users(Iterable users, Iterable users_links) { + super(users, users_links); + } + + } + + @Inject + public ParseUsers(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final KeystoneApi api; + + @Inject + protected ToPagedIterable(KeystoneApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String ignored) { + final UserApi userApi = api.getUserApi().get(); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(userApi.list(marker(input.toString()))); + } + + @Override + public String toString() { + return "listUsers()"; + } + }; + } + + } + +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java index 61e45b6aef..e5e82ff551 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java @@ -25,18 +25,17 @@ import java.net.URI; import javax.inject.Named; -import org.jclouds.javax.annotation.Nullable; - import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; /** * For convenience, resources contain links to themselves. This allows a api to easily obtain a * resource URIs rather than to construct them. - * + * * @author AdrianCole * @see + * /> */ public class Link { /** @@ -57,9 +56,17 @@ public class Link { */ DESCRIBEDBY, /** - * an alternate representation of the resource. For example, an OpenStack Compute image may - * have an alternate representation in the OpenStack Image service. + * Indicates that the link's context is a part of a series, and that the next in the series is + * the link target. */ + NEXT, + + /** + * Indicates that the link's context is a part of a series, and that the previous in the + * series is the link target. + */ + PREVIOUS, + ALTERNATE, /** * the value returned by the OpenStack service was not recognized. @@ -83,80 +90,67 @@ public class Link { return new Link(relation, null, href); } - public static Link create(Relation relation,String type, URI href) { - return new Link(relation, type, href); + public static Link create(Relation relation, String type, URI href) { + return new Link(relation, Optional.fromNullable(type), href); } - public static Builder builder() { - return new ConcreteBuilder(); + public static Builder builder() { + return new Builder(); } - public Builder toBuilder() { - return new ConcreteBuilder().fromLink(this); + public Builder toBuilder() { + return builder().fromLink(this); } - public static abstract class Builder> { - protected abstract T self(); + public static class Builder { protected Link.Relation relation; - protected String type; + protected Optional type = Optional.absent(); protected URI href; /** * @see Link#getRelation() */ - public T relation(Link.Relation relation) { + public Builder relation(Link.Relation relation) { this.relation = relation; - return self(); + return this; } /** * @see Link#getType() */ - public T type(String type) { - this.type = type; - return self(); + public Builder type(String type) { + this.type = Optional.fromNullable(type); + return this; } /** * @see Link#getHref() */ - public T href(URI href) { + public Builder href(URI href) { this.href = href; - return self(); + return this; } public Link build() { return new Link(relation, type, href); } - public T fromLink(Link in) { - return this - .relation(in.getRelation()) - .type(in.getType()) - .href(in.getHref()); - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; + public Builder fromLink(Link in) { + return this.relation(in.getRelation()).type(in.getType().orNull()).href(in.getHref()); } } @Named("rel") private final Link.Relation relation; - private final String type; + private final Optional type; private final URI href; - @ConstructorProperties({ - "rel", "type", "href" - }) - protected Link(Link.Relation relation, @Nullable String type, URI href) { - this.relation = checkNotNull(relation, "relation"); - this.type = type; + @ConstructorProperties({ "rel", "type", "href" }) + protected Link(Link.Relation relation, Optional type, URI href) { this.href = checkNotNull(href, "href"); + this.relation = checkNotNull(relation, "relation of %s", href); + this.type = (type == null) ? Optional. absent() : type; } /** @@ -167,7 +161,7 @@ public class Link { * of the resource. For example, an OpenStack Compute image may have an alternate representation * in the OpenStack Image service. Note that the type attribute here is used to provide a hint as * to the type of representation to expect when following the link. - * + * * @return the relation of the resource in the current OpenStack deployment */ public Link.Relation getRelation() { @@ -177,8 +171,7 @@ public class Link { /** * @return the type of the resource or null if not specified */ - @Nullable - public String getType() { + public Optional getType() { return this.type; } @@ -196,17 +189,18 @@ public class Link { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; Link that = Link.class.cast(obj); - return Objects.equal(this.relation, that.relation) - && Objects.equal(this.type, that.type) - && Objects.equal(this.href, that.href); + return Objects.equal(this.relation, that.relation) && Objects.equal(this.type, that.type) + && Objects.equal(this.href, that.href); } protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("relation", relation).add("type", type).add("href", href); + return Objects.toStringHelper(this).omitNullValues().add("relation", relation).add("type", type.orNull()) + .add("href", href); } @Override diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionApi.java index e8f746ea2a..7705ca498e 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionApi.java @@ -28,7 +28,7 @@ import org.jclouds.openstack.v2_0.domain.Extension; * Provides asynchronous access to Extensions via their REST API. *

* - * @see ExtensionApi + * @see ExtensionAsyncApi * @see @@ -42,7 +42,7 @@ public interface ExtensionApi { * * @return all extensions */ - Set listExtensions(); + Set list(); /** * Extensions may also be queried individually by their unique alias. @@ -51,6 +51,6 @@ public interface ExtensionApi { * id of the extension * @return extension or null if not found */ - Extension getExtensionByAlias(String alias); + Extension get(String alias); } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionAsyncApi.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionAsyncApi.java index c6b957f807..ef88c60272 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionAsyncApi.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/features/ExtensionAsyncApi.java @@ -52,23 +52,23 @@ import com.google.common.util.concurrent.ListenableFuture; public interface ExtensionAsyncApi { /** - * @see ExtensionApi#listExtensions + * @see ExtensionApi#list */ @GET @SelectJson("extensions") @Consumes(MediaType.APPLICATION_JSON) @Path("/extensions") @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listExtensions(); + ListenableFuture> list(); /** - * @see ExtensionApi#getExtensionByAlias + * @see ExtensionApi#get */ @GET @SelectJson("extension") @Consumes(MediaType.APPLICATION_JSON) @Path("/extensions/{alias}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getExtensionByAlias(@PathParam("alias") String id); + ListenableFuture get(@PathParam("alias") String id); } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/BaseListOptions.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/PaginationOptions.java similarity index 59% rename from apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/BaseListOptions.java rename to apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/PaginationOptions.java index f21f1d047d..6e68c61aee 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/BaseListOptions.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/options/PaginationOptions.java @@ -28,30 +28,26 @@ import org.jclouds.http.options.BaseHttpRequestOptions; /** * Options used to control paginated results (aka list commands). * - * @see + * @see * @author Adrian Cole */ -public class BaseListOptions extends BaseHttpRequestOptions { - public static final BaseListOptions NONE = new BaseListOptions(); - +public class PaginationOptions extends BaseHttpRequestOptions { /** * Only return objects changed since this time. */ - public BaseListOptions changesSince(Date ifModifiedSince) { - this.queryParameters.put("changes-since", checkNotNull(ifModifiedSince, "ifModifiedSince") - .getTime() - / 1000 + ""); + public PaginationOptions changesSince(Date ifModifiedSince) { + this.queryParameters.put("changes-since", checkNotNull(ifModifiedSince, "ifModifiedSince").getTime() / 1000 + ""); return this; } /** - * Indicates where to begin listing. The list will only include objects that occur after the - * offset. This is convenient for pagination: To get the next page of results use the last result - * number of the current page + current page offset as the offset. + * The marker parameter is the ID of the last item in the previous list. Items are sorted by + * create time in descending order. When a create time is not available they are sorted by ID. */ - public BaseListOptions startAt(long offset) { - checkState(offset >= 0, "offset must be >= 0"); - queryParameters.put("offset", Long.toString(checkNotNull(offset, "offset"))); + public PaginationOptions marker(String marker) { + queryParameters.put("marker", checkNotNull(marker, "marker")); return this; } @@ -63,7 +59,7 @@ public class BaseListOptions extends BaseHttpRequestOptions { *

* Note that list operations never return itemNotFound (404) faults. */ - public BaseListOptions maxResults(int limit) { + public PaginationOptions limit(int limit) { checkState(limit >= 0, "limit must be >= 0"); checkState(limit <= 10000, "limit must be <= 10000"); queryParameters.put("limit", Integer.toString(limit)); @@ -73,26 +69,26 @@ public class BaseListOptions extends BaseHttpRequestOptions { public static class Builder { /** - * @see BaseListOptions#startAt(long) + * @see PaginationOptions#marker(String) */ - public static BaseListOptions startAt(long prefix) { - BaseListOptions options = new BaseListOptions(); - return options.startAt(prefix); + public static PaginationOptions marker(String marker) { + PaginationOptions options = new PaginationOptions(); + return options.marker(marker); } /** - * @see BaseListOptions#maxResults + * @see PaginationOptions#limit */ - public static BaseListOptions maxResults(int maxKeys) { - BaseListOptions options = new BaseListOptions(); - return options.maxResults(maxKeys); + public static PaginationOptions limit(int limit) { + PaginationOptions options = new PaginationOptions(); + return options.limit(limit); } /** - * @see BaseListOptions#changesSince(Date) + * @see PaginationOptions#changesSince(Date) */ - public static BaseListOptions changesSince(Date since) { - BaseListOptions options = new BaseListOptions(); + public static PaginationOptions changesSince(Date since) { + PaginationOptions options = new PaginationOptions(); return options.changesSince(since); } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/LinkPredicates.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/LinkPredicates.java index dc5b12505f..85b8cf9877 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/LinkPredicates.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/LinkPredicates.java @@ -91,7 +91,7 @@ public class LinkPredicates { return new Predicate() { @Override public boolean apply(Link link) { - return type.equals(link.getType()); + return type.equals(link.getType().orNull()); } @Override diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiExpectTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiExpectTest.java index 094d657221..6d37a3de07 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiExpectTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiExpectTest.java @@ -31,6 +31,7 @@ import org.jclouds.http.HttpResponse; import org.jclouds.openstack.keystone.v2_0.KeystoneApi; import org.jclouds.openstack.keystone.v2_0.domain.Tenant; import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneRestApiExpectTest; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.AuthorizationException; import org.testng.annotations.Test; @@ -47,7 +48,10 @@ public class TenantApiExpectTest extends BaseKeystoneRestApiExpectTest expectedTenants = ImmutableSet.of(Tenant.builder().name("demo").id("05d1dc7af71646deba64cfc17b81bec0") + .build(), Tenant.builder().name("admin").id("7aa2e17ec29f44d193c48feaba0852cc").build()); + public void testListTenants() { TenantApi api = requestsSendResponses( keystoneAuthWithUsernameAndPassword, @@ -56,16 +60,28 @@ public class TenantApiExpectTest extends BaseKeystoneRestApiExpectTest tenants = api.list(); + + assertEquals(api.list().concat().toImmutableSet(), expectedTenants); + } + + public void testListTenantsPage() { + TenantApi api = requestsSendResponses( + keystoneAuthWithUsernameAndPassword, + responseWithKeystoneAccess, + authenticatedGET().endpoint(endpoint + "/v2.0/tenants").build(), + HttpResponse.builder().statusCode(200).payload( + payloadFromResourceWithContentType("/tenant_list.json", APPLICATION_JSON)).build()) + .getTenantApi().get(); + Set tenants = api.list(new PaginationOptions()).toImmutableSet(); assertNotNull(tenants); assertFalse(tenants.isEmpty()); - Set expected = ImmutableSet.of(Tenant.builder().name("demo").id("05d1dc7af71646deba64cfc17b81bec0") - .build(), Tenant.builder().name("admin").id("7aa2e17ec29f44d193c48feaba0852cc").build()); - - assertEquals(tenants, expected); + assertEquals(tenants, expectedTenants); } + // this is not a compatible format of json per: + // http://docs.openstack.org/api/openstack-identity-service/2.0/content/Paginated_Collections-d1e325.html + @Test(enabled = false) public void testListTenantsATT() { TenantApi api = requestsSendResponses( keystoneAuthWithUsernameAndPassword, @@ -74,15 +90,15 @@ public class TenantApiExpectTest extends BaseKeystoneRestApiExpectTest tenants = api.list(); - assertNotNull(tenants); - assertFalse(tenants.isEmpty()); Set expected = ImmutableSet.of(Tenant.builder().name("this-is-a-test").id("14").description("None").build()); - assertEquals(tenants, expected); + assertEquals(api.list().concat().toImmutableSet(), expected); } + // this is not a compatible format of json per: + // http://docs.openstack.org/api/openstack-identity-service/2.0/content/Paginated_Collections-d1e325.html + @Test(enabled = false) public void testListTenantsFailNotFound() { TenantApi api = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/v2.0/tenants").build(), HttpResponse.builder().statusCode(404).build()) diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiLiveTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiLiveTest.java index 8c09e41c95..e3a40336d7 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiLiveTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantApiLiveTest.java @@ -38,7 +38,7 @@ public class TenantApiLiveTest extends BaseKeystoneApiLiveTest { public void testTenants() { TenantApi api = keystoneContext.getApi().getTenantApi().get(); - Set result = api.list(); + Set result = api.list().concat().toImmutableSet(); assertNotNull(result); assertFalse(result.isEmpty()); @@ -56,7 +56,7 @@ public class TenantApiLiveTest extends BaseKeystoneApiLiveTest { TenantApi api = keystoneContext.getApi().getTenantApi().get(); - for (Tenant tenant : api.list()) { + for (Tenant tenant : api.list().concat()) { Tenant aTenant = api.getByName(tenant.getName()); assertNotNull(aTenant, "get returned null for tenant: " + tenant); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserApiExpectTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserApiExpectTest.java index 01eddeff07..104a96fb65 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserApiExpectTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserApiExpectTest.java @@ -30,9 +30,11 @@ import java.util.Set; import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponseException; import org.jclouds.openstack.keystone.v2_0.KeystoneApi; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.domain.Role; import org.jclouds.openstack.keystone.v2_0.domain.User; import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneRestApiExpectTest; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.AuthorizationException; import org.testng.annotations.Test; @@ -43,31 +45,50 @@ import com.google.common.collect.ImmutableSet; * * @author Adam Lowe */ -@Test(testName = "UserApiExpectTest") +@Test(singleThreaded = true, testName = "UserApiExpectTest") public class UserApiExpectTest extends BaseKeystoneRestApiExpectTest { public UserApiExpectTest(){ endpoint = "https://csnode.jclouds.org:35357"; } - + + Set expectedUsers = ImmutableSet.of( + User.builder().name("nova").id("e021dfd758eb44a89f1c57c8ef3be8e2").build(), + User.builder().name("glance").id("3f6c1c9ba993495ead7d2eb2192e284f").build(), + User.builder().name("demo").id("667b2e1420604df8b67cd8ea57d4ee64").build(), + User.builder().name("admin").id("2b9b606181634ae9ac86fd95a8bc2cde").build() + ); + public void testListUsers() { UserApi api = requestsSendResponses( keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/v2.0/users").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/user_list.json", APPLICATION_JSON)).build()) .getUserApi().get(); - Set users = api.list(); + + assertEquals(api.list().concat().toImmutableSet(), expectedUsers); + } + + public void testListUsersPage() { + UserApi api = requestsSendResponses( + keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, + authenticatedGET().endpoint(endpoint + "/v2.0/users").build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/user_list.json", APPLICATION_JSON)).build()) + .getUserApi().get(); + PaginatedCollection users = api.list(new PaginationOptions()); assertNotNull(users); assertFalse(users.isEmpty()); - Set expected = ImmutableSet.of( - User.builder().name("nova").id("e021dfd758eb44a89f1c57c8ef3be8e2").build(), - User.builder().name("glance").id("3f6c1c9ba993495ead7d2eb2192e284f").build(), - User.builder().name("demo").id("667b2e1420604df8b67cd8ea57d4ee64").build(), - User.builder().name("admin").id("2b9b606181634ae9ac86fd95a8bc2cde").build() - ); - assertEquals(users, expected); + assertEquals(users.toImmutableSet(), expectedUsers); + } + + public void testListUsersNotFound() { + UserApi api = requestsSendResponses( + keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, + authenticatedGET().endpoint(endpoint + "/v2.0/users").build(), + HttpResponse.builder().statusCode(404).build()).getUserApi().get(); + assertEquals( api.list(new PaginationOptions()).size(), 0); } @Test(expectedExceptions = AuthorizationException.class) @@ -76,7 +97,7 @@ public class UserApiExpectTest extends BaseKeystoneRestApiExpectTest users = api.list(); + Set users = api.list().concat().toImmutableSet(); assertNotNull(users); assertFalse(users.isEmpty()); for (User user : users) { @@ -54,10 +54,9 @@ public class UserApiLiveTest extends BaseKeystoneApiLiveTest { public void testUserRolesOnTenant() { UserApi api = keystoneContext.getApi().getUserApi().get(); - Set users = api.list(); - Set tenants = keystoneContext.getApi().getTenantApi().get().list(); + Set tenants = keystoneContext.getApi().getTenantApi().get().list().concat().toImmutableSet(); - for (User user : users) { + for (User user : api.list().concat()) { for (Tenant tenant : tenants) { Set roles = api.listRolesOfUserOnTenant(user.getId(), tenant.getId()); for (Role role : roles) { @@ -71,7 +70,7 @@ public class UserApiLiveTest extends BaseKeystoneApiLiveTest { public void testListRolesOfUser() { UserApi api = keystoneContext.getApi().getUserApi().get(); - for (User user : api.list()) { + for (User user : api.list().concat()) { Set roles = api.listRolesOfUser(user.getId()); for (Role role : roles) { assertNotNull(role.getId()); @@ -83,7 +82,7 @@ public class UserApiLiveTest extends BaseKeystoneApiLiveTest { public void testUsersByName() { UserApi api = keystoneContext.getApi().getUserApi().get(); - for (User user : api.list()) { + for (User user : api.list().concat()) { User aUser = api.getByName(user.getName()); assertEquals(aUser, user); } diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java index 9fa985b1ca..6e74370187 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java @@ -5,13 +5,10 @@ import static org.testng.Assert.assertEquals; import java.net.URI; import java.util.Set; -import javax.inject.Named; - import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.internal.ClassMethodArgsAndReturnVal; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.domain.Extension; -import org.jclouds.openstack.v2_0.functions.PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet; import org.jclouds.rest.annotations.Delegate; import org.testng.annotations.Test; diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/BaseListOptionsTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/PaginationOptionsTest.java similarity index 56% rename from apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/BaseListOptionsTest.java rename to apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/PaginationOptionsTest.java index 5387aec178..7e594bdfb4 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/BaseListOptionsTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/options/PaginationOptionsTest.java @@ -18,9 +18,9 @@ */ package org.jclouds.openstack.v2_0.options; -import static org.jclouds.openstack.v2_0.options.BaseListOptions.Builder.changesSince; -import static org.jclouds.openstack.v2_0.options.BaseListOptions.Builder.maxResults; -import static org.jclouds.openstack.v2_0.options.BaseListOptions.Builder.startAt; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.changesSince; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.limit; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; import static org.testng.Assert.assertEquals; import java.util.Date; @@ -34,44 +34,44 @@ import com.google.common.collect.ImmutableList; * * @author Adrian Cole */ -@Test(groups = "unit") -public class BaseListOptionsTest { +@Test(groups = "unit", testName = "PaginationOptionsTest") +public class PaginationOptionsTest { public void testChangesSince() { Date ifModifiedSince = new Date(); - BaseListOptions options = new BaseListOptions().changesSince(ifModifiedSince); - assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""), options - .buildQueryParameters().get("changes-since")); + PaginationOptions options = new PaginationOptions().changesSince(ifModifiedSince); + assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""), + options.buildQueryParameters().get("changes-since")); } - public void testStartAt() { - long offset = 1; - BaseListOptions options = new BaseListOptions().startAt(offset); - assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("offset")); + public void testMarker() { + String marker = "52415800-8b69-11e0-9b19-734f6f006e54"; + PaginationOptions options = new PaginationOptions().marker(marker); + assertEquals(ImmutableList.of(marker), options.buildQueryParameters().get("marker")); } public void testMaxResults() { int limit = 1; - BaseListOptions options = new BaseListOptions().maxResults(limit); + PaginationOptions options = new PaginationOptions().limit(limit); assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("limit")); } public void testChangesSinceStatic() { Date ifModifiedSince = new Date(); - BaseListOptions options = changesSince(ifModifiedSince); - assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""), options - .buildQueryParameters().get("changes-since")); + PaginationOptions options = changesSince(ifModifiedSince); + assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""), + options.buildQueryParameters().get("changes-since")); } - public void testStartAtStatic() { - long offset = 1; - BaseListOptions options = startAt(offset); - assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("offset")); + public void testMarkerStatic() { + String marker = "52415800-8b69-11e0-9b19-734f6f006e54"; + PaginationOptions options = marker(marker); + assertEquals(ImmutableList.of(marker), options.buildQueryParameters().get("marker")); } public void testMaxResultsStatic() { int limit = 1; - BaseListOptions options = maxResults(limit); + PaginationOptions options = limit(limit); assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("limit")); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java index 35eb3db0ca..6898540d44 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java @@ -25,7 +25,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.Zone; import org.jclouds.location.functions.ZoneToEndpoint; -import org.jclouds.openstack.nova.v2_0.extensions.AdminActionsApi; +import org.jclouds.openstack.nova.v2_0.extensions.ServerAdminApi; import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsApi; import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi; import org.jclouds.openstack.nova.v2_0.extensions.HostAdministrationApi; @@ -156,7 +156,7 @@ public interface NovaApi { * Provides synchronous access to Server Admin Actions features. */ @Delegate - Optional getAdminActionsExtensionForZone( + Optional getAdminActionsExtensionForZone( @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java index 3e71a78478..1f22a6ec01 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java @@ -23,7 +23,7 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.Zone; import org.jclouds.location.functions.ZoneToEndpoint; -import org.jclouds.openstack.nova.v2_0.extensions.AdminActionsAsyncApi; +import org.jclouds.openstack.nova.v2_0.extensions.ServerAdminAsyncApi; import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsAsyncApi; import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPAsyncApi; import org.jclouds.openstack.nova.v2_0.extensions.HostAdministrationAsyncApi; @@ -155,7 +155,7 @@ public interface NovaAsyncApi { * Provides asynchronous access to Server Admin Actions features. */ @Delegate - Optional getAdminActionsExtensionForZone( + Optional getAdminActionsExtensionForZone( @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java index 211404391e..d219d728f8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeService.java @@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED; +import static org.jclouds.openstack.nova.v2_0.predicates.KeyPairPredicates.nameMatches; import java.util.Map; import java.util.Set; @@ -65,7 +66,6 @@ import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone; import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName; import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi; import org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi; -import org.jclouds.openstack.nova.v2_0.predicates.KeyPairPredicates; import org.jclouds.openstack.nova.v2_0.predicates.SecurityGroupPredicates; import org.jclouds.scriptbuilder.functions.InitAdminAccess; @@ -138,11 +138,11 @@ public class NovaComputeService extends BaseComputeService { Optional securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId); if (securityGroupApi.isPresent()) { for (String group : groups) { - for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().listSecurityGroups(), + for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(), SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", zoneAndName); - securityGroupApi.get().deleteSecurityGroup(securityGroup.getId()); + securityGroupApi.get().delete(securityGroup.getId()); // TODO: test this clear happens securityGroupMap.invalidate(zoneAndName); logger.debug("<< deleted securityGroup(%s)", zoneAndName); @@ -155,16 +155,13 @@ public class NovaComputeService extends BaseComputeService { Optional keyPairApi = novaApi.getKeyPairExtensionForZone(zoneId); if (keyPairApi.isPresent()) { for (String group : groups) { - for (Map view : keyPairApi.get().listKeyPairs()) { - for (KeyPair pair : Iterables.filter(view.values(), - KeyPairPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { - ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, pair.getName()); - logger.debug(">> deleting keypair(%s)", zoneAndName); - keyPairApi.get().deleteKeyPair(pair.getName()); - // TODO: test this clear happens - keyPairCache.invalidate(zoneAndName); - logger.debug("<< deleted keypair(%s)", zoneAndName); - } + for (KeyPair pair : keyPairApi.get().list().filter(nameMatches(namingConvention.create().containsGroup(group)))) { + ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, pair.getName()); + logger.debug(">> deleting keypair(%s)", zoneAndName); + keyPairApi.get().delete(pair.getName()); + // TODO: test this clear happens + keyPairCache.invalidate(zoneAndName); + logger.debug("<< deleted keypair(%s)", zoneAndName); } keyPairCache.invalidate(ZoneAndName.fromZoneAndName(zoneId, namingConvention.create().sharedNameForGroup(group))); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java index f2b51380d5..67a94910b9 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java @@ -124,8 +124,8 @@ public class NovaComputeServiceAdapter implements String flavorId = template.getHardware().getProviderId(); logger.debug(">> creating new server zone(%s) name(%s) image(%s) flavor(%s) options(%s)", zoneId, name, imageId, flavorId, options); - ServerCreated lightweightServer = novaApi.getServerApiForZone(zoneId).createServer(name, imageId, flavorId, options); - Server server = novaApi.getServerApiForZone(zoneId).getServer(lightweightServer.getId()); + ServerCreated lightweightServer = novaApi.getServerApiForZone(zoneId).create(name, imageId, flavorId, options); + Server server = novaApi.getServerApiForZone(zoneId).get(lightweightServer.getId()); logger.trace("<< server(%s)", server.getId()); @@ -140,7 +140,7 @@ public class NovaComputeServiceAdapter implements public Iterable listHardwareProfiles() { Builder builder = ImmutableSet.builder(); for (final String zoneId : zoneIds.get()) { - builder.addAll(transform(novaApi.getFlavorApiForZone(zoneId).listFlavorsInDetail(), + builder.addAll(transform(novaApi.getFlavorApiForZone(zoneId).listInDetail().concat(), new Function() { @Override @@ -159,7 +159,7 @@ public class NovaComputeServiceAdapter implements Set zones = zoneIds.get(); checkState(zones.size() > 0, "no zones found in supplier %s", zoneIds); for (final String zoneId : zones) { - Set images = novaApi.getImageApiForZone(zoneId).listImagesInDetail(); + Set images = novaApi.getImageApiForZone(zoneId).listInDetail().concat().toImmutableSet(); if (images.size() == 0) { logger.debug("no images found in zone %s", zoneId); continue; @@ -194,8 +194,8 @@ public class NovaComputeServiceAdapter implements public Iterable listNodes() { Builder builder = ImmutableSet.builder(); for (final String zoneId : zoneIds.get()) { - builder.addAll(transform(novaApi.getServerApiForZone(zoneId).listServersInDetail(), - new Function() { + builder.addAll(novaApi.getServerApiForZone(zoneId).listInDetail().concat() + .transform(new Function() { @Override public ServerInZone apply(Server arg0) { @@ -216,14 +216,14 @@ public class NovaComputeServiceAdapter implements @Override public ServerInZone getNode(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); - Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).getServer(zoneAndId.getId()); + Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).get(zoneAndId.getId()); return server == null ? null : new ServerInZone(server, zoneAndId.getZone()); } @Override public ImageInZone getImage(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); - Image image = novaApi.getImageApiForZone(zoneAndId.getZone()).getImage(zoneAndId.getId()); + Image image = novaApi.getImageApiForZone(zoneAndId.getZone()).get(zoneAndId.getId()); return image == null ? null : new ImageInZone(image, zoneAndId.getZone()); } @@ -237,20 +237,20 @@ public class NovaComputeServiceAdapter implements logger.warn(e, "<< error removing and deallocating ip from node(%s): %s", id, e.getMessage()); } } - novaApi.getServerApiForZone(zoneAndId.getZone()).deleteServer(zoneAndId.getId()); + novaApi.getServerApiForZone(zoneAndId.getZone()).delete(zoneAndId.getId()); } @Override public void rebootNode(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); - novaApi.getServerApiForZone(zoneAndId.getZone()).rebootServer(zoneAndId.getId(), RebootType.HARD); + novaApi.getServerApiForZone(zoneAndId.getZone()).reboot(zoneAndId.getId(), RebootType.HARD); } @Override public void resumeNode(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) { - novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().resumeServer(zoneAndId.getId()); + novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId()); } throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension"); } @@ -259,7 +259,7 @@ public class NovaComputeServiceAdapter implements public void suspendNode(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) { - novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().suspendServer(zoneAndId.getId()); + novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId()); } throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension"); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/extensions/NovaImageExtension.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/extensions/NovaImageExtension.java index 4e71c979bc..7670d54925 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/extensions/NovaImageExtension.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/extensions/NovaImageExtension.java @@ -84,7 +84,7 @@ public class NovaImageExtension implements ImageExtension { @Override public ImageTemplate buildImageTemplateFromNode(String name, final String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); - Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).getServer(zoneAndId.getId()); + Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).get(zoneAndId.getId()); if (server == null) throw new NoSuchElementException("Cannot find server with id: " + zoneAndId); CloneImageTemplate template = new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build(); @@ -119,7 +119,7 @@ public class NovaImageExtension implements ImageExtension { public boolean deleteImage(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); try { - this.novaApi.getImageApiForZone(zoneAndId.getZone()).deleteImage(zoneAndId.getId()); + this.novaApi.getImageApiForZone(zoneAndId.getZone()).delete(zoneAndId.getId()); } catch (Exception e) { return false; } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java index 0e1193d05b..dc4b274a8d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java @@ -86,7 +86,7 @@ public class AllocateAndAddFloatingIpToNode implements } catch (InsufficientResourcesException e) { logger.trace("<< [%s] allocating a new floating ip for node(%s)", e.getMessage(), node.getId()); logger.trace(">> searching for existing, unassigned floating ip for node(%s)", node.getId()); - ArrayList unassignedIps = Lists.newArrayList(Iterables.filter(floatingIpApi.listFloatingIPs(), + ArrayList unassignedIps = Lists.newArrayList(Iterables.filter(floatingIpApi.list(), new Predicate() { @Override @@ -101,7 +101,7 @@ public class AllocateAndAddFloatingIpToNode implements } logger.debug(">> adding floatingIp(%s) to node(%s)", ip.getIp(), node.getId()); - floatingIpApi.addFloatingIPToServer(ip.getIp(), node.getProviderId()); + floatingIpApi.addToServer(ip.getIp(), node.getProviderId()); input.set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.getIp())).build()); floatingIpCache.invalidate(ZoneAndId.fromSlashEncoded(node.getId())); return input; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java index fb9aeb824f..015085105f 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CreateSecurityGroupIfNeeded.java @@ -67,17 +67,17 @@ public class CreateSecurityGroupIfNeeded implements Function> creating securityGroup %s", zoneSecurityGroupNameAndPorts); try { - SecurityGroup securityGroup = api.get().createSecurityGroupWithNameAndDescription( + SecurityGroup securityGroup = api.get().createWithDescription( zoneSecurityGroupNameAndPorts.getName(), zoneSecurityGroupNameAndPorts.getName()); logger.debug("<< created securityGroup(%s)", securityGroup); for (int port : zoneSecurityGroupNameAndPorts.getPorts()) { authorizeGroupToItselfAndAllIPsToTCPPort(api.get(), securityGroup, port); } - return new SecurityGroupInZone(api.get().getSecurityGroup(securityGroup.getId()), zoneId); + return new SecurityGroupInZone(api.get().get(securityGroup.getId()), zoneId); } catch (IllegalStateException e) { logger.trace("<< trying to find securityGroup(%s): %s", zoneSecurityGroupNameAndPorts, e.getMessage()); - SecurityGroup group = find(api.get().listSecurityGroups(), nameEquals(zoneSecurityGroupNameAndPorts + SecurityGroup group = find(api.get().list(), nameEquals(zoneSecurityGroupNameAndPorts .getName())); logger.debug("<< reused securityGroup(%s)", group.getId()); return new SecurityGroupInZone(group, zoneId); @@ -88,7 +88,7 @@ public class CreateSecurityGroupIfNeeded implements Function> authorizing securityGroup(%s) permission to 0.0.0.0/0 on port %d", securityGroup, port); - securityGroupApi.createSecurityGroupRuleAllowingCidrBlock(securityGroup.getId(), Ingress.builder().ipProtocol( + securityGroupApi.createRuleAllowingCidrBlock(securityGroup.getId(), Ingress.builder().ipProtocol( IpProtocol.TCP).fromPort(port).toPort(port).build(), "0.0.0.0/0"); logger.debug("<< authorized securityGroup(%s) permission to 0.0.0.0/0 on port %d", securityGroup, port); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java index 00f93cbc25..fb59e5c0eb 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java @@ -61,7 +61,7 @@ public class RemoveFloatingIpFromNodeAndDeallocate implements Function> removing floatingIp(%s) from node(%s)", ip, id); - floatingIpApi.removeFloatingIPFromServer(ip.getIp(), id.getId()); + floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); floatingIpApi.deallocate(ip.getId()); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java index 6454419fe9..7fa631a0f6 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPair.java @@ -68,7 +68,7 @@ public class CreateUniqueKeyPair extends CacheLoader { KeyPair keyPair = null; while (keyPair == null) { try { - keyPair = api.get().createKeyPair(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); + keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); } catch (IllegalStateException e) { } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java index d773bd5b11..0a8ebb8c80 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstance.java @@ -30,7 +30,6 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; /** * Each zone may or may not have the floating ip function present. In order to safely proceed, we @@ -53,7 +52,7 @@ public class LoadFloatingIpsForInstance extends CacheLoader ipApiOptional = api.getFloatingIPExtensionForZone(zone); if (ipApiOptional.isPresent()) { - return Iterables.filter(ipApiOptional.get().listFloatingIPs(), + return ipApiOptional.get().list().filter( new Predicate() { @Override public boolean apply(FloatingIP input) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java index 4de15d5408..32aa332546 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java @@ -162,7 +162,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { /** *

Note

* - * This requires that {@link NovaApi#getFloatingIPExtensionForZone(String)} to return + * This requires that {@link NovaApi#getExtensionForZone(String)} to return * {@link Optional#isPresent present} * * @return true if auto assignment of a floating ip to each vm is enabled diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResult.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResult.java index 5f2f38d1a7..254b405572 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResult.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResult.java @@ -35,7 +35,6 @@ import org.jclouds.predicates.PredicateWithResult; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; /** * @author David Alves @@ -89,7 +88,7 @@ public final class GetImageWhenImageInZoneHasActiveStatusPredicateWithResult imp } public org.jclouds.openstack.nova.v2_0.domain.Image findImage(final ZoneAndId zoneAndId) { - return Iterables.tryFind(api.getImageApiForZone(zoneAndId.getZone()).listImagesInDetail(), + return api.getImageApiForZone(zoneAndId.getZone()).listInDetail().concat().firstMatch( new Predicate() { @Override public boolean apply(org.jclouds.openstack.nova.v2_0.domain.Image input) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java index 0bef0894e7..597451daad 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java @@ -32,8 +32,8 @@ import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.NovaAsyncApi; -import org.jclouds.openstack.nova.v2_0.extensions.AdminActionsApi; -import org.jclouds.openstack.nova.v2_0.extensions.AdminActionsAsyncApi; +import org.jclouds.openstack.nova.v2_0.extensions.ServerAdminApi; +import org.jclouds.openstack.nova.v2_0.extensions.ServerAdminAsyncApi; import org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces; import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsApi; import org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsAsyncApi; @@ -106,7 +106,7 @@ public class NovaRestClientModule ext .put(VolumeApi.class, VolumeAsyncApi.class) .put(VirtualInterfaceApi.class, VirtualInterfaceAsyncApi.class) .put(ServerWithSecurityGroupsApi.class, ServerWithSecurityGroupsAsyncApi.class) - .put(AdminActionsApi.class, AdminActionsAsyncApi.class) + .put(ServerAdminApi.class, ServerAdminAsyncApi.class) .put(HostAggregateApi.class, HostAggregateAsyncApi.class) .put(FlavorExtraSpecsApi.class, FlavorExtraSpecsAsyncApi.class) .put(QuotaApi.class, QuotaAsyncApi.class) @@ -114,6 +114,7 @@ public class NovaRestClientModule ext .put(VolumeTypeApi.class, VolumeTypeAsyncApi.class) .build(); + @SuppressWarnings("unchecked") public NovaRestClientModule() { super(TypeToken.class.cast(TypeToken.of(NovaApi.class)), TypeToken.class.cast(TypeToken.of(NovaAsyncApi.class)), DELEGATE_MAP); } @@ -172,7 +173,7 @@ public class NovaRestClientModule ext .build(new CacheLoader>() { @Override public Set load(String key) throws Exception { - return novaApi.get().getExtensionApiForZone(key).listExtensions(); + return novaApi.get().getExtensionApiForZone(key).list(); } }); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java index 98137e4318..80e09bd822 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java @@ -36,7 +36,7 @@ import com.google.common.base.Optional; * * @author Jeremy Daggett * @see */ public class Flavor extends Resource { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java similarity index 90% rename from apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.java rename to apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java index 3b0d518008..6915511377 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java @@ -32,7 +32,7 @@ import com.google.common.base.Objects.ToStringHelper; * * @see org.jclouds.openstack.nova.v2_0.extensions.QuotaApi */ -public class Quotas { +public class Quota { public static Builder builder() { return new ConcreteBuilder(); @@ -60,7 +60,7 @@ public class Quotas { protected int keyPairs; /** - * @see Quotas#getId() + * @see Quota#getId() */ public T id(String id) { this.id = id; @@ -68,7 +68,7 @@ public class Quotas { } /** - * @see Quotas#getMetadataItems() + * @see Quota#getMetadataItems() */ public T metadataItems(int metadataItems) { this.metadataItems = metadataItems; @@ -76,7 +76,7 @@ public class Quotas { } /** - * @see Quotas#getInjectedFileContentBytes() + * @see Quota#getInjectedFileContentBytes() */ public T injectedFileContentBytes(int injectedFileContentBytes) { this.injectedFileContentBytes = injectedFileContentBytes; @@ -84,7 +84,7 @@ public class Quotas { } /** - * @see Quotas#getVolumes() + * @see Quota#getVolumes() */ public T volumes(int volumes) { this.volumes = volumes; @@ -92,7 +92,7 @@ public class Quotas { } /** - * @see Quotas#getGigabytes() + * @see Quota#getGigabytes() */ public T gigabytes(int gigabytes) { this.gigabytes = gigabytes; @@ -100,7 +100,7 @@ public class Quotas { } /** - * @see Quotas#getRam() + * @see Quota#getRam() */ public T ram(int ram) { this.ram = ram; @@ -108,7 +108,7 @@ public class Quotas { } /** - * @see Quotas#getFloatingIps() + * @see Quota#getFloatingIps() */ public T floatingIps(int floatingIps) { this.floatingIps = floatingIps; @@ -116,7 +116,7 @@ public class Quotas { } /** - * @see Quotas#getInstances() + * @see Quota#getInstances() */ public T instances(int instances) { this.instances = instances; @@ -124,7 +124,7 @@ public class Quotas { } /** - * @see Quotas#getInjectedFiles() + * @see Quota#getInjectedFiles() */ public T injectedFiles(int injectedFiles) { this.injectedFiles = injectedFiles; @@ -132,7 +132,7 @@ public class Quotas { } /** - * @see Quotas#getCores() + * @see Quota#getCores() */ public T cores(int cores) { this.cores = cores; @@ -140,7 +140,7 @@ public class Quotas { } /** - * @see Quotas#getSecurityGroups() + * @see Quota#getSecurityGroups() */ public T securityGroups(int securityGroups) { this.securityGroups = securityGroups; @@ -148,7 +148,7 @@ public class Quotas { } /** - * @see Quotas#getSecurityGroupRules() + * @see Quota#getSecurityGroupRules() */ public T securityGroupRules(int securityGroupRules) { this.securityGroupRules = securityGroupRules; @@ -156,18 +156,18 @@ public class Quotas { } /** - * @see Quotas#getKeyPairs() + * @see Quota#getKeyPairs() */ public T keyPairs(int keyPairs) { this.keyPairs = keyPairs; return self(); } - public Quotas build() { - return new Quotas(id, metadataItems, injectedFileContentBytes, volumes, gigabytes, ram, floatingIps, instances, injectedFiles, cores, securityGroups, securityGroupRules, keyPairs); + public Quota build() { + return new Quota(id, metadataItems, injectedFileContentBytes, volumes, gigabytes, ram, floatingIps, instances, injectedFiles, cores, securityGroups, securityGroupRules, keyPairs); } - public T fromQuotas(Quotas in) { + public T fromQuotas(Quota in) { return this .id(in.getId()) .metadataItems(in.getMetadataItems()) @@ -216,7 +216,7 @@ public class Quotas { @ConstructorProperties({ "id", "metadata_items", "injected_file_content_bytes", "volumes", "gigabytes", "ram", "floating_ips", "instances", "injected_files", "cores", "security_groups", "security_group_rules", "key_pairs" }) - protected Quotas(String id, int metadataItems, int injectedFileContentBytes, int volumes, int gigabytes, int ram, int floatingIps, int instances, int injectedFiles, int cores, int securityGroups, int securityGroupRules, int keyPairs) { + protected Quota(String id, int metadataItems, int injectedFileContentBytes, int volumes, int gigabytes, int ram, int floatingIps, int instances, int injectedFiles, int cores, int securityGroups, int securityGroupRules, int keyPairs) { this.id = checkNotNull(id, "id"); this.metadataItems = metadataItems; this.injectedFileContentBytes = injectedFileContentBytes; @@ -329,7 +329,7 @@ public class Quotas { public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; - Quotas that = Quotas.class.cast(obj); + Quota that = Quota.class.cast(obj); return Objects.equal(this.id, that.id) && Objects.equal(this.metadataItems, that.metadataItems) && Objects.equal(this.injectedFileContentBytes, that.injectedFileContentBytes) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java index 792805dbca..0c96b81a68 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java @@ -25,7 +25,7 @@ import java.beans.ConstructorProperties; * * @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClassApi */ -public class QuotaClass extends Quotas { +public class QuotaClass extends Quota { public static Builder builder() { return new ConcreteBuilder(); @@ -35,7 +35,7 @@ public class QuotaClass extends Quotas { return new ConcreteBuilder().fromQuotaClass(this); } - public static abstract class Builder> extends Quotas.Builder { + public static abstract class Builder> extends Quota.Builder { public QuotaClass build() { return new QuotaClass(id, metadataItems, injectedFileContentBytes, volumes, gigabytes, ram, floatingIps, instances, injectedFiles, cores, securityGroups, securityGroupRules, keyPairs); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApi.java index 5e8d19dced..1274c69ce4 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApi.java @@ -22,10 +22,10 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; -import org.jclouds.rest.annotations.RequestFilters; + +import com.google.common.annotations.Beta; /** * Provide access to extra metadata for Nova flavors. @@ -35,9 +35,9 @@ import org.jclouds.rest.annotations.RequestFilters; * @see org.jclouds.openstack.nova.v2_0.features.FlavorApi * @see org.jclouds.openstack.nova.v2_0.extensions.FlavorExtraSpecsAsyncApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLAVOR_EXTRA_SPECS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -@RequestFilters(AuthenticateRequest.class) public interface FlavorExtraSpecsApi { /** @@ -45,7 +45,7 @@ public interface FlavorExtraSpecsApi { * * @return the set of extra metadata for the flavor */ - Map getAllExtraSpecs(String flavorId); + Map getMetadata(String flavorId); /** * Creates or updates the extra specs for a given flavor @@ -53,7 +53,7 @@ public interface FlavorExtraSpecsApi { * @param flavorId the id of the flavor to modify * @param specs the extra specs to apply */ - Boolean setAllExtraSpecs(String flavorId, Map specs); + Boolean updateMetadata(String flavorId, Map specs); /** * Return a single extra spec value @@ -61,7 +61,7 @@ public interface FlavorExtraSpecsApi { * @param flavorId the id of the flavor to modify * @param key the extra spec key to retrieve */ - String getExtraSpec(String flavorId, String key); + String getMetadataKey(String flavorId, String key); /** * Creates or updates a single extra spec value @@ -70,7 +70,7 @@ public interface FlavorExtraSpecsApi { * @param key the extra spec key (when creating ensure this does not include whitespace or other difficult characters) * @param value the value to associate with the key */ - Boolean setExtraSpec(String flavorId, String key, String value); + Boolean updateMetadataEntry(String flavorId, String key, String value); /** * Deletes an extra spec @@ -78,6 +78,6 @@ public interface FlavorExtraSpecsApi { * @param flavorId the id of the flavor to modify * @param key the extra spec key to delete */ - Boolean deleteExtraSpec(String flavorId, String key); + Boolean deleteMetadataKey(String flavorId, String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsAsyncApi.java index e58ac22fc0..d93342b0d9 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsAsyncApi.java @@ -19,7 +19,6 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.Map; -import java.util.concurrent.TimeUnit; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -31,7 +30,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.jclouds.concurrent.Timeout; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; @@ -47,6 +45,7 @@ import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; import com.google.common.util.concurrent.ListenableFuture; /** @@ -57,59 +56,59 @@ import com.google.common.util.concurrent.ListenableFuture; * @see org.jclouds.openstack.nova.v2_0.features.FlavorApi * @see FlavorExtraSpecsApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLAVOR_EXTRA_SPECS) -@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @RequestFilters(AuthenticateRequest.class) @Consumes(MediaType.APPLICATION_JSON) public interface FlavorExtraSpecsAsyncApi { /** - * @see FlavorExtraSpecsApi#getAllExtraSpecs(String) + * @see FlavorExtraSpecsApi#getMetadata(String) */ @GET @SelectJson("extra_specs") @Path("/flavors/{flavor_id}/os-extra_specs") @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) - ListenableFuture> getAllExtraSpecs(@PathParam("flavor_id") String flavorId); + ListenableFuture> getMetadata(@PathParam("flavor_id") String flavorId); /** - * @see FlavorExtraSpecsApi#setExtraSpec(String, String, String) + * @see FlavorExtraSpecsApi#updateMetadataEntry(String, String, String) */ @POST @Path("/flavors/{flavor_id}/os-extra_specs") @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @MapBinder(BindToJsonPayload.class) - ListenableFuture setAllExtraSpecs(@PathParam("flavor_id") String flavorId, @PayloadParam("extra_specs") Map specs); + ListenableFuture updateMetadata(@PathParam("flavor_id") String flavorId, @PayloadParam("extra_specs") Map specs); /** - * @see FlavorExtraSpecsApi#getExtraSpec(String, String) + * @see FlavorExtraSpecsApi#getMetadataKey(String, String) */ @GET @Path("/flavors/{flavor_id}/os-extra_specs/{key}") @Unwrap @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getExtraSpec(@PathParam("flavor_id") String flavorId, @PathParam("key") String key); + ListenableFuture getMetadataKey(@PathParam("flavor_id") String flavorId, @PathParam("key") String key); /** - * @see FlavorExtraSpecsApi#setExtraSpec(String, String, String) + * @see FlavorExtraSpecsApi#updateMetadataEntry(String, String, String) */ @PUT @Path("/flavors/{flavor_id}/os-extra_specs/{key}") @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @Payload("%7B\"{key}\":\"{value}\"%7D") - ListenableFuture setExtraSpec(@PathParam("flavor_id") String flavorId, + ListenableFuture updateMetadataEntry(@PathParam("flavor_id") String flavorId, @PathParam("key") @PayloadParam("key") String key, @PayloadParam("value") String value); /** - * @see FlavorExtraSpecsApi#deleteExtraSpec(String, String) + * @see FlavorExtraSpecsApi#deleteMetadataKey(String, String) */ @DELETE @Path("/flavors/{flavor_id}/os-extra_specs/{key}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture deleteExtraSpec(@PathParam("flavor_id") String flavorId, + ListenableFuture deleteMetadataKey(@PathParam("flavor_id") String flavorId, @PathParam("key") String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java index 45ee544aad..e7b0b9db1b 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -26,6 +25,9 @@ import org.jclouds.openstack.nova.v2_0.domain.FloatingIP; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Floating IPs. *

@@ -33,6 +35,7 @@ import org.jclouds.openstack.v2_0.services.Extension; * @see FloatingIPAsyncApi * @author Jeremy Daggett */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLOATING_IPS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface FloatingIPApi { @@ -42,14 +45,14 @@ public interface FloatingIPApi { * * @return all Floating IPs */ - Set listFloatingIPs(); + FluentIterable list(); /** * Get a specific Floating IP address * * @return all Floating IPs */ - FloatingIP getFloatingIP(String id); + FloatingIP get(String id); /** * Allocate a Floating IP address @@ -76,7 +79,7 @@ public interface FloatingIPApi { * * NOTE: Possibly move this to ServerApi? */ - void addFloatingIPToServer(String address, String serverId); + void addToServer(String address, String serverId); /** * Remove a Floating IP address from a Server @@ -88,5 +91,5 @@ public interface FloatingIPApi { * * NOTE: Possibly move this to ServerApi? */ - void removeFloatingIPFromServer(String address, String serverId); + void removeFromServer(String address, String serverId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java index d0db242d20..0b30fcd442 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -40,9 +38,11 @@ import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -57,30 +57,31 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLOATING_IPS) @SkipEncoding( { '/', '=' }) @RequestFilters(AuthenticateRequest.class) public interface FloatingIPAsyncApi { /** - * @see FloatingIPApi#listFloatingIPs + * @see FloatingIPApi#list */ @GET @Path("/os-floating-ips") @SelectJson("floating_ips") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listFloatingIPs(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see FloatingIPApi#getFloatingIP + * @see FloatingIPApi#get */ @GET @Path("/os-floating-ips/{id}") @SelectJson("floating_ip") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getFloatingIP(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** * @see FloatingIPApi#allocate @@ -104,25 +105,25 @@ public interface FloatingIPAsyncApi { ListenableFuture deallocate(@PathParam("id") String id); /** - * @see FloatingIPApi#addFloatingIPToServer + * @see FloatingIPApi#addToServer */ @POST @Path("/servers/{server}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"addFloatingIp\":%7B\"address\":\"{address}\"%7D%7D") - ListenableFuture addFloatingIPToServer(@PayloadParam("address") String address, + ListenableFuture addToServer(@PayloadParam("address") String address, @PathParam("server") String serverId); /** - * @see FloatingIPApi#removeFloatingIPFromServer + * @see FloatingIPApi#removeFromServer */ @POST @Path("/servers/{server}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"removeFloatingIp\":%7B\"address\":\"{address}\"%7D%7D") - ListenableFuture removeFloatingIPFromServer(@PayloadParam("address") String address, + ListenableFuture removeFromServer(@PayloadParam("address") String address, @PathParam("server") String serverId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApi.java index 5b1666f7f2..1a9c594baf 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -27,6 +26,9 @@ import org.jclouds.openstack.nova.v2_0.domain.HostResourceUsage; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides asynchronous access to Host Administration features via the REST API. *

@@ -34,6 +36,7 @@ import org.jclouds.openstack.v2_0.services.Extension; * @author Adam Lowe * @see HostAdministrationAsyncApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.HOSTS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface HostAdministrationApi { @@ -43,28 +46,28 @@ public interface HostAdministrationApi { * * @return the usage information */ - Set listHosts(); + FluentIterable list(); /** * Retrieves the physical/usage resource on a specific host * * @return the usage information */ - Set getHostResourceUsage(String hostId); + FluentIterable listResourceUsage(String hostId); /** * Allow the specified host to accept new instances. * * @return true if successful */ - Boolean enableHost(String hostId); + boolean enable(String hostId); /** * Prevent the specified host from accepting new instances. * * @return true if successful */ - Boolean disableHost(String hostId); + boolean disable(String hostId); /** * Start host maintenance window. @@ -73,34 +76,34 @@ public interface HostAdministrationApi { * * @return true if successful */ - Boolean startHostMaintenance(String hostId); + boolean startMaintenance(String hostId); /** * Stop host maintenance window. * * @return true if successful */ - Boolean stopHostMaintenance(String hostId); + boolean stopMaintenance(String hostId); /** * Startup a host. * * @return true if successful */ - Boolean startupHost(String hostId); + boolean startup(String hostId); /** * Shutdown a host. * * @return true if successful */ - Boolean shutdownHost(String hostId); + boolean shutdown(String hostId); /** * Reboot a host. * * @return true if successful */ - Boolean rebootHost(String hostId); + boolean reboot(String hostId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationAsyncApi.java index 89ea47fa36..dcf9f9f6aa 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; @@ -46,8 +44,10 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -60,6 +60,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.HOSTS) @SkipEncoding({'/', '='}) @RequestFilters(AuthenticateRequest.class) @@ -68,83 +69,83 @@ import com.google.common.util.concurrent.ListenableFuture; public interface HostAdministrationAsyncApi { /** - * @see HostAdministrationApi#listHosts() + * @see HostAdministrationApi#list() */ @GET @SelectJson("hosts") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listHosts(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see HostAdministrationApi#getHostResourceUsage(String) + * @see HostAdministrationApi#listResourceUsage(String) */ @GET @Path("/{id}") @SelectJson("host") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> getHostResourceUsage(@PathParam("id") String hostId); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listResourceUsage(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#enableHost(String) + * @see HostAdministrationApi#enable(String) */ @PUT @Produces(MediaType.APPLICATION_JSON) @Path("/{id}") @Payload("{\"status\":\"enable\"}") @ResponseParser(StatusEnabledResponseParser.class) - ListenableFuture enableHost(@PathParam("id") String hostId); + ListenableFuture enable(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#disableHost(String) + * @see HostAdministrationApi#disable(String) */ @PUT @Produces(MediaType.APPLICATION_JSON) @Path("/{id}") @Payload("{\"status\":\"disable\"}") @ResponseParser(StatusDisabledResponseParser.class) - ListenableFuture disableHost(@PathParam("id") String hostId); + ListenableFuture disable(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#startHostMaintenance(String) + * @see HostAdministrationApi#startMaintenance(String) */ @PUT @Produces(MediaType.APPLICATION_JSON) @Path("/{id}") @Payload("{\"maintenance_mode\":\"enable\"}") @ResponseParser(MaintenanceModeEnabledResponseParser.class) - ListenableFuture startHostMaintenance(@PathParam("id") String hostId); + ListenableFuture startMaintenance(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#stopHostMaintenance(String) + * @see HostAdministrationApi#stopMaintenance(String) */ @PUT @Produces(MediaType.APPLICATION_JSON) @Path("/{id}") @Payload("{\"maintenance_mode\":\"disable\"}") @ResponseParser(MaintenanceModeDisabledResponseParser.class) - ListenableFuture stopHostMaintenance(@PathParam("id") String hostId); + ListenableFuture stopMaintenance(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#startupHost(String) + * @see HostAdministrationApi#startup(String) */ @GET @Path("/{id}/startup") @ResponseParser(PowerIsStartupResponseParser.class) - ListenableFuture startupHost(@PathParam("id") String hostId); + ListenableFuture startup(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#shutdownHost(String) + * @see HostAdministrationApi#shutdown(String) */ @GET @Path("/{id}/shutdown") @ResponseParser(PowerIsShutdownResponseParser.class) - ListenableFuture shutdownHost(@PathParam("id") String hostId); + ListenableFuture shutdown(@PathParam("id") String hostId); /** - * @see HostAdministrationApi#rebootHost(String) + * @see HostAdministrationApi#reboot(String) */ @GET @Path("/{id}/reboot") @ResponseParser(PowerIsRebootResponseParser.class) - ListenableFuture rebootHost(@PathParam("id") String hostId); + ListenableFuture reboot(@PathParam("id") String hostId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApi.java index 61bc112032..0d8ecd06f1 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApi.java @@ -19,15 +19,15 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.nova.v2_0.domain.HostAggregate; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; -import org.jclouds.rest.annotations.RequestFilters; + +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; /** * Provide access to Host Aggregates in Nova (alias "OS-AGGREGATES") @@ -37,29 +37,29 @@ import org.jclouds.rest.annotations.RequestFilters; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.AGGREGATES) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -@RequestFilters(AuthenticateRequest.class) public interface HostAggregateApi { /** * @return the set of host aggregates. */ - Set listAggregates(); + FluentIterable list(); /** * Retrieves the details of an aggregate, hosts and metadata included. * * @return the details of the aggregate requested. */ - HostAggregate getAggregate(String id); + HostAggregate get(String id); /** * Creates an aggregate, given its name and availability zone. * * @return the newly created Aggregate */ - HostAggregate createAggregate(String name, String availabilityZone); + HostAggregate createInAvailabilityZone(String name, String availabilityZone); /** * Updates the name of an aggregate. @@ -74,7 +74,7 @@ public interface HostAggregateApi { /** * Removes an aggregate. */ - Boolean deleteAggregate(String id); + Boolean delete(String id); /** * Adds a host to an aggregate diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateAsyncApi.java index a964b48e2a..54bd93f8fb 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateAsyncApi.java @@ -19,8 +19,6 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -31,7 +29,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.jclouds.concurrent.Timeout; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.nova.v2_0.domain.HostAggregate; import org.jclouds.openstack.v2_0.ServiceType; @@ -41,10 +38,12 @@ import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.WrapWith; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -53,40 +52,40 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adam Lowe * @see HostAggregateApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.AGGREGATES) -@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @RequestFilters(AuthenticateRequest.class) @Path("/os-aggregates") public interface HostAggregateAsyncApi { /** - * @see HostAggregateApi#listAggregates() + * @see HostAggregateApi#list() */ @GET @SelectJson("aggregates") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listAggregates(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see HostAggregateApi#getAggregate(String) + * @see HostAggregateApi#get(String) */ @GET @Path("/{id}") @SelectJson("aggregate") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getAggregate(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** - * @see HostAggregateApi#createAggregate(String, String) + * @see HostAggregateApi#createInAvailabilityZone(String, String) */ @POST @SelectJson("aggregate") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @WrapWith("aggregate") - ListenableFuture createAggregate(@PayloadParam("name") String name, + ListenableFuture createInAvailabilityZone(@PayloadParam("name") String name, @PayloadParam("availability_zone") String availabilityZone); /** @@ -110,13 +109,13 @@ public interface HostAggregateAsyncApi { ListenableFuture updateAvailabilityZone(@PathParam("id") String id, @PayloadParam("availability_zone") String availabilityZone); /** - * @see HostAggregateApi#deleteAggregate(String) + * @see HostAggregateApi#delete(String) */ @DELETE @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture deleteAggregate(@PathParam("id") String id); + ListenableFuture delete(@PathParam("id") String id); /** * @see HostAggregateApi#addHost(String,String) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApi.java index 1d5ae3c049..a2769399c4 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -27,6 +25,9 @@ import org.jclouds.openstack.nova.v2_0.domain.KeyPair; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Security Groups. *

@@ -34,6 +35,7 @@ import org.jclouds.openstack.v2_0.services.Extension; * @see KeyPairAsyncApi * @author Jeremy Daggett */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.KEYPAIRS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface KeyPairApi { @@ -43,27 +45,27 @@ public interface KeyPairApi { * * @return all Key Pairs */ - Set> listKeyPairs(); + FluentIterable list(); /** * Create a Key Pair. * * @return a Key Pair */ - KeyPair createKeyPair(String name); + KeyPair create(String name); /** * Create a Key Pair with a public key. * * @return a Key Pair with a public key. */ - KeyPair createKeyPairWithPublicKey(String name, String publicKey); + KeyPair createWithPublicKey(String name, String publicKey); /** * Delete a Key Pairs. * * @return */ - Boolean deleteKeyPair(String name); + boolean delete(String name); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairAsyncApi.java index 3fb1056d38..c5b0f69fda 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairAsyncApi.java @@ -18,9 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Map; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -32,6 +29,7 @@ import javax.ws.rs.core.MediaType; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.nova.v2_0.domain.KeyPair; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseKeyPairs; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.features.ExtensionAsyncApi; import org.jclouds.openstack.v2_0.services.Extension; @@ -39,11 +37,14 @@ import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -59,6 +60,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.KEYPAIRS) @SkipEncoding({ '/', '=' }) @RequestFilters(AuthenticateRequest.class) @@ -66,10 +68,10 @@ public interface KeyPairAsyncApi { @GET @Path("/os-keypairs") - @SelectJson("keypairs") + @ResponseParser(ParseKeyPairs.class) @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture>> listKeyPairs(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); @POST @Path("/os-keypairs") @@ -77,7 +79,7 @@ public interface KeyPairAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"keypair\":%7B\"name\":\"{name}\"%7D%7D") - ListenableFuture createKeyPair(@PayloadParam("name") String name); + ListenableFuture create(@PayloadParam("name") String name); @POST @Path("/os-keypairs") @@ -85,13 +87,13 @@ public interface KeyPairAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"keypair\":%7B\"name\":\"{name}\",\"public_key\":\"{publicKey}\"%7D%7D") - ListenableFuture createKeyPairWithPublicKey(@PayloadParam("name") String name, + ListenableFuture createWithPublicKey(@PayloadParam("name") String name, @PayloadParam("publicKey") String publicKey); @DELETE @Path("/os-keypairs/{name}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @Consumes - ListenableFuture deleteKeyPair(@PathParam("name") String name); + ListenableFuture delete(@PathParam("name") String name); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApi.java index 9a38d1f914..af313b9e90 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApi.java @@ -21,11 +21,11 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.nova.v2_0.domain.Quotas; +import org.jclouds.openstack.nova.v2_0.domain.Quota; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; -import org.jclouds.rest.annotations.RequestFilters; + +import com.google.common.annotations.Beta; /** * The quotas extension enables limiters placed on the resources used per tenant (project) for virtual instances. It is @@ -38,26 +38,26 @@ import org.jclouds.rest.annotations.RequestFilters; * @see QuotaAsyncApi * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.QUOTAS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -@RequestFilters(AuthenticateRequest.class) public interface QuotaApi { /** * @return the quota settings for the tenant */ - Quotas getQuotasForTenant(String tenantId); + Quota getByTenant(String tenantId); /** * Update the quotas for a given tenant * * @return true if successful */ - Boolean updateQuotasForTenant(String tenantId, Quotas quotas); + boolean updateQuotaOfTenant(Quota quota, String tenantId); /** * @return the set of default quotas for the tenant */ - Quotas getDefaultQuotasForTenant(String tenantId); + Quota getDefaultsForTenant(String tenantId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaAsyncApi.java index b0f6dc7da7..16269867aa 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.concurrent.TimeUnit; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; @@ -28,9 +26,8 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.jclouds.concurrent.Timeout; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.nova.v2_0.domain.Quotas; +import org.jclouds.openstack.nova.v2_0.domain.Quota; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; import org.jclouds.rest.annotations.ExceptionParser; @@ -41,48 +38,50 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; import com.google.common.util.concurrent.ListenableFuture; /** * Provide access to Quota information for Nova tenants. - * + * * @author Adam Lowe * @see QuotaApi * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.QUOTAS) -@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @RequestFilters(AuthenticateRequest.class) @Path("/os-quota-sets") public interface QuotaAsyncApi { /** - * @see QuotaApi#getDefaultQuotasForTenant(String) + * @see QuotaApi#getDefaultsForTenant(String) */ @GET @SelectJson("quota_set") @Consumes(MediaType.APPLICATION_JSON) @Path("/{tenant_id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getQuotasForTenant(@PathParam("tenant_id") String tenantId); + ListenableFuture getByTenant(@PathParam("tenant_id") String tenantId); /** - * @see QuotaApi#updateQuotasForTenant(String, org.jclouds.openstack.nova.v2_0.domain.Quotas) + * @see QuotaApi#updateQuotaOfTenant */ @PUT @Path("/{tenant_id}") @Produces(MediaType.APPLICATION_JSON) @MapBinder(BindToJsonPayload.class) - ListenableFuture updateQuotasForTenant(@PathParam("tenant_id") String tenantId, @PayloadParam("quota_set") Quotas quotas); + ListenableFuture updateQuotaOfTenant(@PayloadParam("quota_set") Quota quota, + @PathParam("tenant_id") String tenantId); /** - * @see QuotaApi#getDefaultQuotasForTenant(String) + * @see QuotaApi#getDefaultsForTenant(String) */ @GET @SelectJson("quota_set") @Consumes(MediaType.APPLICATION_JSON) @Path("/{tenant_id}/defaults") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getDefaultQuotasForTenant(@PathParam("tenant_id") String tenantId); + ListenableFuture getDefaultsForTenant(@PathParam("tenant_id") String tenantId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApi.java index 86922ce492..aed2b37986 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApi.java @@ -21,11 +21,11 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.nova.v2_0.domain.QuotaClass; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; -import org.jclouds.rest.annotations.RequestFilters; + +import com.google.common.annotations.Beta; /** * Provides synchronous access to Quota Classes via the REST API. @@ -37,21 +37,21 @@ import org.jclouds.rest.annotations.RequestFilters; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.QUOTA_CLASSES) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -@RequestFilters(AuthenticateRequest.class) public interface QuotaClassApi { /** * @return the quota settings for the tenant */ - QuotaClass getQuotaClass(String id); + QuotaClass get(String id); /** * Update the quotas for a given tenant * * @return true if successful */ - Boolean updateQuotaClass(String id, QuotaClass quotas); + boolean update(String id, QuotaClass quotas); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassAsyncApi.java index 41cfe91881..b614bea5cc 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.concurrent.TimeUnit; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; @@ -28,7 +26,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.jclouds.concurrent.Timeout; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.nova.v2_0.domain.QuotaClass; import org.jclouds.openstack.v2_0.ServiceType; @@ -41,6 +38,7 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; import com.google.common.util.concurrent.ListenableFuture; /** @@ -51,29 +49,29 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.QUOTA_CLASSES) -@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @RequestFilters(AuthenticateRequest.class) @Path("/os-quota-class-sets") public interface QuotaClassAsyncApi { /** - * @see QuotaClassApi#getQuotaClass + * @see QuotaClassApi#get */ @GET @SelectJson("quota_class_set") @Consumes(MediaType.APPLICATION_JSON) @Path("/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getQuotaClass(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** - * @see QuotaClassApi#updateQuotaClass + * @see QuotaClassApi#update */ @PUT @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) @MapBinder(BindToJsonPayload.class) - ListenableFuture updateQuotaClass(@PathParam("id") String id, @PayloadParam("quota_class_set") QuotaClass quotas); + ListenableFuture update(@PathParam("id") String id, @PayloadParam("quota_class_set") QuotaClass quotas); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApi.java index 8042ad2868..f3811319f0 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -28,6 +27,9 @@ import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Security Groups. *

@@ -35,6 +37,7 @@ import org.jclouds.openstack.v2_0.services.Extension; * @see SecurityGroupAsyncApi * @author Jeremy Daggett */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SECURITY_GROUPS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface SecurityGroupApi { @@ -42,44 +45,44 @@ public interface SecurityGroupApi { /** * List all Security Groups. * - * @return all Floating IPs + * @return all Security Groups */ - Set listSecurityGroups(); + FluentIterable list(); /** * Get a specific Security Group * * @return a specific Security Group */ - SecurityGroup getSecurityGroup(String id); + SecurityGroup get(String id); /** * Create a Security Group * * @return a new Security Group */ - SecurityGroup createSecurityGroupWithNameAndDescription(String name, String description); + SecurityGroup createWithDescription(String name, String description); /** * Delete a Security Group. * * @return */ - Boolean deleteSecurityGroup(String id); + boolean delete(String id); /** * Create a Security Group Rule. * * @return a new Security Group Rule */ - SecurityGroupRule createSecurityGroupRuleAllowingCidrBlock(String parentGroup, Ingress ingress, String sourceCidr); + SecurityGroupRule createRuleAllowingCidrBlock(String parentGroup, Ingress ingress, String sourceCidr); /** * Create a Security Group Rule. * * @return a new Security Group Rule */ - SecurityGroupRule createSecurityGroupRuleAllowingSecurityGroupId(String parentGroup, Ingress ingress, + SecurityGroupRule createRuleAllowingSecurityGroupId(String parentGroup, Ingress ingress, String sourceCidr); /** @@ -87,6 +90,6 @@ public interface SecurityGroupApi { * * @return */ - Boolean deleteSecurityGroupRule(String id); + Boolean deleteRule(String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupAsyncApi.java index 438c85eeb3..0303ff8270 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -43,10 +41,12 @@ import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -60,33 +60,34 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SECURITY_GROUPS) @SkipEncoding( { '/', '=' }) @RequestFilters(AuthenticateRequest.class) public interface SecurityGroupAsyncApi { /** - * @see SecurityGroupApi#listSecurityGroups + * @see SecurityGroupApi#list */ @GET @SelectJson("security_groups") @Consumes(MediaType.APPLICATION_JSON) @Path("/os-security-groups") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listSecurityGroups(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see SecurityGroupApi#getSecurityGroup + * @see SecurityGroupApi#get */ @GET @Path("/os-security-groups/{id}") @SelectJson("security_group") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getSecurityGroup(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** - * @see SecurityGroupApi#createSecurityGroupWithNameAndDescription + * @see SecurityGroupApi#createWithDescription */ @POST @Path("/os-security-groups") @@ -95,20 +96,20 @@ public interface SecurityGroupAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"security_group\":%7B\"name\":\"{name}\",\"description\":\"{description}\"%7D%7D") - ListenableFuture createSecurityGroupWithNameAndDescription(@PayloadParam("name") String name, + ListenableFuture createWithDescription(@PayloadParam("name") String name, @PayloadParam("description") String description); /** - * @see SecurityGroupApi#deleteSecurityGroup + * @see SecurityGroupApi#delete */ @DELETE @Path("/os-security-groups/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture deleteSecurityGroup(@PathParam("id") String id); + ListenableFuture delete(@PathParam("id") String id); /** - * @see SecurityGroupApi#createSecurityGroupRuleAllowingCidrBlock + * @see SecurityGroupApi#createRuleAllowingCidrBlock */ @POST @Path("/os-security-group-rules") @@ -117,7 +118,7 @@ public interface SecurityGroupAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @MapBinder(BindSecurityGroupRuleToJsonPayload.class) - ListenableFuture createSecurityGroupRuleAllowingCidrBlock( + ListenableFuture createRuleAllowingCidrBlock( @PayloadParam("parent_group_id") String parent_group_id, Ingress ip_protocol, @PayloadParam("cidr") String cidr); @@ -131,17 +132,17 @@ public interface SecurityGroupAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @MapBinder(BindSecurityGroupRuleToJsonPayload.class) - ListenableFuture createSecurityGroupRuleAllowingSecurityGroupId( + ListenableFuture createRuleAllowingSecurityGroupId( @PayloadParam("parent_group_id") String parent_group_id, Ingress ip_protocol, @PayloadParam("group_id") String group_id); /** - * @see SecurityGroupApi#deleteSecurityGroupRule + * @see SecurityGroupApi#deleteRule */ @DELETE @Path("/os-security-group-rules/{security_group_rule_ID}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @Consumes - ListenableFuture deleteSecurityGroupRule(@PathParam("security_group_rule_ID") String security_group_rule_ID); + ListenableFuture deleteRule(@PathParam("security_group_rule_ID") String security_group_rule_ID); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerAdminApi.java similarity index 79% rename from apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApi.java rename to apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerAdminApi.java index aa2e92a7b7..351bb783f8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerAdminApi.java @@ -26,59 +26,62 @@ import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; + /** * Provide additional actions for servers: * 'suspend', 'resume', 'migrate', 'lock', 'unlock', 'resetNetwork', 'createBackup', 'pause', 'migrateLive', * 'injectNetworkInfo', 'unpause' * * @author Adam Lowe - * @see org.jclouds.openstack.nova.v2_0.extensions.AdminActionsAsyncApi + * @see org.jclouds.openstack.nova.v2_0.extensions.ServerAdminAsyncApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.ADMIN_ACTIONS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -public interface AdminActionsApi { +public interface ServerAdminApi { /** * Suspend a server. * * @param id id of the server */ - Boolean suspendServer(String id); + Boolean suspend(String id); /** * Resume a server. * * @param id id of the server */ - Boolean resumeServer(String id); + Boolean resume(String id); /** * Migrate a server. * * @param id id of the server */ - Boolean migrateServer(String id); + Boolean migrate(String id); /** * Lock a server. * * @param id id of the server */ - Boolean lockServer(String id); + Boolean lock(String id); /** * Unlock a server. * * @param id id of the server */ - Boolean unlockServer(String id); + Boolean unlock(String id); /** * Reset network of a server. * * @param id id of the server */ - Boolean resetNetworkOfServer(String id); + Boolean resetNetwork(String id); /** * Create backup of a server. @@ -90,21 +93,21 @@ public interface AdminActionsApi { * @param options optional rotation and/or metadata parameters * @return the id of the newly created image */ - String createBackupOfServer(String id, String imageName, BackupType backupType, int rotation, CreateBackupOfServerOptions... options); + String createBackup(String id, String imageName, BackupType backupType, int rotation, CreateBackupOfServerOptions... options); /** * Pause a server. * * @param id id of the server */ - Boolean pauseServer(String id); + Boolean pause(String id); /** * Unpause a server. * * @param id id of the server */ - Boolean unpauseServer(String id); + Boolean unpause(String id); /** @@ -112,12 +115,12 @@ public interface AdminActionsApi { * * @param id id of the server */ - Boolean liveMigrateServer(String id, String host, boolean blockMigration, boolean diskOverCommit); + Boolean liveMigrate(String id, String host, boolean blockMigration, boolean diskOverCommit); /** * Inject network info into a server. * * @param id id of the server */ - Boolean injectNetworkInfoIntoServer(String id); + Boolean injectNetworkInfo(String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerAdminAsyncApi.java similarity index 76% rename from apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsAsyncApi.java rename to apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerAdminAsyncApi.java index a219e214d0..f6ce679b30 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerAdminAsyncApi.java @@ -41,76 +41,78 @@ import org.jclouds.rest.annotations.WrapWith; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; +import com.google.common.annotations.Beta; import com.google.common.util.concurrent.ListenableFuture; /** * Provide access to Admin Server Actions via REST API * * @author Adam Lowe - * @see org.jclouds.openstack.nova.v2_0.extensions.AdminActionsApi + * @see org.jclouds.openstack.nova.v2_0.extensions.ServerAdminApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.ADMIN_ACTIONS) @SkipEncoding( { '/', '=' }) @RequestFilters(AuthenticateRequest.class) @Path("/servers/{id}/action") -public interface AdminActionsAsyncApi { +public interface ServerAdminAsyncApi { /** - * @see AdminActionsApi#suspendServer(String) + * @see ServerAdminApi#suspend(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"suspend\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture suspendServer(@PathParam("id") String id); + ListenableFuture suspend(@PathParam("id") String id); /** - * @see AdminActionsApi#resumeServer(String) + * @see ServerAdminApi#resume(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"resume\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture resumeServer(@PathParam("id") String id); + ListenableFuture resume(@PathParam("id") String id); /** - * @see AdminActionsApi#migrateServer(String) + * @see ServerAdminApi#migrate(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"migrate\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture migrateServer(@PathParam("id") String id); + ListenableFuture migrate(@PathParam("id") String id); /** - * @see AdminActionsApi#suspendServer(String) + * @see ServerAdminApi#lock(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"lock\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture lockServer(@PathParam("id") String id); + ListenableFuture lock(@PathParam("id") String id); /** - * @see AdminActionsApi#unlockServer(String) + * @see ServerAdminApi#unlock(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"unlock\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture unlockServer(@PathParam("id") String id); + ListenableFuture unlock(@PathParam("id") String id); /** - * @see AdminActionsApi#resetNetworkOfServer(String) + * @see ServerAdminApi#resetNetwork(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"resetNetwork\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture resetNetworkOfServer(@PathParam("id") String id); + ListenableFuture resetNetwork(@PathParam("id") String id); /** - * @see AdminActionsApi#createBackupOfServer + * @see ServerAdminApi#createBackup */ @POST @Consumes(MediaType.APPLICATION_JSON) @@ -118,47 +120,47 @@ public interface AdminActionsAsyncApi { @WrapWith("createBackup") @ExceptionParser(MapHttp4xxCodesToExceptions.class) @ResponseParser(ParseImageIdFromLocationHeader.class) - ListenableFuture createBackupOfServer(@PathParam("id") String id, + ListenableFuture createBackup(@PathParam("id") String id, @PayloadParam("name") String imageName, @PayloadParam("backup_type") BackupType backupType, @PayloadParam("rotation") int rotation, CreateBackupOfServerOptions... options); /** - * @see AdminActionsApi#pauseServer(String) + * @see ServerAdminApi#pause(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"pause\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture pauseServer(@PathParam("id") String id); + ListenableFuture pause(@PathParam("id") String id); /** - * @see AdminActionsApi#unpauseServer(String) + * @see ServerAdminApi#unpause(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"unpause\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture unpauseServer(@PathParam("id") String id); + ListenableFuture unpause(@PathParam("id") String id); /** - * @see AdminActionsApi#suspendServer(String) + * @see ServerAdminApi#injectNetworkInfo(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @Payload("{\"injectNetworkInfo\":null}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture injectNetworkInfoIntoServer(@PathParam("id") String id); + ListenableFuture injectNetworkInfo(@PathParam("id") String id); /** - * @see AdminActionsApi#migrateServer(String) + * @see ServerAdminApi#liveMigrate(String) */ @POST @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @WrapWith("os-migrateLive") - ListenableFuture liveMigrateServer(@PathParam("id") String id, + ListenableFuture liveMigrate(@PathParam("id") String id, @PayloadParam("host") String host, @PayloadParam("block_migration") boolean blockMigration, @PayloadParam("disk_over_commit") boolean diskOverCommit); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApi.java index 6910cb263b..c14138c658 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApi.java @@ -25,6 +25,8 @@ import org.jclouds.openstack.nova.v2_0.domain.ServerWithSecurityGroups; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; + /** * Provides synchronous access to Server details including security group, referred to as the CREATESERVEREXT extension * in the nova documentation @@ -37,6 +39,7 @@ import org.jclouds.openstack.v2_0.services.Extension; * @see ServerWithSecurityGroupsAsyncApi * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.CREATESERVEREXT) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface ServerWithSecurityGroupsApi { @@ -47,6 +50,6 @@ public interface ServerWithSecurityGroupsApi { * @param id id of the server * @return server or null if not found */ - ServerWithSecurityGroups getServer(String id); + ServerWithSecurityGroups get(String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsAsyncApi.java index 30b8375f8f..9585b309ed 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsAsyncApi.java @@ -34,6 +34,7 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; import com.google.common.util.concurrent.ListenableFuture; /** @@ -44,19 +45,20 @@ import com.google.common.util.concurrent.ListenableFuture; * @see ServerWithSecurityGroupsApi * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.CREATESERVEREXT) @SkipEncoding({'/', '='}) @RequestFilters(AuthenticateRequest.class) public interface ServerWithSecurityGroupsAsyncApi { /** - * @see ServerWithSecurityGroupsApi#getServer(String) + * @see ServerWithSecurityGroupsApi#get(String) */ @GET @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) @Path("/os-create-server-ext/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getServer(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApi.java index d17eb19e03..a28c4ec727 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -26,6 +25,9 @@ import org.jclouds.openstack.nova.v2_0.domain.SimpleTenantUsage; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides asynchronous access to Simple Tenant Usage via the REST API. *

@@ -33,6 +35,7 @@ import org.jclouds.openstack.v2_0.services.Extension; * @author Adam Lowe * @see SimpleTenantUsageAsyncApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SIMPLE_TENANT_USAGE) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface SimpleTenantUsageApi { @@ -42,12 +45,12 @@ public interface SimpleTenantUsageApi { * * @return the set of TenantUsage reports */ - Set listTenantUsages(); + FluentIterable list(); /** * Retrieve tenant_usage for a specified tenant * * @return the requested tenant usage */ - SimpleTenantUsage getTenantUsage(String tenantId); + SimpleTenantUsage get(String tenantId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageAsyncApi.java index 729f50e99e..ea14d37d7b 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -34,9 +32,11 @@ import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -49,29 +49,30 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SIMPLE_TENANT_USAGE) @SkipEncoding({'/', '='}) @RequestFilters(AuthenticateRequest.class) public interface SimpleTenantUsageAsyncApi { /** - * @see SimpleTenantUsageApi#listTenantUsages() + * @see SimpleTenantUsageApi#list() */ @GET @Path("/os-simple-tenant-usage") @SelectJson("tenant_usages") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listTenantUsages(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see SimpleTenantUsageApi#getTenantUsage(String) + * @see SimpleTenantUsageApi#get(String) */ @GET @Path("/os-simple-tenant-usage/{id}") @SelectJson("tenant_usage") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getTenantUsage(@PathParam("id") String tenantId); + ListenableFuture get(@PathParam("id") String tenantId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApi.java index 257dea3e3c..b3c1027cc2 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -26,12 +25,16 @@ import org.jclouds.openstack.nova.v2_0.domain.VirtualInterface; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Virtual Interface features (VIFs). * * @see VirtualInterfaceAsyncApi * @author Adam Lowe */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VIRTUAL_INTERFACES) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface VirtualInterfaceApi { @@ -41,6 +44,6 @@ public interface VirtualInterfaceApi { * * @return the list of snapshots */ - Set listVirtualInterfacesForServer(String serverId); + FluentIterable listOnServer(String serverId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceAsyncApi.java index f37bf6904e..de94545adf 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -34,8 +32,10 @@ import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -44,17 +44,18 @@ import com.google.common.util.concurrent.ListenableFuture; * @see VirtualInterfaceApi * @author Adam Lowe */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VIRTUAL_INTERFACES) @SkipEncoding({'/', '='}) @RequestFilters(AuthenticateRequest.class) public interface VirtualInterfaceAsyncApi { /** - * @see VirtualInterfaceApi#listVirtualInterfacesForServer(String) + * @see VirtualInterfaceApi#listOnServer(String) */ @GET @SelectJson("virtual_interfaces") @Consumes(MediaType.APPLICATION_JSON) @Path("/servers/{server_id}/os-virtual-interfaces") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listVirtualInterfacesForServer(@PathParam("server_id") String serverId); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listOnServer(@PathParam("server_id") String serverId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApi.java index 3e3af64ccf..30f509fd90 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -30,13 +29,18 @@ import org.jclouds.openstack.nova.v2_0.options.CreateVolumeSnapshotOptions; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Volumes. *

* + * @see VolumeAsyncApi * @see org.jclouds.openstack.nova.v2_0.extensions.VolumeAsyncApi * @author Adam Lowe */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUMES) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface VolumeApi { @@ -45,42 +49,42 @@ public interface VolumeApi { * * @return the list of snapshots */ - Set listVolumes(); + FluentIterable list(); /** * Returns a detailed list of volumes. * * @return the list of volumes. */ - Set listVolumesInDetail(); + FluentIterable listInDetail(); /** * Return data about the given volume. * * @return details of a specific snapshot. */ - Volume getVolume(String volumeId); + Volume get(String volumeId); /** * Creates a new Snapshot * * @return the new Snapshot */ - Volume createVolume(int sizeGB, CreateVolumeOptions... options); + Volume create(int sizeGB, CreateVolumeOptions... options); /** * Delete a snapshot. * * @return true if successful */ - Boolean deleteVolume(String volumeId); + boolean delete(String volumeId); /** * List volume attachments for a given instance. * * @return all Floating IPs */ - Set listAttachmentsOnServer(String serverId); + FluentIterable listAttachmentsOnServer(String serverId); /** * Get a specific attached volume. @@ -108,14 +112,14 @@ public interface VolumeApi { * * @return the list of snapshots */ - Set listSnapshots(); + FluentIterable listSnapshots(); /** * Returns a summary list of snapshots. * * @return the list of snapshots */ - Set listSnapshotsInDetail(); + FluentIterable listSnapshotsInDetail(); /** * Return data about the given snapshot. @@ -136,6 +140,6 @@ public interface VolumeApi { * * @return true if successful */ - Boolean deleteSnapshot(String snapshotId); + boolean deleteSnapshot(String snapshotId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAsyncApi.java index 412183aca3..d85bf687cc 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.extensions; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -44,10 +42,12 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.WrapWith; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -57,6 +57,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @see org.jclouds.openstack.nova.v2_0.extensions.VolumeAsyncApi * @author Adam Lowe */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUMES) @SkipEncoding({'/', '='}) @RequestFilters(AuthenticateRequest.class) @@ -70,8 +71,8 @@ public interface VolumeAsyncApi { @Path("/os-volumes") @SelectJson("volumes") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listVolumes(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** * Returns a detailed list of volumes. @@ -82,8 +83,8 @@ public interface VolumeAsyncApi { @Path("/os-volumes/detail") @SelectJson("volumes") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listVolumesInDetail(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listInDetail(); /** * Return data about the given volume. @@ -95,7 +96,7 @@ public interface VolumeAsyncApi { @SelectJson("volume") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVolume(@PathParam("id") String volumeId); + ListenableFuture get(@PathParam("id") String volumeId); /** * Creates a new volume @@ -108,7 +109,7 @@ public interface VolumeAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @MapBinder(CreateVolumeOptions.class) - ListenableFuture createVolume(@PayloadParam("size") int sizeGB, CreateVolumeOptions... options); + ListenableFuture create(@PayloadParam("size") int sizeGB, CreateVolumeOptions... options); /** * Delete a volume. @@ -119,7 +120,7 @@ public interface VolumeAsyncApi { @Path("/os-volumes/{id}") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture deleteVolume(@PathParam("id") String volumeId); + ListenableFuture delete(@PathParam("id") String volumeId); /** * List volume attachments for a given instance. @@ -130,8 +131,8 @@ public interface VolumeAsyncApi { @Path("/servers/{server_id}/os-volume_attachments") @SelectJson("volumeAttachments") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listAttachmentsOnServer(@PathParam("server_id") String serverId); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listAttachmentsOnServer(@PathParam("server_id") String serverId); /** * Get a specific attached volume. @@ -180,8 +181,8 @@ public interface VolumeAsyncApi { @Path("/os-snapshots") @SelectJson("snapshots") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listSnapshots(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listSnapshots(); /** * Returns a summary list of snapshots. @@ -192,8 +193,8 @@ public interface VolumeAsyncApi { @Path("/os-snapshots/detail") @SelectJson("snapshots") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listSnapshotsInDetail(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listSnapshotsInDetail(); /** * Return data about the given snapshot. diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApi.java index b1225c3d0a..16d2950785 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApi.java @@ -19,16 +19,16 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.nova.v2_0.domain.VolumeType; import org.jclouds.openstack.nova.v2_0.options.CreateVolumeTypeOptions; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.services.Extension; -import org.jclouds.rest.annotations.RequestFilters; + +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; /** * Provides synchronous access to Volume Type features @@ -39,21 +39,21 @@ import org.jclouds.rest.annotations.RequestFilters; * @see * @see */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUME_TYPES) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -@RequestFilters(AuthenticateRequest.class) public interface VolumeTypeApi { /** * @return set of all volume types */ - Set listVolumeTypes(); + FluentIterable list(); /** * @param id the id of the volume type to retrieve * @return the requested volume type */ - VolumeType getVolumeType(String id); + VolumeType get(String id); /** * Creates a new volume type @@ -62,23 +62,23 @@ public interface VolumeTypeApi { * @param options optional settings for the new volume type * @return the new volume type */ - VolumeType createVolumeType(String name, CreateVolumeTypeOptions... options); + VolumeType create(String name, CreateVolumeTypeOptions... options); /** * Deletes a volume type */ - Boolean deleteVolumeType(String id); + boolean delete(String id); /** * @param id the id of the volume type * @return the set of extra metadata for the flavor */ - Map getAllExtraSpecs(String id); + Map getExtraSpecs(String id); /** * Creates or updates the extra metadata for a given flavor */ - Boolean setAllExtraSpecs(String id, Map specs); + boolean updateExtraSpecs(String id, Map specs); /** * Retrieve a single extra spec value @@ -95,7 +95,7 @@ public interface VolumeTypeApi { * @param key the extra spec key (when creating ensure this does not include whitespace or other difficult characters) * @param value the new value to store associate with the key */ - Boolean setExtraSpec(String id, String key, String value); + boolean updateExtraSpec(String id, String key, String value); /** * Deletes an existing extra spec @@ -103,5 +103,5 @@ public interface VolumeTypeApi { * @param id the id of the volume type * @param key the key of the extra spec to delete */ - Boolean deleteExtraSpec(String id, String key); + boolean deleteExtraSpec(String id, String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeAsyncApi.java index e50e172a8f..8dc6061ecf 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeAsyncApi.java @@ -19,7 +19,6 @@ package org.jclouds.openstack.nova.v2_0.extensions; import java.util.Map; -import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -46,11 +45,13 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.annotations.WrapWith; import org.jclouds.rest.binders.BindToJsonPayload; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -59,6 +60,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adam Lowe * @see VolumeTypeApi */ +@Beta @Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUME_TYPES) @SkipEncoding({'/', '='}) @RequestFilters(AuthenticateRequest.class) @@ -67,58 +69,58 @@ import com.google.common.util.concurrent.ListenableFuture; public interface VolumeTypeAsyncApi { /** - * @see VolumeTypeApi#listVolumeTypes + * @see VolumeTypeApi#list */ @GET @SelectJson("volume_types") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listVolumeTypes(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see VolumeTypeApi#getVolumeType + * @see VolumeTypeApi#get */ @GET @Path("/{id}") @SelectJson("volume_type") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVolumeType(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** - * @see VolumeTypeApi#createVolumeType + * @see VolumeTypeApi#create */ @POST @SelectJson("volume_type") @Produces(MediaType.APPLICATION_JSON) @WrapWith("volume_type") - ListenableFuture createVolumeType(@PayloadParam("name") String name, CreateVolumeTypeOptions... options); + ListenableFuture create(@PayloadParam("name") String name, CreateVolumeTypeOptions... options); /** - * @see VolumeTypeApi#deleteVolumeType + * @see VolumeTypeApi#delete */ @DELETE @Path("/{id}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture deleteVolumeType(@PathParam("id") String id); + ListenableFuture delete(@PathParam("id") String id); /** - * @see VolumeTypeApi#getAllExtraSpecs(String) + * @see VolumeTypeApi#getExtraSpecs(String) */ @GET @SelectJson("extra_specs") @Path("/{id}/extra_specs") @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) - ListenableFuture> getAllExtraSpecs(@PathParam("id") String id); + ListenableFuture> getExtraSpecs(@PathParam("id") String id); /** - * @see VolumeTypeApi#setAllExtraSpecs(String, java.util.Map) + * @see VolumeTypeApi#updateExtraSpecs(String, java.util.Map) */ @POST @Path("/{id}/extra_specs") @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @MapBinder(BindToJsonPayload.class) - ListenableFuture setAllExtraSpecs(@PathParam("id") String id, @PayloadParam("extra_specs") Map specs); + ListenableFuture updateExtraSpecs(@PathParam("id") String id, @PayloadParam("extra_specs") Map specs); /** * @see VolumeTypeApi#getExtraSpec(String, String) @@ -130,14 +132,14 @@ public interface VolumeTypeAsyncApi { ListenableFuture getExtraSpec(@PathParam("id") String id, @PathParam("key") String key); /** - * @see VolumeTypeApi#setExtraSpec(String, String, String) + * @see VolumeTypeApi#updateExtraSpec(String, String, String) */ @PUT @Path("/{id}/extra_specs/{key}") @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"{key}\":\"{value}\"%7D") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - ListenableFuture setExtraSpec(@PathParam("id") String id, + ListenableFuture updateExtraSpec(@PathParam("id") String id, @PathParam("key") @PayloadParam("key") String key, @PayloadParam("value") String value); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorApi.java index 5eb5cc69ed..bfda028a9d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorApi.java @@ -18,20 +18,22 @@ */ package org.jclouds.openstack.nova.v2_0.features; -import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.nova.v2_0.domain.Flavor; import org.jclouds.openstack.v2_0.domain.Resource; +import org.jclouds.openstack.v2_0.options.PaginationOptions; /** * Provides asynchronous access to Flavors via their REST API. *

* - * @see FlavorApi + * @see FlavorAsyncApi * @see * @author Jeremy Daggett */ @@ -43,14 +45,18 @@ public interface FlavorApi { * * @return all flavors (IDs, names, links) */ - Set listFlavors(); + PagedIterable list(); + + PaginatedCollection list(PaginationOptions options); /** * List all flavors (all details) * * @return all flavors (all details) */ - Set listFlavorsInDetail(); + PagedIterable listInDetail(); + + PaginatedCollection listInDetail(PaginationOptions options); /** * List details of the specified flavor @@ -59,6 +65,6 @@ public interface FlavorApi { * id of the flavor * @return flavor or null if not found */ - Flavor getFlavor(String id); + Flavor get(String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorAsyncApi.java index 632f888668..411acb5cd8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/FlavorAsyncApi.java @@ -18,22 +18,28 @@ */ package org.jclouds.openstack.nova.v2_0.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; +import org.jclouds.collect.PagedIterable; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; import org.jclouds.openstack.nova.v2_0.domain.Flavor; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseFlavorDetails; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseFlavors; import org.jclouds.openstack.v2_0.domain.Resource; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -44,43 +50,65 @@ import com.google.common.util.concurrent.ListenableFuture; * * @see FlavorApi * @see - * @author Jeremy Daggett TODO: Need a ListFlavorOptions class - * minDisk=minDiskInGB& minRam=minRamInMB& marker=markerID&limit=int + * "http://docs.openstack.org/api/openstack-compute/2/content/List_Flavors-d1e4188.html" + * >docs + * @author Jeremy Daggett TODO: Need a ListFlavorOptions class minDisk=minDiskInGB& + * minRam=minRamInMB& marker=markerID&limit=int */ @SkipEncoding({ '/', '=' }) @RequestFilters(AuthenticateRequest.class) public interface FlavorAsyncApi { /** - * @see FlavorApi#listFlavors + * @see FlavorApi#list() */ @GET - @SelectJson("flavors") @Consumes(MediaType.APPLICATION_JSON) @Path("/flavors") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listFlavors(); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseFlavors.class) + @Transform(ParseFlavors.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** @see FlavorApi#list(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/flavors") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseFlavors.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> list(PaginationOptions options); /** - * @see FlavorApi#listFlavorsInDetail + * @see FlavorApi#listInDetail() */ @GET - @SelectJson("flavors") @Consumes(MediaType.APPLICATION_JSON) @Path("/flavors/detail") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listFlavorsInDetail(); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseFlavorDetails.class) + @Transform(ParseFlavorDetails.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> listInDetail(); + + /** @see FlavorApi#listInDetail(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/flavors/detail") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseFlavorDetails.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> listInDetail(PaginationOptions options); /** - * @see FlavorApi#getFlavor + * @see FlavorApi#get */ @GET @SelectJson("flavor") @Consumes(MediaType.APPLICATION_JSON) @Path("/flavors/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getFlavor(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java index 89fe3e38d5..a6ccf4d17b 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java @@ -18,12 +18,14 @@ */ package org.jclouds.openstack.nova.v2_0.features; -import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.nova.v2_0.domain.Image; import org.jclouds.openstack.v2_0.domain.Resource; +import org.jclouds.openstack.v2_0.options.PaginationOptions; /** * Provides synchronous access to Images. @@ -43,14 +45,18 @@ public interface ImageApi { * * @return all images (IDs, names, links) */ - Set listImages(); + PagedIterable list(); + + PaginatedCollection list(PaginationOptions options); /** * List all images (all details) * * @return all images (all details) */ - Set listImagesInDetail(); + PagedIterable listInDetail(); + + PaginatedCollection listInDetail(PaginationOptions options); /** * List details of the specified image @@ -59,7 +65,7 @@ public interface ImageApi { * id of the server * @return server or null if not found */ - Image getImage(String id); + Image get(String id); /** * Delete the specified image @@ -68,6 +74,6 @@ public interface ImageApi { * id of the image * @return server or null if not found */ - void deleteImage(String id); + void delete(String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java index 40fbc949b6..c68fb74149 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -27,14 +25,22 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; +import org.jclouds.collect.PagedIterable; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; import org.jclouds.openstack.nova.v2_0.domain.Image; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImageDetails; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages; import org.jclouds.openstack.v2_0.domain.Resource; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; @@ -52,42 +58,64 @@ import com.google.common.util.concurrent.ListenableFuture; public interface ImageAsyncApi { /** - * @see ImageApi#listImages + * @see ImageApi#list() */ @GET - @SelectJson("images") @Consumes(MediaType.APPLICATION_JSON) @Path("/images") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listImages(); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImages.class) + @Transform(ParseImages.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** @see ImageApi#list(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/images") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImages.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> list(PaginationOptions options); /** - * @see ImageApi#listImagesInDetail + * @see ImageApi#listInDetail() */ @GET - @SelectJson("images") @Consumes(MediaType.APPLICATION_JSON) @Path("/images/detail") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listImagesInDetail(); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImageDetails.class) + @Transform(ParseImageDetails.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> listInDetail(); + + /** @see ImageApi#listInDetail(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/images/detail") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImageDetails.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> listInDetail(PaginationOptions options); /** - * @see ImageApi#getImage + * @see ImageApi#get */ @GET @SelectJson("image") @Consumes(MediaType.APPLICATION_JSON) @Path("/images/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getImage(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** - * @see ImageApi#deleteImage + * @see ImageApi#delete */ @DELETE @Consumes(MediaType.APPLICATION_JSON) @Path("/images/{id}") @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - ListenableFuture deleteImage(@PathParam("id") String id); + ListenableFuture delete(@PathParam("id") String id); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java index 1378b18856..c289e24a95 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java @@ -18,16 +18,18 @@ */ package org.jclouds.openstack.nova.v2_0.features; -import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.nova.v2_0.domain.RebootType; import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.nova.v2_0.domain.ServerCreated; import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; import org.jclouds.openstack.nova.v2_0.options.RebuildServerOptions; import org.jclouds.openstack.v2_0.domain.Resource; +import org.jclouds.openstack.v2_0.options.PaginationOptions; /** * Provides synchronous access to Server. @@ -47,14 +49,18 @@ public interface ServerApi { * * @return all servers (IDs, names, links) */ - Set listServers(); + PagedIterable list(); + + PaginatedCollection list(PaginationOptions options); /** * List all servers (all details) * * @return all servers (all details) */ - Set listServersInDetail(); + PagedIterable listInDetail(); + + PaginatedCollection listInDetail(PaginationOptions options); /** * List details of the specified server @@ -63,7 +69,7 @@ public interface ServerApi { * id of the server * @return server or null if not found */ - Server getServer(String id); + Server get(String id); /** * Create a new server @@ -81,7 +87,7 @@ public interface ServerApi { */ // blocking call @Timeout(duration = 10, timeUnit = TimeUnit.MINUTES) - ServerCreated createServer(String name, String imageRef, String flavorRef, CreateServerOptions... options); + ServerCreated create(String name, String imageRef, String flavorRef, CreateServerOptions... options); /** * Terminate and delete a server. @@ -90,7 +96,7 @@ public interface ServerApi { * id of the server * @return True if successful, False otherwise */ - Boolean deleteServer(String id); + Boolean delete(String id); /** * Start a server @@ -98,7 +104,7 @@ public interface ServerApi { * @param id * id of the server */ - void startServer(String id); + void start(String id); /** * Stop a server @@ -106,7 +112,7 @@ public interface ServerApi { * @param id * id of the server */ - void stopServer(String id); + void stop(String id); /** * Reboot a server. @@ -116,7 +122,7 @@ public interface ServerApi { * @param rebootType * The type of reboot to perform (Hard/Soft) */ - void rebootServer(String id, RebootType rebootType); + void reboot(String id, RebootType rebootType); /** * Resize a server to a new flavor size. @@ -126,7 +132,7 @@ public interface ServerApi { * @param flavorId * id of the new flavor to use */ - void resizeServer(String id, String flavorId); + void resize(String id, String flavorId); /** * Confirm a resize operation. @@ -134,7 +140,7 @@ public interface ServerApi { * @param id * id of the server */ - void confirmResizeServer(String id); + void confirmResize(String id); /** * Revert a resize operation. @@ -142,7 +148,7 @@ public interface ServerApi { * @param id * id of the server */ - void revertResizeServer(String id); + void revertResize(String id); /** * Rebuild a server. @@ -152,7 +158,7 @@ public interface ServerApi { * @param options * Optional parameters to the rebuilding operation. */ - void rebuildServer(String id, RebuildServerOptions... options); + void rebuild(String id, RebuildServerOptions... options); /** * Change the administrative password to a server. @@ -172,7 +178,7 @@ public interface ServerApi { * @param newName * The new name for the server */ - void renameServer(String id, String newName); + void rename(String id, String newName); /** * Create an image from a server. diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java index c1d7a7b79b..848a57ddeb 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -30,14 +28,20 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.jclouds.collect.PagedIterable; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; import org.jclouds.openstack.nova.v2_0.domain.RebootType; import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.nova.v2_0.domain.ServerCreated; import org.jclouds.openstack.nova.v2_0.functions.ParseImageIdFromLocationHeader; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServerDetails; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServers; import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; import org.jclouds.openstack.nova.v2_0.options.RebuildServerOptions; import org.jclouds.openstack.v2_0.domain.Resource; +import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.Payload; @@ -46,9 +50,10 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -69,123 +74,146 @@ import com.google.common.util.concurrent.ListenableFuture; public interface ServerAsyncApi { /** - * @see ServerApi#listServers + * @see ServerApi#list() */ @GET - @SelectJson("servers") @Consumes(MediaType.APPLICATION_JSON) @Path("/servers") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listServers(); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseServers.class) + @Transform(ParseServers.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** @see ServerApi#list(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/servers") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseServers.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> list(PaginationOptions options); /** - * @see ServerApi#listServersInDetail + * @see ServerApi#listInDetail() */ @GET - @SelectJson("servers") @Consumes(MediaType.APPLICATION_JSON) @Path("/servers/detail") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listServersInDetail(); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseServerDetails.class) + @Transform(ParseServerDetails.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> listInDetail(); + + /** @see ServerApi#listInDetail(PaginationOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/servers/detail") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseServerDetails.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> listInDetail(PaginationOptions options); + /** - * @see ServerApi#getServer + * @see ServerApi#get */ @GET @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) @Path("/servers/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getServer(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** - * @see ServerApi#deleteServer + * @see ServerApi#delete */ @DELETE @Consumes @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @Path("/servers/{id}") - ListenableFuture deleteServer(@PathParam("id") String id); + ListenableFuture delete(@PathParam("id") String id); /** - * @see ServerApi#startServer + * @see ServerApi#start */ @POST @Path("/servers/{id}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("{\"os-start\":null}") - ListenableFuture startServer(@PathParam("id") String id); + ListenableFuture start(@PathParam("id") String id); /** - * @see ServerApi#stopServer + * @see ServerApi#stop */ @POST @Path("/servers/{id}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("{\"os-stop\":null}") - ListenableFuture stopServer(@PathParam("id") String id); + ListenableFuture stop(@PathParam("id") String id); /** - * @see ServerApi#rebootServer + * @see ServerApi#reboot */ @POST @Path("/servers/{id}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"reboot\":%7B\"type\":\"{type}\"%7D%7D") - ListenableFuture rebootServer(@PathParam("id") String id, @PayloadParam("type") RebootType rebootType); + ListenableFuture reboot(@PathParam("id") String id, @PayloadParam("type") RebootType rebootType); /** - * @see ServerApi#resizeServer + * @see ServerApi#resize */ @POST @Path("/servers/{id}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"resize\":%7B\"flavorRef\":{flavorId}%7D%7D") - ListenableFuture resizeServer(@PathParam("id") String id, @PayloadParam("flavorId") String flavorId); + ListenableFuture resize(@PathParam("id") String id, @PayloadParam("flavorId") String flavorId); /** - * @see ServerApi#confirmResizeServer + * @see ServerApi#confirmResize */ @POST @Path("/servers/{id}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("{\"confirmResize\":null}") - ListenableFuture confirmResizeServer(@PathParam("id") String id); + ListenableFuture confirmResize(@PathParam("id") String id); /** - * @see ServerApi#revertResizeServer + * @see ServerApi#revertResize */ @POST @Path("/servers/{id}/action") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("{\"revertResize\":null}") - ListenableFuture revertResizeServer(@PathParam("id") String id); + ListenableFuture revertResize(@PathParam("id") String id); /** - * @see ServerApi#createServer + * @see ServerApi#create */ @POST @Unwrap @Consumes(MediaType.APPLICATION_JSON) @Path("/servers") @MapBinder(CreateServerOptions.class) - ListenableFuture createServer(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef, + ListenableFuture create(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef, @PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options); /** - * @see ServerApi#rebuildServer + * @see ServerApi#rebuild */ @POST @Path("/servers/{id}/action") @Consumes @MapBinder(RebuildServerOptions.class) - ListenableFuture rebuildServer(@PathParam("id") String id, RebuildServerOptions... options); + ListenableFuture rebuild(@PathParam("id") String id, RebuildServerOptions... options); /** * @see ServerApi#changeAdminPass @@ -198,14 +226,14 @@ public interface ServerAsyncApi { ListenableFuture changeAdminPass(@PathParam("id") String id, @PayloadParam("adminPass") String adminPass); /** - * @see ServerApi#renameServer + * @see ServerApi#rename */ @PUT @Path("/servers/{id}") @Consumes @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"server\":%7B\"name\":\"{name}\"%7D%7D") - ListenableFuture renameServer(@PathParam("id") String id, @PayloadParam("name") String newName); + ListenableFuture rename(@PathParam("id") String id, @PayloadParam("name") String newName); /** * @see ServerApi#createImageFromServer diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavorDetails.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavorDetails.java new file mode 100644 index 0000000000..45354e057b --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavorDetails.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.domain.Flavor; +import org.jclouds.openstack.nova.v2_0.features.FlavorApi; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseFlavorDetails.Flavors; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseFlavorDetails extends ParseJson> { + static class Flavors extends PaginatedCollection { + + @ConstructorProperties({ "flavors", "flavors_links" }) + protected Flavors(Iterable flavors, Iterable flavors_links) { + super(flavors, flavors_links); + } + + } + + @Inject + public ParseFlavorDetails(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final NovaApi api; + + @Inject + protected ToPagedIterable(NovaApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final FlavorApi flavorApi = api.getFlavorApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(flavorApi.listInDetail(marker(input.toString()))); + } + + @Override + public String toString() { + return "listFlavorsInDetail()"; + } + }; + } + + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavors.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavors.java new file mode 100644 index 0000000000..fd28914d88 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseFlavors.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.features.FlavorApi; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseFlavors.Flavors; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.openstack.v2_0.domain.Resource; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseFlavors extends ParseJson> { + static class Flavors extends PaginatedCollection { + + @ConstructorProperties({ "flavors", "flavors_links" }) + protected Flavors(Iterable flavors, Iterable flavors_links) { + super(flavors, flavors_links); + } + + } + + @Inject + public ParseFlavors(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final NovaApi api; + + @Inject + protected ToPagedIterable(NovaApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final FlavorApi flavorApi = api.getFlavorApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(flavorApi.list(marker(input.toString()))); + } + + @Override + public String toString() { + return "listFlavors()"; + } + }; + } + + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImageDetails.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImageDetails.java new file mode 100644 index 0000000000..225e9f15e7 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImageDetails.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.domain.Image; +import org.jclouds.openstack.nova.v2_0.features.ImageApi; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImageDetails.Images; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseImageDetails extends ParseJson> { + static class Images extends PaginatedCollection { + + @ConstructorProperties({ "images", "images_links" }) + protected Images(Iterable images, Iterable images_links) { + super(images, images_links); + } + + } + + @Inject + public ParseImageDetails(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final NovaApi api; + + @Inject + protected ToPagedIterable(NovaApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final ImageApi imageApi = api.getImageApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(imageApi.listInDetail(marker(input.toString()))); + } + + @Override + public String toString() { + return "listInDetail()"; + } + }; + } + + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImages.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImages.java new file mode 100644 index 0000000000..51680f72c4 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseImages.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.features.ImageApi; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages.Images; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.openstack.v2_0.domain.Resource; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseImages extends ParseJson> { + static class Images extends PaginatedCollection { + + @ConstructorProperties({ "images", "images_links" }) + protected Images(Iterable images, Iterable images_links) { + super(images, images_links); + } + + } + + @Inject + public ParseImages(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final NovaApi api; + + @Inject + protected ToPagedIterable(NovaApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final ImageApi imageApi = api.getImageApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(imageApi.list(marker(input.toString()))); + } + + @Override + public String toString() { + return "list()"; + } + }; + } + + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseKeyPairs.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseKeyPairs.java new file mode 100644 index 0000000000..1f4d54ab3c --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseKeyPairs.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.json.internal.GsonWrapper; +import org.jclouds.openstack.nova.v2_0.domain.KeyPair; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.FluentIterable; +import com.google.inject.Inject; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ParseKeyPairs implements Function> { + private final ParseFirstJsonValueNamed> parser; + + private static class Wrapper implements Supplier { + private KeyPair keypair; + + @Override + public KeyPair get() { + return keypair; + } + + } + + @Inject + public ParseKeyPairs(GsonWrapper gsonView) { + this.parser = new ParseFirstJsonValueNamed>(checkNotNull(gsonView, "gsonView"), + new TypeLiteral>() { + }, "keypairs"); + } + + public FluentIterable apply(HttpResponse response) { + checkNotNull(response, "response"); + return parser.apply(response).transform(Suppliers. supplierFunction()); + } +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServerDetails.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServerDetails.java new file mode 100644 index 0000000000..588d99d4e3 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServerDetails.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.domain.Server; +import org.jclouds.openstack.nova.v2_0.features.ServerApi; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServerDetails.Servers; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseServerDetails extends ParseJson> { + static class Servers extends PaginatedCollection { + + @ConstructorProperties({ "servers", "servers_links" }) + protected Servers(Iterable servers, Iterable servers_links) { + super(servers, servers_links); + } + + } + + @Inject + public ParseServerDetails(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final NovaApi api; + + @Inject + protected ToPagedIterable(NovaApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final ServerApi serverApi = api.getServerApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(serverApi.listInDetail(marker(input.toString()))); + } + + @Override + public String toString() { + return "listInDetail()"; + } + }; + } + + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServers.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServers.java new file mode 100644 index 0000000000..fb8d05d69f --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/ParseServers.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.features.ServerApi; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServers.Servers; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.openstack.v2_0.domain.Resource; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseServers extends ParseJson> { + static class Servers extends PaginatedCollection { + + @ConstructorProperties({ "servers", "servers_links" }) + protected Servers(Iterable servers, Iterable servers_links) { + super(servers, servers_links); + } + + } + + @Inject + public ParseServers(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final NovaApi api; + + @Inject + protected ToPagedIterable(NovaApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final ServerApi serverApi = api.getServerApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(serverApi.list(marker(input.toString()))); + } + + @Override + public String toString() { + return "list()"; + } + }; + } + + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateBackupOfServerOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateBackupOfServerOptions.java index 93ed7563a3..b56eea2749 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateBackupOfServerOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateBackupOfServerOptions.java @@ -55,7 +55,7 @@ public class CreateBackupOfServerOptions implements MapBinder { @Override public R bindToRequest(R request, Object toBind) { - throw new IllegalStateException("createBackupOfServer is a POST operation"); + throw new IllegalStateException("createBackup is a POST operation"); } @Override diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java index 4acf3594bb..db2bbed3ee 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java @@ -152,7 +152,7 @@ public class CreateServerOptions implements MapBinder { return string().toString(); } - private class ServerRequest { + static class ServerRequest { final String name; final String imageRef; final String flavorRef; diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/ListOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/ListOptions.java index 8cd271c3ae..4d8fa91b04 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/ListOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/ListOptions.java @@ -20,16 +20,16 @@ package org.jclouds.openstack.nova.v2_0.options; import java.util.Date; -import org.jclouds.openstack.v2_0.options.BaseListOptions; +import org.jclouds.openstack.v2_0.options.PaginationOptions; /** * Options used to control the amount of detail in the request. * - * @see BaseListOptions + * @see PaginationOptions * @see * @author Adrian Cole */ -public class ListOptions extends BaseListOptions { +public class ListOptions extends PaginationOptions { public static final ListOptions NONE = new ListOptions(); @@ -56,8 +56,8 @@ public class ListOptions extends BaseListOptions { * {@inheritDoc} */ @Override - public ListOptions maxResults(int limit) { - super.maxResults(limit); + public ListOptions limit(int limit) { + super.limit(limit); return this; } @@ -66,8 +66,8 @@ public class ListOptions extends BaseListOptions { * {@inheritDoc} */ @Override - public ListOptions startAt(long offset) { - super.startAt(offset); + public ListOptions marker(String marker) { + super.marker(marker); return this; } @@ -82,23 +82,23 @@ public class ListOptions extends BaseListOptions { } /** - * @see BaseListOptions#startAt(long) + * @see PaginationOptions#marker(String) */ - public static ListOptions startAt(long prefix) { + public static ListOptions marker(String marker) { ListOptions options = new ListOptions(); - return options.startAt(prefix); + return options.marker(marker); } /** - * @see BaseListOptions#maxResults(long) + * @see PaginationOptions#limit(long) */ public static ListOptions maxResults(int maxKeys) { ListOptions options = new ListOptions(); - return options.maxResults(maxKeys); + return options.limit(maxKeys); } /** - * @see BaseListOptions#changesSince(Date) + * @see PaginationOptions#changesSince(Date) */ public static ListOptions changesSince(Date since) { ListOptions options = new ListOptions(); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java index 0c435e3c61..bf4f1ad2ac 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/predicates/FindSecurityGroupWithNameAndReturnTrue.java @@ -67,7 +67,7 @@ public class FindSecurityGroupWithNameAndReturnTrue implements Predicate() { + SecurityGroup returnVal = Iterables.find(api.get().list(), new Predicate() { @Override public boolean apply(SecurityGroup input) { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest.java index 41ec1504a5..3abe926c5a 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest.java @@ -70,7 +70,7 @@ public class AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest extends Ba assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().toString(), + assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseServerListTest().expected().toString()); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java index 0c113d0b10..c8acfec60c 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java @@ -70,7 +70,7 @@ public class AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().toString(), + assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseServerListTest().expected().toString()); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAuthenticationExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAuthenticationExpectTest.java index 3e737e0fa7..eee0154afc 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAuthenticationExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAuthenticationExpectTest.java @@ -65,7 +65,7 @@ public class AccessKeyAndSecretKeyAuthenticationExpectTest extends BaseNovaApiEx assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().toString(), + assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseServerListTest().expected().toString()); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationExpectTest.java index 51c6815af6..d3b6c4152e 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationExpectTest.java @@ -56,7 +56,7 @@ public class PasswordAuthenticationExpectTest extends BaseNovaApiExpectTest { assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().toString(), + assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseServerListTest().expected().toString()); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationWithTenantNameExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationWithTenantNameExpectTest.java index ad19ef2864..2e63e910a9 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationWithTenantNameExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/PasswordAuthenticationWithTenantNameExpectTest.java @@ -65,7 +65,7 @@ public class PasswordAuthenticationWithTenantNameExpectTest extends BaseNovaApiE assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().toString(), + assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseServerListTest().expected().toString()); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java index 3b2e6f4a2d..48ff0689e8 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java @@ -79,7 +79,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC Map requestResponseMap = ImmutableMap. builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) .put(extensionsOfNovaRequest, extensionsOfNovaResponse) - .put(listImagesDetail, listImagesDetailResponse) + .put(listDetail, listDetailResponse) .put(listFlavorsDetail, listFlavorsDetailResponse) .put(createServer, createServerResponse) .put(serverDetail, serverDetailResponse).build(); @@ -131,7 +131,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC Map requestResponseMap = ImmutableMap. builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) .put(extensionsOfNovaRequest, extensionsOfNovaResponse) - .put(listImagesDetail, listImagesDetailResponse) + .put(listDetail, listDetailResponse) .put(listFlavorsDetail, listFlavorsDetailResponse) .put(createServer, createServerResponse) .put(serverDetail, serverDetailResponse).build(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java index b29a11f371..37abcd0885 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java @@ -57,7 +57,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe Map requestResponseMap = ImmutableMap. builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) - .put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(listImagesDetail, listImagesDetailResponse) + .put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(listDetail, listDetailResponse) .put(listServers, listServersResponse).put(listFlavorsDetail, listFlavorsDetailResponse).build(); ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap); @@ -88,7 +88,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe .endpoint("https://nova-api.trystack.org:9774/v1.1/3456/extensions").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/extension_list_trystack.json")) .build()) - .put(listImagesDetail.toBuilder() + .put(listDetail.toBuilder() .endpoint("https://nova-api.trystack.org:9774/v1.1/3456/images/detail").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/image_list_detail_trystack.json")) .build()) @@ -135,7 +135,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe assertTrue(apiWhenNoServersExist.listNodes().isEmpty()); } - HttpRequest listSecurityGroups = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://nova-api.trystack.org:9774/v1.1/3456/os-security-groups") @@ -144,7 +144,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe HttpResponse notFound = HttpResponse.builder().statusCode(404).build(); - HttpRequest createSecurityGroupWithPrefixOnGroup = HttpRequest + HttpRequest createWithPrefixOnGroup = HttpRequest .builder() .method("POST") .endpoint("https://nova-api.trystack.org:9774/v1.1/3456/os-security-groups") @@ -158,7 +158,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe HttpResponse securityGroupCreated = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/securitygroup_created.json")).build(); - HttpRequest createSecurityGroupRuleForDefaultPort22 = HttpRequest + HttpRequest createRuleForDefaultPort22 = HttpRequest .builder() .method("POST") .endpoint("https://nova-api.trystack.org:9774/v1.1/3456/os-security-group-rules") @@ -182,7 +182,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe HttpResponse securityGroupWithPort22 = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/securitygroup_details_port22.json")).build(); - HttpRequest createKeyPair = HttpRequest + HttpRequest create = HttpRequest .builder() .method("POST") .endpoint("https://nova-api.trystack.org:9774/v1.1/3456/os-keypairs") @@ -210,15 +210,15 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe public void testCreateNodeWithGeneratedKeyPair() throws Exception { Builder requestResponseMap = ImmutableMap. builder() .putAll(defaultTemplateTryStack); - requestResponseMap.put(listSecurityGroups, notFound); + requestResponseMap.put(list, notFound); - requestResponseMap.put(createSecurityGroupWithPrefixOnGroup, securityGroupCreated); + requestResponseMap.put(createWithPrefixOnGroup, securityGroupCreated); - requestResponseMap.put(createSecurityGroupRuleForDefaultPort22, securityGroupRuleCreated); + requestResponseMap.put(createRuleForDefaultPort22, securityGroupRuleCreated); requestResponseMap.put(getSecurityGroup, securityGroupWithPort22); - requestResponseMap.put(createKeyPair, keyPairWithPrivateKey); + requestResponseMap.put(create, keyPairWithPrivateKey); requestResponseMap.put(serverDetail, serverDetailResponse); @@ -266,11 +266,11 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe public void testCreateNodeWhileUserSpecifiesKeyPair() throws Exception { Builder requestResponseMap = ImmutableMap. builder() .putAll(defaultTemplateTryStack); - requestResponseMap.put(listSecurityGroups, notFound); + requestResponseMap.put(list, notFound); - requestResponseMap.put(createSecurityGroupWithPrefixOnGroup, securityGroupCreated); + requestResponseMap.put(createWithPrefixOnGroup, securityGroupCreated); - requestResponseMap.put(createSecurityGroupRuleForDefaultPort22, securityGroupRuleCreated); + requestResponseMap.put(createRuleForDefaultPort22, securityGroupRuleCreated); requestResponseMap.put(getSecurityGroup, securityGroupWithPort22); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java index ebd632b13d..39062ed150 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java @@ -106,12 +106,12 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer "{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}", "application/json")).build(); - HttpRequest listFloatingIPs = HttpRequest.builder().method("GET").endpoint( + HttpRequest list = HttpRequest.builder().method("GET").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).build(); - HttpResponse listFloatingIPsResponseForUnassigned = HttpResponse.builder().statusCode(200).payload( + HttpResponse listResponseForUnassigned = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/floatingip_list.json")).build(); HttpRequest addFloatingIPRequest = addFloatingIPForAddress("10.0.0.5"); @@ -120,8 +120,8 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer ImmutableMap. builder().put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess).put(extensionsOfNovaRequest, extensionsOfNovaResponse).put( allocateFloatingIP, allocateFloatingIPResponse) - .put(addFloatingIPRequest, addFloatingIPResponse).put(listFloatingIPs, - listFloatingIPsResponseForUnassigned).build()).getContext().utils().injector() + .put(addFloatingIPRequest, addFloatingIPResponse).put(list, + listResponseForUnassigned).build()).getContext().utils().injector() .getInstance(AllocateAndAddFloatingIpToNode.class); AtomicReference nodeRef = new AtomicReference(node); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java index c2de758b67..b7552a392a 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java @@ -56,7 +56,7 @@ public class CreateUniqueKeyPairTest { expect(api.getKeyPairExtensionForZone("zone")).andReturn(optKeyApi).atLeastOnce(); - expect(keyApi.createKeyPair("group-1")).andReturn(pair); + expect(keyApi.create("group-1")).andReturn(pair); replay(api, keyApi); @@ -88,9 +88,9 @@ public class CreateUniqueKeyPairTest { expect(api.getKeyPairExtensionForZone("zone")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce(); expect(uniqueIdSupplier.get()).andReturn("1"); - expect(keyApi.createKeyPair("group-1")).andThrow(new IllegalStateException()); + expect(keyApi.create("group-1")).andThrow(new IllegalStateException()); expect(uniqueIdSupplier.get()).andReturn("2"); - expect(keyApi.createKeyPair("group-2")).andReturn(pair); + expect(keyApi.create("group-2")).andReturn(pair); replay(api, keyApi, uniqueIdSupplier); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java index 291d89ecbb..f4afb77b63 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java @@ -34,6 +34,7 @@ import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi; import org.testng.annotations.Test; import com.google.common.base.Optional; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; /** @@ -49,7 +50,8 @@ public class LoadFloatingIpsForInstanceTest { FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build(); expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce(); - expect(ipApi.listFloatingIPs()).andReturn((Set) ImmutableSet.of(testIp)).atLeastOnce(); + expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet. of(testIp))) + .atLeastOnce(); replay(api); replay(ipApi); @@ -69,7 +71,8 @@ public class LoadFloatingIpsForInstanceTest { expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce(); - expect(ipApi.listFloatingIPs()).andReturn((Set) ImmutableSet.of()).atLeastOnce(); + expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet. of())) + .atLeastOnce(); replay(api); replay(ipApi); @@ -90,9 +93,8 @@ public class LoadFloatingIpsForInstanceTest { expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce(); - expect(ipApi.listFloatingIPs()).andReturn( - (Set) ImmutableSet.of(FloatingIP.builder().id("1").ip("1.1.1.1").build())) - .atLeastOnce(); + expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet. of(FloatingIP.builder().id("1").ip("1.1.1.1").build()))) + .atLeastOnce(); replay(api); replay(ipApi); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResultExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResultExpectTest.java index 8be5dd21a1..f9da95ef1a 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResultExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/predicates/GetImageWhenImageInZoneHasActiveStatusPredicateWithResultExpectTest.java @@ -45,12 +45,12 @@ import com.google.inject.Injector; public class GetImageWhenImageInZoneHasActiveStatusPredicateWithResultExpectTest extends BaseNovaComputeServiceContextExpectTest { - private final HttpResponse listImagesDetailImageExtensionResponse = HttpResponse.builder().statusCode(200) + private final HttpResponse listDetailImageExtensionResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/image_list_detail_imageextension.json")).build(); private Map requestResponseMap = ImmutableMap. builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) - .put(listImagesDetail, listImagesDetailImageExtensionResponse).build(); + .put(listDetail, listDetailImageExtensionResponse).build(); public void testReturnsFalseOnImageStatusSavingAndTrueOnActive() { Injector injector = requestsSendResponses(requestResponseMap); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java index 6980ab1613..58285d06b2 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java @@ -47,249 +47,249 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { public void testSuspend() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.suspendServer("1")); + assertTrue(api.suspend("1")); } public void testSuspendFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.suspendServer("1")); + assertFalse(api.suspend("1")); } @Test(expectedExceptions = AuthorizationException.class) public void testSuspendFailsNotAuthorized() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), HttpResponse.builder().statusCode(403).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - api.suspendServer("1"); + api.suspend("1"); } public void testResume() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.resumeServer("1")); + assertTrue(api.resume("1")); } public void testResumeFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.resumeServer("1")); + assertFalse(api.resume("1")); } @Test(expectedExceptions = AuthorizationException.class) public void testResumeFailsNotAuthorized() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), HttpResponse.builder().statusCode(403).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - api.resumeServer("1"); + api.resume("1"); } public void testLock() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "lock").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.lockServer("1")); + assertTrue(api.lock("1")); } public void testLockFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "lock").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.lockServer("1")); + assertFalse(api.lock("1")); } public void testUnlock() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.unlockServer("1")); + assertTrue(api.unlock("1")); } public void testUnlockFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.unlockServer("1")); + assertFalse(api.unlock("1")); } public void testPause() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "pause").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.pauseServer("1")); + assertTrue(api.pause("1")); } public void testPauseFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "pause").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.pauseServer("1")); + assertFalse(api.pause("1")); } public void testUnpause() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.unpauseServer("1")); + assertTrue(api.unpause("1")); } public void testUnpauseFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.unpauseServer("1")); + assertFalse(api.unpause("1")); } public void testMigrateServer() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.migrateServer("1")); + assertTrue(api.migrate("1")); } public void testMigrateServerFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.migrateServer("1")); + assertFalse(api.migrate("1")); } public void testResetNetworkOfServer() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.resetNetworkOfServer("1")); + assertTrue(api.resetNetwork("1")); } public void testResetNetworkOfServerFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.resetNetworkOfServer("1")); + assertFalse(api.resetNetwork("1")); } public void testInjectNetworkInfoIntoServer() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(), HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.injectNetworkInfoIntoServer("1")); + assertTrue(api.injectNetworkInfo("1")); } public void testInjectNetworkInfoIntoServerFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(), HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.injectNetworkInfoIntoServer("1")); + assertFalse(api.injectNetworkInfo("1")); } public void testBackupServer() { - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action").method("POST") @@ -297,14 +297,14 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(202).addHeader("Location", "http://172.16.89.149:8774/v2/images/1976b3b3-409a-468d-b16c-a9172c341b46").build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - String imageId = api.createBackupOfServer("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other"))); + String imageId = api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other"))); assertEquals(imageId, "1976b3b3-409a-468d-b16c-a9172c341b46"); } @Test(expectedExceptions = ResourceNotFoundException.class) public void testBackupServerFailNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).method("POST") @@ -312,12 +312,12 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - api.createBackupOfServer("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other"))); + api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other"))); } public void testLiveMigrateServer() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") @@ -325,12 +325,12 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(202).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.liveMigrateServer("1", "bighost", true, false)); + assertTrue(api.liveMigrate("1", "bighost", true, false)); } public void testLiveMigrateServerFailsNotFound() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action"); - AdminActionsApi api = requestsSendResponses( + ServerAdminApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") @@ -338,7 +338,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.liveMigrateServer("1", "bighost", true, false)); + assertFalse(api.liveMigrate("1", "bighost", true, false)); } protected HttpRequest.Builder standardActionRequestBuilderVoidResponse(URI endpoint, String actionName) { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java index ae1bc4a33d..d9ea62936b 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java @@ -53,7 +53,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { private ImageApi imageApi; private ServerApi serverApi; private ExtensionApi extensionApi; - private Optional apiOption; + private Optional apiOption; private String zone; private String testServerId; @@ -78,10 +78,10 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { protected void tearDown() { if (apiOption.isPresent()) { if (testServerId != null) { - assertTrue(novaContext.getApi().getServerApiForZone(zone).deleteServer(testServerId)); + assertTrue(novaContext.getApi().getServerApiForZone(zone).delete(testServerId)); } if (backupImageId != null) { - imageApi.deleteImage(backupImageId); + imageApi.delete(backupImageId); } } super.tearDown(); @@ -94,25 +94,25 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { public void testSuspendAndResume() { if (apiOption.isPresent()) { - AdminActionsApi api = apiOption.get(); + ServerAdminApi api = apiOption.get(); // Suspend-resume try { - api.resumeServer(testServerId); + api.resume(testServerId); fail("Resumed an active server!"); } catch (HttpResponseException e) { } - assertTrue(api.suspendServer(testServerId)); + assertTrue(api.suspend(testServerId)); blockUntilServerInState(testServerId, serverApi, Status.SUSPENDED); try { - api.suspendServer(testServerId); + api.suspend(testServerId); fail("Suspended an already suspended server!"); } catch (HttpResponseException e) { } - assertTrue(api.resumeServer(testServerId)); + assertTrue(api.resume(testServerId)); blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); try { - api.resumeServer(testServerId); + api.resume(testServerId); fail("Resumed an already resumed server!"); } catch (HttpResponseException e) { } @@ -121,48 +121,48 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { public void testLockAndUnlock() { if (apiOption.isPresent()) { - AdminActionsApi api = apiOption.get(); + ServerAdminApi api = apiOption.get(); // TODO should we be able to double-lock (as it were) - assertTrue(api.unlockServer(testServerId)); - assertTrue(api.unlockServer(testServerId)); - assertTrue(api.lockServer(testServerId)); - assertTrue(api.lockServer(testServerId)); - assertTrue(api.unlockServer(testServerId)); - assertTrue(api.unlockServer(testServerId)); + assertTrue(api.unlock(testServerId)); + assertTrue(api.unlock(testServerId)); + assertTrue(api.lock(testServerId)); + assertTrue(api.lock(testServerId)); + assertTrue(api.unlock(testServerId)); + assertTrue(api.unlock(testServerId)); } } public void testResetNetworkAndInjectNetworkInfo() { if (apiOption.isPresent()) { - AdminActionsApi api = apiOption.get(); - assertTrue(api.resetNetworkOfServer(testServerId)); - assertTrue(api.injectNetworkInfoIntoServer(testServerId)); + ServerAdminApi api = apiOption.get(); + assertTrue(api.resetNetwork(testServerId)); + assertTrue(api.injectNetworkInfo(testServerId)); } } @Test public void testPauseAndUnpause() { if (apiOption.isPresent()) { - AdminActionsApi api = apiOption.get(); + ServerAdminApi api = apiOption.get(); // Unlock and lock (double-checking error contitions too) try { - api.unpauseServer(testServerId); + api.unpause(testServerId); fail("Unpaused active server!"); } catch (HttpResponseException e) { } - assertTrue(api.pauseServer(testServerId)); + assertTrue(api.pause(testServerId)); blockUntilServerInState(testServerId, serverApi, Status.PAUSED); try { - api.pauseServer(testServerId); + api.pause(testServerId); fail("paused a paused server!"); } catch (HttpResponseException e) { } - assertTrue(api.unpauseServer(testServerId)); + assertTrue(api.unpause(testServerId)); blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); try { - api.unpauseServer(testServerId); + api.unpause(testServerId); fail("Unpaused a server we just unpaused!"); } catch (HttpResponseException e) { } @@ -172,19 +172,19 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { @Test public void testCreateBackupOfServer() throws InterruptedException { if (apiOption.isPresent()) { - backupImageId = apiOption.get().createBackupOfServer(testServerId, "jclouds-test-backup", BackupType.DAILY, 0, + backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("test", "metadata"))); assertNotNull(backupImageId); // If we don't have extended task status, we'll have to wait here! - if (extensionApi.getExtensionByAlias("OS-EXT-STS") == null) { + if (extensionApi.get("OS-EXT-STS") == null) { Thread.sleep(30000); } blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); - Image backupImage = imageApi.getImage(backupImageId); + Image backupImage = imageApi.get(backupImageId); assertEquals(backupImage.getId(), backupImageId); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.java index f483ece6dc..3832a39f08 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.java @@ -50,7 +50,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_extra_specs.json")).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getAllExtraSpecs("9"), ImmutableMap.of("test", "value1")); + assertEquals(api.getMetadata("9"), ImmutableMap.of("test", "value1")); } public void testGetAllExtraSpecsFailNotFound() { @@ -62,7 +62,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.getAllExtraSpecs("9").isEmpty()); + assertTrue(api.getMetadata("9").isEmpty()); } public void testSetAllExtraSpecs() { @@ -76,7 +76,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.setAllExtraSpecs("9", ImmutableMap.of("test1", "somevalue"))); + assertTrue(api.updateMetadata("9", ImmutableMap.of("test1", "somevalue"))); } public void testSetExtraSpec() { @@ -90,7 +90,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.setExtraSpec("5", "test1", "somevalue")); + assertTrue(api.updateMetadataEntry("5", "test1", "somevalue")); } public void testGetExtraSpec() { @@ -102,7 +102,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"test1\":\"another value\"}", MediaType.APPLICATION_JSON)).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getExtraSpec("5", "test1"), "another value"); + assertEquals(api.getMetadataKey("5", "test1"), "another value"); } public void testGetExtraSpecFailNotFound() { @@ -114,7 +114,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getExtraSpec("5", "test1")); + assertNull(api.getMetadataKey("5", "test1")); } public void testDeleteExtraSpec() { @@ -126,7 +126,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.deleteExtraSpec("5", "test1")); + assertTrue(api.deleteMetadataKey("5", "test1")); } public void testDeleteExtraSpecFailNotFound() { @@ -138,7 +138,7 @@ public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.deleteExtraSpec("5", "test1")); + assertFalse(api.deleteMetadataKey("5", "test1")); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java index a666aafa45..fc2ec17238 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java @@ -64,7 +64,7 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest { public void tearDown() { if (apiOption.isPresent() && testFlavor != null) { for(String key : testSpecs.keySet()) { - assertTrue(apiOption.get().deleteExtraSpec(testFlavor.getId(), key)); + assertTrue(apiOption.get().deleteMetadataKey(testFlavor.getId(), key)); } } super.tearDown(); @@ -73,15 +73,15 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest { public void testCreateExtraSpecs() { if (apiOption.isPresent()) { FlavorExtraSpecsApi api = apiOption.get(); - testFlavor = Iterables.getLast(flavorApi.listFlavors()); - Map before = api.getAllExtraSpecs(testFlavor.getId()); + testFlavor = Iterables.getLast(flavorApi.list().concat()); + Map before = api.getMetadata(testFlavor.getId()); assertNotNull(before); Map specs = Maps.newHashMap(before); specs.putAll(testSpecs); - assertTrue(api.setAllExtraSpecs(testFlavor.getId(), specs)); - assertEquals(api.getAllExtraSpecs(testFlavor.getId()), specs); + assertTrue(api.updateMetadata(testFlavor.getId(), specs)); + assertEquals(api.getMetadata(testFlavor.getId()), specs); for (Map.Entry entry : specs.entrySet()) { - assertEquals(api.getExtraSpec(testFlavor.getId(), entry.getKey()), entry.getValue()); + assertEquals(api.getMetadataKey(testFlavor.getId(), entry.getKey()), entry.getValue()); } } } @@ -91,13 +91,13 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest { if (apiOption.isPresent()) { FlavorExtraSpecsApi api = apiOption.get(); for (String key : testSpecs.keySet()) { - assertTrue(api.getAllExtraSpecs(testFlavor.getId()).containsKey(key)); + assertTrue(api.getMetadata(testFlavor.getId()).containsKey(key)); } - for (Resource flavor : flavorApi.listFlavors()) { - Map specs = api.getAllExtraSpecs(flavor.getId()); + for (Resource flavor : flavorApi.list().concat()) { + Map specs = api.getMetadata(flavor.getId()); assertNotNull(specs); for (Map.Entry entry : specs.entrySet()) { - assertEquals(api.getExtraSpec(flavor.getId(), entry.getKey()), entry.getValue()); + assertEquals(api.getMetadataKey(flavor.getId(), entry.getKey()), entry.getValue()); } } } @@ -108,16 +108,16 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest { if (apiOption.isPresent()) { FlavorExtraSpecsApi api = apiOption.get(); for (String key : testSpecs.keySet()) { - assertTrue(api.setExtraSpec(testFlavor.getId(), key, "new value")); + assertTrue(api.updateMetadataEntry(testFlavor.getId(), key, "new value")); } for (String key : testSpecs.keySet()) { - assertEquals(api.getExtraSpec(testFlavor.getId(), key), "new value"); + assertEquals(api.getMetadataKey(testFlavor.getId(), key), "new value"); } - for (Resource flavor : flavorApi.listFlavors()) { - Map specs = api.getAllExtraSpecs(flavor.getId()); + for (Resource flavor : flavorApi.list().concat()) { + Map specs = api.getMetadata(flavor.getId()); assertNotNull(specs); for (Map.Entry entry : specs.entrySet()) { - assertEquals(api.getExtraSpec(flavor.getId(), entry.getKey()), entry.getValue()); + assertEquals(api.getMetadataKey(flavor.getId(), entry.getKey()), entry.getValue()); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java index af71ea1acf..3d85f11ce3 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java @@ -63,73 +63,73 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest { } public void testListFloatingIPsWhenResponseIs2xx() throws Exception { - HttpRequest listFloatingIPs = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/floatingip_list.json")).build(); NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); assertEquals(apiWhenFloatingIPsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs() + assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list() .toString(), new ParseFloatingIPListTest().expected().toString()); } public void testListFloatingIPsWhenResponseIs404() throws Exception { - HttpRequest listFloatingIPs = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); - assertTrue(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs().isEmpty()); + assertTrue(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list().isEmpty()); } public void testGetFloatingIPWhenResponseIs2xx() throws Exception { - HttpRequest getFloatingIP = HttpRequest + HttpRequest get = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips/1") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(200) + HttpResponse getResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/floatingip_details.json")).build(); NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse); - assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1") + assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1") .toString(), new ParseFloatingIPTest().expected().toString()); } public void testGetFloatingIPWhenResponseIs404() throws Exception { - HttpRequest getFloatingIP = HttpRequest + HttpRequest get = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips/1") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse); - assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1")); + assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1")); } public void testAllocateWhenResponseIs2xx() throws Exception { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java index a35aaabb9b..9f4e439d8a 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java @@ -52,11 +52,11 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { if (!apiOption.isPresent()) continue; FloatingIPApi api = apiOption.get(); - Set response = api.listFloatingIPs(); + Set response = api.list().toImmutableSet(); assert null != response; assertTrue(response.size() >= 0); for (FloatingIP ip : response) { - FloatingIP newDetails = api.getFloatingIP(ip.getId()); + FloatingIP newDetails = api.get(ip.getId()); assertEquals(newDetails.getId(), ip.getId()); assertEquals(newDetails.getIp(), ip.getIp()); @@ -77,7 +77,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { FloatingIP floatingIP = api.allocate(); assertNotNull(floatingIP); - Set response = api.listFloatingIPs(); + Set response = api.list().toImmutableSet(); boolean ipInSet = false; for (FloatingIP ip : response) { if (ip.getId().equals(floatingIP.getId())) @@ -87,7 +87,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { api.deallocate(floatingIP.getId()); - response = api.listFloatingIPs(); + response = api.list().toImmutableSet(); ipInSet = false; for (FloatingIP ip : response) { if (ip.getId().equals(floatingIP.getId())) { @@ -110,11 +110,11 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { FloatingIP floatingIP = api.allocate(); assertNotNull(floatingIP); try { - api.addFloatingIPToServer(floatingIP.getIp(), server.getId()); + api.addToServer(floatingIP.getIp(), server.getId()); assertEventually(new ServerHasFloatingIP(serverApi, server.getId(), floatingIP.getIp())); } finally { - api.removeFloatingIPFromServer(floatingIP.getIp(), server.getId()); - serverApi.deleteServer(server.getId()); + api.removeFromServer(floatingIP.getIp(), server.getId()); + serverApi.delete(server.getId()); } } } @@ -155,7 +155,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { public void run() { try { - Server server = api.getServer(serverId); + Server server = api.get(serverId); boolean ipInServerAddresses = false; Multimap addresses = server.getAddresses(); for (Address address : addresses.values()) { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java index 32f1506771..793ba42fe2 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java @@ -64,74 +64,74 @@ public class FloatingIPAsyncApiExpectTest extends BaseNovaAsyncApiExpectTest { } public void testListFloatingIPsWhenResponseIs2xx() throws Exception { - HttpRequest listFloatingIPs = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/floatingip_list.json")).build(); NovaAsyncApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); assertEquals(apiWhenFloatingIPsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs().get() + assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list().get() .toString(), new ParseFloatingIPListTest().expected().toString()); } public void testListFloatingIPsWhenResponseIs404() throws Exception { - HttpRequest listFloatingIPs = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); NovaAsyncApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); - assertTrue(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs().get() + assertTrue(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list().get() .isEmpty()); } public void testGetFloatingIPWhenResponseIs2xx() throws Exception { - HttpRequest getFloatingIP = HttpRequest + HttpRequest get = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips/1") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(200) + HttpResponse getResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/floatingip_details.json")).build(); NovaAsyncApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse); - assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1").get() + assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1").get() .toString(), new ParseFloatingIPTest().expected().toString()); } public void testGetFloatingIPWhenResponseIs404() throws Exception { - HttpRequest getFloatingIP = HttpRequest + HttpRequest get = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips/1") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); NovaAsyncApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse); - assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1").get()); + assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1").get()); } public void testAllocateWhenResponseIs2xx() throws Exception { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java index b824552ec8..f280603328 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java @@ -59,7 +59,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { Host expected = Host.builder().name("ubuntu").service("compute").build(); - Set result = api.listHosts(); + Set result = api.list().toImmutableSet(); Host host = Iterables.getOnlyElement(result); assertEquals(host.getName(), "ubuntu"); assertEquals(host.getService(), "compute"); @@ -84,7 +84,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HostResourceUsage.builder().memoryMb(6144).project("f8535069c3fb404cb61c873b1a0b4921").cpu(3).diskGb(80).host("ubuntu").build() ); - assertEquals(api.getHostResourceUsage("xyz"), expected); + assertEquals(api.listResourceUsage("xyz").toImmutableSet(), expected); } public void testEnableHost() { @@ -99,7 +99,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"enabled\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.enableHost("ubuntu")); + assertTrue(api.enable("ubuntu")); } @Test(expectedExceptions = ResourceNotFoundException.class) @@ -114,7 +114,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { .endpoint(endpoint).build(), HttpResponse.builder().statusCode(404) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - api.enableHost("ubuntu"); + api.enable("ubuntu"); } public void testEnableHostFailNotEnabled() { @@ -129,7 +129,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"disabled\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.enableHost("ubuntu")); + assertFalse(api.enable("ubuntu")); } public void testDisableHost() { @@ -144,7 +144,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"disabled\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.disableHost("ubuntu")); + assertTrue(api.disable("ubuntu")); } public void testStartMaintenance() { @@ -159,7 +159,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"maintenance_mode\":\"on_maintenance\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.startHostMaintenance("ubuntu")); + assertTrue(api.startMaintenance("ubuntu")); } public void testStopMaintenance() { @@ -174,7 +174,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"maintenance_mode\":\"off_maintenance\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.stopHostMaintenance("ubuntu")); + assertTrue(api.stopMaintenance("ubuntu")); } public void testStartupHost() { @@ -187,7 +187,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"startup\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.startupHost("ubuntu")); + assertTrue(api.startup("ubuntu")); } @Test(expectedExceptions = ResourceNotFoundException.class) @@ -199,7 +199,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(), HttpResponse.builder().statusCode(404).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.startupHost("ubuntu")); + assertTrue(api.startup("ubuntu")); } public void testStartupHostFailWrongActionInProgress() { @@ -212,7 +212,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"shutdown\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.startupHost("ubuntu")); + assertFalse(api.startup("ubuntu")); } public void testShutdownHost() { @@ -225,7 +225,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"shutdown\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.shutdownHost("ubuntu")); + assertTrue(api.shutdown("ubuntu")); } public void testRebootHost() { @@ -238,6 +238,6 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"reboot\"}", MediaType.APPLICATION_JSON)) .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.rebootHost("ubuntu")); + assertTrue(api.reboot("ubuntu")); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java index 20ce931b8e..d9f0fe8c4d 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java @@ -65,10 +65,10 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest { public void testListAndGet() throws Exception { if (optApi.isPresent()) { HostAdministrationApi api = optApi.get(); - Set hosts = api.listHosts(); + Set hosts = api.list().toImmutableSet(); assertNotNull(hosts); for (Host host : hosts) { - for (HostResourceUsage usage : api.getHostResourceUsage(host.getName())) { + for (HostResourceUsage usage : api.listResourceUsage(host.getName())) { assertEquals(usage.getHost(), host.getName()); assertNotNull(usage); } @@ -80,10 +80,10 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest { public void testEnableDisable() throws Exception { if (optApi.isPresent()) { HostAdministrationApi api = optApi.get(); - Host host = Iterables.find(api.listHosts(), isComputeHost); + Host host = Iterables.find(api.list(), isComputeHost); - assertTrue(api.disableHost(host.getName())); - assertTrue(api.enableHost(host.getName())); + assertTrue(api.disable(host.getName())); + assertTrue(api.enable(host.getName())); } } @@ -91,9 +91,9 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest { public void testMaintenanceMode() throws Exception { if (optApi.isPresent()) { HostAdministrationApi api = optApi.get(); - Host host = Iterables.find(api.listHosts(), isComputeHost); - assertTrue(api.startHostMaintenance(host.getName())); - assertTrue(api.stopHostMaintenance(host.getName())); + Host host = Iterables.find(api.list(), isComputeHost); + assertTrue(api.startMaintenance(host.getName())); + assertTrue(api.stopMaintenance(host.getName())); } } @@ -101,8 +101,8 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest { public void testReboot() throws Exception { if (optApi.isPresent()) { HostAdministrationApi api = optApi.get(); - Host host = Iterables.find(api.listHosts(), isComputeHost); - assertTrue(api.rebootHost(host.getName())); + Host host = Iterables.find(api.list(), isComputeHost); + assertTrue(api.reboot(host.getName())); } } @@ -110,9 +110,9 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest { public void testShutdownAndStartup() throws Exception { if (optApi.isPresent()) { HostAdministrationApi api = optApi.get(); - Host host = Iterables.find(api.listHosts(), isComputeHost); - assertTrue(api.shutdownHost(host.getName())); - assertTrue(api.startupHost(host.getName())); + Host host = Iterables.find(api.list(), isComputeHost); + assertTrue(api.shutdown(host.getName())); + assertTrue(api.startup(host.getName())); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java index 55997fb309..f84c934b1f 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java @@ -54,7 +54,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_list.json")).build()) .getHostAggregateExtensionForZone("az-1.region-a.geo-1").get(); - HostAggregate result = Iterables.getOnlyElement(api.listAggregates()); + HostAggregate result = Iterables.getOnlyElement(api.list()); assertEquals(result, exampleHostAggregate()); } @@ -66,7 +66,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_with_host_details.json")).build()) .getHostAggregateExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getAggregate("1"), exampleHostAggregateWithHost()); + assertEquals(api.get("1"), exampleHostAggregateWithHost()); } public void testGetFailNotFound() { @@ -76,7 +76,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getAggregate("1")); + assertNull(api.get("1")); } public void testCreateAggregate() { @@ -89,7 +89,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()) .getHostAggregateExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.createAggregate("ubuntu1", "nova"), exampleHostAggregate()); + assertEquals(api.createInAvailabilityZone("ubuntu1", "nova"), exampleHostAggregate()); } public void testDeleteAggregate() { @@ -99,7 +99,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(200).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.deleteAggregate("1")); + assertTrue(api.delete("1")); } public void testDeleteAggregateFailNotFound() { @@ -109,7 +109,7 @@ public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(404).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.deleteAggregate("1")); + assertFalse(api.delete("1")); } public void testUpdateName() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java index 566c2b3c53..847ad551c5 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java @@ -62,7 +62,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { @AfterGroups(groups = {"integration", "live"}) public void tearDown() { if (testAggregate != null) { - assertTrue(apiOption.get().deleteAggregate(testAggregate.getId())); + assertTrue(apiOption.get().delete(testAggregate.getId())); } super.tearDown(); } @@ -70,7 +70,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { public void testCreateAggregate() { if (apiOption.isPresent()) { // TODO assuming "nova" availability zone is present - testAggregate = apiOption.get().createAggregate("jclouds-test-a", "nova"); + testAggregate = apiOption.get().createInAvailabilityZone("jclouds-test-a", "nova"); } } @@ -78,13 +78,13 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { public void testListAndGetAggregate() { if (apiOption.isPresent()) { HostAggregateApi api = apiOption.get(); - Set aggregates = api.listAggregates(); + Set aggregates = api.list().toImmutableSet(); for (HostAggregate aggregate : aggregates) { assertNotNull(aggregate.getId()); assertNotNull(aggregate.getName()); assertNotNull(aggregate.getAvailabilityZone()); - HostAggregate details = api.getAggregate(aggregate.getId()); + HostAggregate details = api.get(aggregate.getId()); assertEquals(details.getId(), aggregate.getId()); assertEquals(details.getName(), aggregate.getName()); assertEquals(details.getAvailabilityZone(), aggregate.getAvailabilityZone()); @@ -110,7 +110,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { } // Re-fetch to double-check - details = api.getAggregate(testAggregate.getId()); + details = api.get(testAggregate.getId()); for (String key : theMetaData.keySet()) { assertEquals(details.getMetadata().get(key), theMetaData.get(key)); } @@ -123,7 +123,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { public void testModifyHosts() { if (apiOption.isPresent() && hostAdminOption.isPresent()) { HostAggregateApi api = apiOption.get(); - Host host = Iterables.getFirst(hostAdminOption.get().listHosts(), null); + Host host = Iterables.getFirst(hostAdminOption.get().list(), null); assertNotNull(host); String host_id = host.getName(); @@ -136,7 +136,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { assertEquals(details.getHosts(), ImmutableSet.of(host_id)); // re-fetch to double-check - details = api.getAggregate(testAggregate.getId()); + details = api.get(testAggregate.getId()); assertEquals(details.getHosts(), ImmutableSet.of(host_id)); // TODO wait until status of aggregate isn't CHANGING (hostAdministration.shutdown?) diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java index 5f215c3b50..74004a4096 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java @@ -40,45 +40,45 @@ import com.google.common.collect.ImmutableSet; public class KeyPairApiExpectTest extends BaseNovaApiExpectTest { public void testListKeyPairsWhenResponseIs2xx() throws Exception { - HttpRequest listKeyPairs = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/keypair_list.json")).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listKeyPairs, listKeyPairsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); // NOTE this required a change to the KeyPair domain object toString method - assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().listKeyPairs().toString(), + assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().list().toString(), new ParseKeyPairListTest().expected().toString()); } public void testListKeyPairsWhenResponseIs404() throws Exception { - HttpRequest listKeyPairs = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listKeyPairs, listKeyPairsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); - assertTrue(apiWhenNoServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().listKeyPairs().isEmpty()); + assertTrue(apiWhenNoServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().list().isEmpty()); } public void testCreateKeyPair() throws Exception { - HttpRequest createKeyPair = HttpRequest + HttpRequest create = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs") @@ -87,19 +87,19 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest { .payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\"}}", "application/json")) .build(); - HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200) + HttpResponse createResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/keypair_created.json")).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createKeyPair, createKeyPairResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, create, createResponse); - assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().createKeyPair("testkeypair") + assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().create("testkeypair") .toString(), new ParseKeyPairTest().expected().toString()); } public void testCreateKeyPairWithPublicKey() throws Exception { - HttpRequest createKeyPair = HttpRequest + HttpRequest create = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs") @@ -110,35 +110,35 @@ public class KeyPairApiExpectTest extends BaseNovaApiExpectTest { "{\"keypair\":{\"name\":\"testkeypair\",\"public_key\":\"ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n\"}}", "application/json")).build(); - HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200) + HttpResponse createResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/keypair_created.json")).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createKeyPair, createKeyPairResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, create, createResponse); assertEquals( apiWhenServersExist .getKeyPairExtensionForZone("az-1.region-a.geo-1") .get() - .createKeyPairWithPublicKey( + .createWithPublicKey( "testkeypair", "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n") .toString(), new ParseKeyPairTest().expected().toString()); } public void testDeleteKeyPair() throws Exception { - HttpRequest deleteKeyPair = HttpRequest + HttpRequest delete = HttpRequest .builder() .method("DELETE") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs/testkeypair") .addHeader("Accept", "*/*") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse deleteKeyPairResponse = HttpResponse.builder().statusCode(202).build(); + HttpResponse deleteResponse = HttpResponse.builder().statusCode(202).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteKeyPair, deleteKeyPairResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete, deleteResponse); - assertTrue(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().deleteKeyPair("testkeypair")); + assertTrue(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().delete("testkeypair")); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java index e8f2837970..4bb91ef873 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java @@ -20,13 +20,12 @@ package org.jclouds.openstack.nova.v2_0.extensions; import static org.testng.Assert.assertNotNull; -import java.util.Map; -import java.util.Set; - import org.jclouds.openstack.nova.v2_0.domain.KeyPair; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; + /** * Tests behavior of {@code KeyPairApi} * @@ -38,7 +37,7 @@ public class KeyPairApiLiveTest extends BaseNovaApiLiveTest { public void testListKeyPairs() throws Exception { for (String zoneId : novaContext.getApi().getConfiguredZones()) { KeyPairApi api = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get(); - Set> keyPairsList = api.listKeyPairs(); + FluentIterable keyPairsList = api.list(); assertNotNull(keyPairsList); } } @@ -49,11 +48,11 @@ public class KeyPairApiLiveTest extends BaseNovaApiLiveTest { KeyPairApi api = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get(); KeyPair keyPair = null; try { - keyPair = api.createKeyPair(KEYPAIR_NAME); + keyPair = api.create(KEYPAIR_NAME); assertNotNull(keyPair); } finally { if (keyPair != null) { - api.deleteKeyPair(KEYPAIR_NAME); + api.delete(KEYPAIR_NAME); } } } @@ -67,11 +66,11 @@ public class KeyPairApiLiveTest extends BaseNovaApiLiveTest { KeyPairApi api = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get(); KeyPair keyPair = null; try { - keyPair = api.createKeyPairWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY); + keyPair = api.createWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY); assertNotNull(keyPair); } finally { if (keyPair != null) { - api.deleteKeyPair(KEYPAIR_NAME); + api.delete(KEYPAIR_NAME); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java index b3e31ae09a..b28a35f606 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java @@ -28,7 +28,7 @@ import javax.ws.rs.core.MediaType; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.nova.v2_0.domain.Quotas; +import org.jclouds.openstack.nova.v2_0.domain.Quota; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; @@ -48,7 +48,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getQuotasForTenant("demo"), getTestQuotas()); + assertEquals(api.getByTenant("demo"), getTestQuotas()); } public void testGetQuotasFailsTenantNotFound() throws Exception { @@ -57,7 +57,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getQuotasForTenant("demo")); + assertNull(api.getByTenant("demo")); } public void testGetDefaultQuotas() throws Exception { @@ -67,7 +67,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getDefaultQuotasForTenant("demo"), getTestQuotas()); + assertEquals(api.getDefaultsForTenant("demo"), getTestQuotas()); } public void testGetDefaultQuotasFailsTenantNotFound() throws Exception { @@ -76,7 +76,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getDefaultQuotasForTenant("demo")); + assertNull(api.getDefaultsForTenant("demo")); } @@ -90,7 +90,7 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest { .build(), HttpResponse.builder().statusCode(200).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.updateQuotasForTenant("demo", getTestQuotas())); + assertTrue(api.updateQuotaOfTenant(getTestQuotas(), "demo")); } @Test(expectedExceptions = ResourceNotFoundException.class) @@ -104,11 +104,11 @@ public class QuotaApiExpectTest extends BaseNovaApiExpectTest { .build(), HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get(); - api.updateQuotasForTenant("demo", getTestQuotas()); + api.updateQuotaOfTenant(getTestQuotas(), "demo"); } - public static Quotas getTestQuotas() { - return Quotas.builder() + public static Quota getTestQuotas() { + return Quota.builder() .metadataItems(128) .injectedFileContentBytes(10240) .injectedFiles(5) diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java index efd88d750d..ec771e4a52 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java @@ -21,7 +21,7 @@ package org.jclouds.openstack.nova.v2_0.extensions; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import org.jclouds.openstack.nova.v2_0.domain.Quotas; +import org.jclouds.openstack.nova.v2_0.domain.Quota; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -50,14 +50,14 @@ public class QuotaApiLiveTest extends BaseNovaApiLiveTest { public void testGetQuotasForCurrentTenant() { if (apiOption.isPresent()) { - Quotas quota = apiOption.get().getQuotasForTenant(tenant); + Quota quota = apiOption.get().getByTenant(tenant); assertQuotasIsValid(quota); } } public void testGetDefaultQuotasForCurrentTenant() { if (apiOption.isPresent()) { - Quotas quota = apiOption.get().getDefaultQuotasForTenant(tenant); + Quota quota = apiOption.get().getDefaultsForTenant(tenant); assertQuotasIsValid(quota); } } @@ -65,10 +65,10 @@ public class QuotaApiLiveTest extends BaseNovaApiLiveTest { public void testUpdateQuotasOfCurrentTenantThenReset() { if (apiOption.isPresent()) { QuotaApi api = apiOption.get(); - Quotas before = api.getQuotasForTenant(tenant); + Quota before = api.getByTenant(tenant); assertQuotasIsValid(before); - Quotas modified = before.toBuilder() + Quota modified = before.toBuilder() .cores(before.getCores() - 1) .instances(before.getInstances() - 1) .metadataItems(before.getMetadataItems() - 1) @@ -76,17 +76,17 @@ public class QuotaApiLiveTest extends BaseNovaApiLiveTest { .volumes(before.getVolumes() - 1) .build(); - assertTrue(api.updateQuotasForTenant(tenant, modified)); + assertTrue(api.updateQuotaOfTenant(modified, tenant)); - assertEquals(api.getQuotasForTenant(tenant), modified); + assertEquals(api.getByTenant(tenant), modified); - assertTrue(api.updateQuotasForTenant(tenant, before)); + assertTrue(api.updateQuotaOfTenant(before, tenant)); - assertEquals(api.getQuotasForTenant(tenant), before); + assertEquals(api.getByTenant(tenant), before); } } - protected void assertQuotasIsValid(Quotas quota) { + protected void assertQuotasIsValid(Quota quota) { assertTrue(quota.getCores() > 0); assertTrue(quota.getFloatingIps() >= 0); assertTrue(quota.getGigabytes() > 0); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiExpectTest.java index 0a8ca1a5f6..612c73f8f2 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiExpectTest.java @@ -48,7 +48,7 @@ public class QuotaClassApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quota_class.json")).build()).getQuotaClassExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getQuotaClass("jcloudstestquotas"), getTestQuotas()); + assertEquals(api.get("jcloudstestquotas"), getTestQuotas()); } public void testGetQuotasFailsTenantNotFound() throws Exception { @@ -57,7 +57,7 @@ public class QuotaClassApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()).getQuotaClassExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getQuotaClass("jcloudstestquotas")); + assertNull(api.get("jcloudstestquotas")); } public void testUpdateQuotas() throws Exception { @@ -70,7 +70,7 @@ public class QuotaClassApiExpectTest extends BaseNovaApiExpectTest { .build(), HttpResponse.builder().statusCode(200).build()).getQuotaClassExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.updateQuotaClass("myclass", getTestQuotas())); + assertTrue(api.update("myclass", getTestQuotas())); } @Test(expectedExceptions = ResourceNotFoundException.class) @@ -84,7 +84,7 @@ public class QuotaClassApiExpectTest extends BaseNovaApiExpectTest { .build(), HttpResponse.builder().statusCode(404).build()).getQuotaClassExtensionForZone("az-1.region-a.geo-1").get(); - api.updateQuotaClass("jcloudstestquotas", getTestQuotas()); + api.update("jcloudstestquotas", getTestQuotas()); } public static QuotaClass getTestQuotas() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiLiveTest.java index d5b80da512..dd79198298 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaClassApiLiveTest.java @@ -60,16 +60,16 @@ public class QuotaClassApiLiveTest extends BaseNovaApiLiveTest { .volumes(5) .build(); - assertTrue(api.updateQuotaClass(firstVersion.getId(), firstVersion)); + assertTrue(api.update(firstVersion.getId(), firstVersion)); - assertEquals(api.getQuotaClass(firstVersion.getId()), firstVersion); + assertEquals(api.get(firstVersion.getId()), firstVersion); // Change it again (since we may have run this test before and we can't delete the QuotaClass) QuotaClass secondVersion = firstVersion.toBuilder().ram(8192).build(); - assertTrue(api.updateQuotaClass(secondVersion.getId(), secondVersion)); + assertTrue(api.update(secondVersion.getId(), secondVersion)); - assertEquals(api.getQuotaClass(secondVersion.getId()), secondVersion); + assertEquals(api.get(secondVersion.getId()), secondVersion); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiExpectTest.java index cf978e2f31..b76249cc92 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiExpectTest.java @@ -47,22 +47,22 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit", testName = "SecurityGroupApiExpectTest") public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { public void testListSecurityGroupsWhenResponseIs2xx() throws Exception { - HttpRequest listSecurityGroups = HttpRequest.builder().method("GET").endpoint( + HttpRequest list = HttpRequest.builder().method("GET").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).build(); - HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse listResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygroup_list.json")).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listSecurityGroups, - listSecurityGroupsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, + listResponse); assertEquals(apiWhenSecurityGroupsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); assertEquals(apiWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .listSecurityGroups().toString(), new ParseSecurityGroupListTest().expected().toString()); + .list().toString(), new ParseSecurityGroupListTest().expected().toString()); } public void testListSecurityGroupsWhenReponseIs404IsEmpty() throws Exception { @@ -78,7 +78,7 @@ public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { listListSecurityGroupsResponse); assertTrue(apiWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .listSecurityGroups().isEmpty()); + .list().isEmpty()); } public void testGetSecurityGroupWhenResponseIs2xx() throws Exception { @@ -96,7 +96,7 @@ public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { getSecurityGroupResponse); assertEquals(apiWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .getSecurityGroup("0").toString(), new ParseSecurityGroupTest().expected().toString()); + .get("0").toString(), new ParseSecurityGroupTest().expected().toString()); } public void testGetSecurityGroupWhenResponseIs404() throws Exception { @@ -112,12 +112,12 @@ public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { getSecurityGroupResponse); assertNull(apiWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .getSecurityGroup("0")); + .get("0")); } public void testCreateSecurityGroupWhenResponseIs2xx() throws Exception { - HttpRequest createSecurityGroup = HttpRequest.builder().method("POST").endpoint( + HttpRequest create = HttpRequest.builder().method("POST").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()) @@ -126,38 +126,38 @@ public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { "{\"security_group\":{\"name\":\"jclouds-test\",\"description\":\"jclouds-test\"}}", "application/json")).build(); - HttpResponse createSecurityGroupResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse createResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygroup_created.json")).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createSecurityGroup, - createSecurityGroupResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, create, + createResponse); assertEquals(apiWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .createSecurityGroupWithNameAndDescription("jclouds-test", "jclouds-test").toString(), - createSecurityGroupExpected().toString()); + .createWithDescription("jclouds-test", "jclouds-test").toString(), + createExpected().toString()); } public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception { - HttpRequest deleteSecurityGroup = HttpRequest.builder().method("DELETE").endpoint( + HttpRequest delete = HttpRequest.builder().method("DELETE").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups/160")) .headers( ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); - HttpResponse deleteSecurityGroupResponse = HttpResponse.builder().statusCode(202).build(); + HttpResponse deleteResponse = HttpResponse.builder().statusCode(202).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteSecurityGroup, - deleteSecurityGroupResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete, + deleteResponse); assertTrue(apiWhenServersExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .deleteSecurityGroup("160")); + .delete("160")); } public void testCreateSecurityGroupRuleForCidrBlockWhenResponseIs2xx() throws Exception { - HttpRequest createSecurityGroupRule = HttpRequest + HttpRequest createRule = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-group-rules") @@ -168,21 +168,21 @@ public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { "{\"security_group_rule\":{\"parent_group_id\":\"161\",\"cidr\":\"0.0.0.0/0\",\"ip_protocol\":\"tcp\",\"from_port\":\"80\",\"to_port\":\"8080\"}}", "application/json")).build(); - HttpResponse createSecurityGroupRuleResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse createRuleResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygrouprule_created.json")).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createSecurityGroupRule, - createSecurityGroupRuleResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createRule, + createRuleResponse); assertEquals(apiWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .createSecurityGroupRuleAllowingCidrBlock("161", + .createRuleAllowingCidrBlock("161", Ingress.builder().ipProtocol(IpProtocol.TCP).fromPort(80).toPort(8080).build(), "0.0.0.0/0") - .toString(), createSecurityGroupRuleExpected().toString()); + .toString(), createRuleExpected().toString()); } public void testCreateSecurityGroupRuleForSecurityGroupIdWhenResponseIs2xx() throws Exception { - HttpRequest createSecurityGroupRule = HttpRequest + HttpRequest createRule = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-group-rules") @@ -193,43 +193,43 @@ public class SecurityGroupApiExpectTest extends BaseNovaApiExpectTest { "{\"security_group_rule\":{\"group_id\":\"999\",\"parent_group_id\":\"161\",\"ip_protocol\":\"tcp\",\"from_port\":\"80\",\"to_port\":\"8080\"}}", "application/json")).build(); - HttpResponse createSecurityGroupRuleResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse createRuleResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygrouprule_created.json")).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createSecurityGroupRule, - createSecurityGroupRuleResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createRule, + createRuleResponse); assertEquals(apiWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .createSecurityGroupRuleAllowingSecurityGroupId("161", + .createRuleAllowingSecurityGroupId("161", Ingress.builder().ipProtocol(IpProtocol.TCP).fromPort(80).toPort(8080).build(), "999") - .toString(), createSecurityGroupRuleExpected().toString()); + .toString(), createRuleExpected().toString()); } public void testDeleteSecurityGroupRuleWhenResponseIs2xx() throws Exception { - HttpRequest deleteSecurityGroupRule = HttpRequest.builder().method("DELETE").endpoint( + HttpRequest deleteRule = HttpRequest.builder().method("DELETE").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-group-rules/161")) .headers( ImmutableMultimap. builder().put("Accept", "*/*") .put("X-Auth-Token", authToken).build()).build(); - HttpResponse deleteSecurityGroupRuleResponse = HttpResponse.builder().statusCode(202).build(); + HttpResponse deleteRuleResponse = HttpResponse.builder().statusCode(202).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteSecurityGroupRule, - deleteSecurityGroupRuleResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteRule, + deleteRuleResponse); assertTrue(apiWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() - .deleteSecurityGroupRule("161")); + .deleteRule("161")); } - private SecurityGroup createSecurityGroupExpected() { + private SecurityGroup createExpected() { return SecurityGroup.builder().description("jclouds-test").id("160").name("jclouds-test").rules( ImmutableSet. of()).tenantId("dev_16767499955063").build(); } - private SecurityGroupRule createSecurityGroupRuleExpected() { + private SecurityGroupRule createRuleExpected() { return SecurityGroupRule.builder().fromPort(80).id("218").ipProtocol( IpProtocol.TCP).ipRange("0.0.0.0/0").parentGroupId("161").toPort(8080).build(); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiLiveTest.java index e6a5a57ce8..b3555bcf06 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SecurityGroupApiLiveTest.java @@ -41,10 +41,10 @@ public class SecurityGroupApiLiveTest extends BaseNovaApiLiveTest { public static final String SECURITY_GROUP_NAME = "testsg"; - public void listSecurityGroups() throws Exception { + public void list() throws Exception { for (String zoneId : novaContext.getApi().getConfiguredZones()) { SecurityGroupApi api = novaContext.getApi().getSecurityGroupExtensionForZone(zoneId).get(); - Set securityGroupsList = api.listSecurityGroups(); + Set securityGroupsList = api.list().toImmutableSet(); assertNotNull(securityGroupsList); } } @@ -56,14 +56,14 @@ public class SecurityGroupApiLiveTest extends BaseNovaApiLiveTest { String id; try { securityGroup = api - .createSecurityGroupWithNameAndDescription(SECURITY_GROUP_NAME, "test security group"); + .createWithDescription(SECURITY_GROUP_NAME, "test security group"); assertNotNull(securityGroup); id = securityGroup.getId(); - SecurityGroup theGroup = api.getSecurityGroup(id); + SecurityGroup theGroup = api.get(id); assertNotNull(theGroup); } finally { if (securityGroup != null) { - api.deleteSecurityGroup(securityGroup.getId()); + api.delete(securityGroup.getId()); } } } @@ -75,25 +75,25 @@ public class SecurityGroupApiLiveTest extends BaseNovaApiLiveTest { SecurityGroup securityGroup = null; try { - securityGroup = api.createSecurityGroupWithNameAndDescription(SECURITY_GROUP_NAME, "test security group"); + securityGroup = api.createWithDescription(SECURITY_GROUP_NAME, "test security group"); assertNotNull(securityGroup); for (int port : ImmutableSet.of(22, 8080)) { - SecurityGroupRule rule = api.createSecurityGroupRuleAllowingCidrBlock(securityGroup.getId(), Ingress + SecurityGroupRule rule = api.createRuleAllowingCidrBlock(securityGroup.getId(), Ingress .builder().ipProtocol(IpProtocol.TCP).fromPort(port).toPort(port).build(), "0.0.0.0/0"); assertNotNull(rule); - SecurityGroupRule rule2 = api.createSecurityGroupRuleAllowingSecurityGroupId(securityGroup.getId(), + SecurityGroupRule rule2 = api.createRuleAllowingSecurityGroupId(securityGroup.getId(), Ingress.builder().ipProtocol(IpProtocol.TCP).fromPort(port).toPort(port).build(), securityGroup .getId()); assertNotNull(rule2); } - securityGroup = api.getSecurityGroup(securityGroup.getId()); + securityGroup = api.get(securityGroup.getId()); } finally { if (securityGroup != null) { - api.deleteSecurityGroup(securityGroup.getId()); + api.delete(securityGroup.getId()); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiExpectTest.java index 8c06d5bdd2..e9551c0981 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiExpectTest.java @@ -47,7 +47,7 @@ public class ServerWithSecurityGroupsApiExpectTest extends BaseNovaApiExpectTest HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_with_security_groups.json")).build() ).getServerWithSecurityGroupsExtensionForZone("az-1.region-a.geo-1").get(); - ServerWithSecurityGroups server = api.getServer("8d0a6ca5-8849-4b3d-b86e-f24c92490ebb"); + ServerWithSecurityGroups server = api.get("8d0a6ca5-8849-4b3d-b86e-f24c92490ebb"); assertEquals(server.getId(), "8d0a6ca5-8849-4b3d-b86e-f24c92490ebb"); assertEquals(server.getSecurityGroupNames(), ImmutableSet.of("default", "group1")); } @@ -60,6 +60,6 @@ public class ServerWithSecurityGroupsApiExpectTest extends BaseNovaApiExpectTest authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build() ).getServerWithSecurityGroupsExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getServer("8d0a6ca5-8849-4b3d-b86e-f24c92490ebb")); + assertNull(api.get("8d0a6ca5-8849-4b3d-b86e-f24c92490ebb")); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiLiveTest.java index 533ac32432..4254a1d147 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ServerWithSecurityGroupsApiLiveTest.java @@ -56,8 +56,8 @@ public class ServerWithSecurityGroupsApiLiveTest extends BaseNovaApiLiveTest { public void testGetServer() { if (apiOption.isPresent()) { - for (Resource server : serverApi.listServers()) { - ServerWithSecurityGroups serverWithGroups = apiOption.get().getServer(server.getId()); + for (Resource server : serverApi.list().concat()) { + ServerWithSecurityGroups serverWithGroups = apiOption.get().get(server.getId()); assertEquals(serverWithGroups.getId(), server.getId()); assertEquals(serverWithGroups.getName(), server.getName()); assertNotNull(serverWithGroups.getSecurityGroupNames()); @@ -68,12 +68,12 @@ public class ServerWithSecurityGroupsApiLiveTest extends BaseNovaApiLiveTest { try { testServer = createServerInZone(zone); - ServerWithSecurityGroups results = apiOption.get().getServer(testServer.getId()); + ServerWithSecurityGroups results = apiOption.get().get(testServer.getId()); assertEquals(results.getId(), testServer.getId()); assertEquals(results.getSecurityGroupNames(), ImmutableSet.of("default")); } finally { if (testServer != null) { - serverApi.deleteServer(testServer.getId()); + serverApi.delete(testServer.getId()); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiExpectTest.java index e158655dd2..d99e66bb6f 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiExpectTest.java @@ -58,7 +58,7 @@ public class SimpleTenantUsageApiExpectTest extends BaseNovaApiExpectTest { .payload(payloadFromResource("/simple_tenant_usages.json")).build()) .getSimpleTenantUsageExtensionForZone("az-1.region-a.geo-1").get(); - Set results = api.listTenantUsages(); + Set results = api.list().toImmutableSet(); SimpleTenantUsage usage = Iterables.getOnlyElement(results); assertEquals(usage.getTenantId(), "f8535069c3fb404cb61c873b1a0b4921"); @@ -84,7 +84,7 @@ public class SimpleTenantUsageApiExpectTest extends BaseNovaApiExpectTest { .payload(payloadFromResource("/simple_tenant_usage.json")).build()) .getSimpleTenantUsageExtensionForZone("az-1.region-a.geo-1").get(); - SimpleTenantUsage usage = api.getTenantUsage("test-1234"); + SimpleTenantUsage usage = api.get("test-1234"); assertEquals(usage.getTenantId(), "f8535069c3fb404cb61c873b1a0b4921"); SimpleTenantUsage expected = SimpleTenantUsage.builder().tenantId("f8535069c3fb404cb61c873b1a0b4921").totalHours(4.833333333333333E-7).totalLocalGbUsage(1.933333333333333E-05) diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiLiveTest.java index 4fe7a30b36..887481a56f 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageApiLiveTest.java @@ -41,10 +41,10 @@ public class SimpleTenantUsageApiLiveTest extends BaseNovaApiLiveTest { Optional optApi = novaContext.getApi().getSimpleTenantUsageExtensionForZone(zoneId); if (optApi.isPresent() && identity.endsWith(":admin")) { SimpleTenantUsageApi api = optApi.get(); - Set usages = api.listTenantUsages(); + Set usages = api.list().toImmutableSet(); assertNotNull(usages); for (SimpleTenantUsage usage : usages) { - SimpleTenantUsage details = api.getTenantUsage(usage.getTenantId()); + SimpleTenantUsage details = api.get(usage.getTenantId()); assertNotNull(details); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java index be03ed603a..b3dfefe215 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java @@ -47,7 +47,7 @@ public class VirtualInterfaceApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/virtual_interfaces_list.json")).build() ).getVirtualInterfaceExtensionForZone("az-1.region-a.geo-1").get(); - VirtualInterface vif = Iterables.getOnlyElement(api.listVirtualInterfacesForServer("1")); + VirtualInterface vif = Iterables.getOnlyElement(api.listOnServer("1")); assertEquals(vif.getId(), "02315827-b05c-4668-9c05-75c68838074a"); assertEquals(vif.getMacAddress(), "fa:16:3e:09:71:34"); } @@ -61,6 +61,6 @@ public class VirtualInterfaceApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVirtualInterfaceExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.listVirtualInterfacesForServer("1").isEmpty()); + assertTrue(api.listOnServer("1").isEmpty()); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java index f409ea1181..8047bcae93 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java @@ -55,14 +55,14 @@ public class VirtualInterfaceApiLiveTest extends BaseNovaApiLiveTest { Server testServer = null; try { testServer = createServerInZone(zone); - Set results = apiOption.get().listVirtualInterfacesForServer(testServer.getId()); + Set results = apiOption.get().listOnServer(testServer.getId()).toImmutableSet(); for (VirtualInterface vif : results) { assertNotNull(vif.getId()); assertNotNull(vif.getMacAddress()); } } finally { if (testServer != null) { - novaContext.getApi().getServerApiForZone(zone).deleteServer(testServer.getId()); + novaContext.getApi().getServerApiForZone(zone).delete(testServer.getId()); } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java index 80bde501e3..25b036a4da 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java @@ -62,7 +62,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set volumes = api.listVolumes(); + Set volumes = api.list().toImmutableSet(); assertEquals(volumes, ImmutableSet.of(testVolume())); } @@ -75,7 +75,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set volumes = api.listVolumes(); + Set volumes = api.list().toImmutableSet(); assertTrue(volumes.isEmpty()); } @@ -88,7 +88,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list_detail.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set volumes = api.listVolumesInDetail(); + Set volumes = api.listInDetail().toImmutableSet(); assertEquals(volumes, ImmutableSet.of(testVolume())); } @@ -101,7 +101,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set volumes = api.listVolumesInDetail(); + Set volumes = api.listInDetail().toImmutableSet(); assertTrue(volumes.isEmpty()); } @@ -117,7 +117,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_details.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Volume volume = api.createVolume(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume")); + Volume volume = api.create(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume")); assertEquals(volume, testVolume()); } @@ -135,7 +135,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).payload(payloadFromResource("/volume_details.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - api.createVolume(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume")); + api.create(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume")); } public void testGetVolume() { @@ -147,7 +147,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_details.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Volume volume = api.getVolume("1"); + Volume volume = api.get("1"); assertEquals(volume, testVolume()); // double-check equals() assertEquals(volume.getStatus(), Volume.Status.IN_USE); @@ -167,7 +167,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getVolume("1")); + assertNull(api.get("1")); } public void testDeleteVolume() { @@ -179,7 +179,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.deleteVolume("1")); + assertTrue(api.delete("1")); } public void testDeleteVolumeFail() { @@ -191,7 +191,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.deleteVolume("1")); + assertFalse(api.delete("1")); } public void testListAttachments() { @@ -203,7 +203,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set attachments = api.listAttachmentsOnServer("instance-1"); + Set attachments = api.listAttachmentsOnServer("instance-1").toImmutableSet(); assertEquals(attachments, ImmutableSet.of(testAttachment())); // double-check individual fields VolumeAttachment attachment = Iterables.getOnlyElement(attachments); @@ -312,7 +312,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set snapshots = api.listSnapshots(); + Set snapshots = api.listSnapshots().toImmutableSet(); assertEquals(snapshots, ImmutableSet.of(testSnapshot())); } @@ -325,7 +325,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set snapshots = api.listSnapshots(); + Set snapshots = api.listSnapshots().toImmutableSet(); assertTrue(snapshots.isEmpty()); } @@ -363,7 +363,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list_detail.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set snapshots = api.listSnapshotsInDetail(); + Set snapshots = api.listSnapshotsInDetail().toImmutableSet(); assertEquals(snapshots, ImmutableSet.of(testSnapshot())); // double-check individual fields @@ -385,7 +385,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); - Set snapshots = api.listSnapshotsInDetail(); + Set snapshots = api.listSnapshotsInDetail().toImmutableSet(); assertTrue(snapshots.isEmpty()); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java index fe10147f79..0d9363cfb5 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java @@ -78,11 +78,11 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { } if (testVolume != null) { final String volumeId = testVolume.getId(); - assertTrue(volumeOption.get().deleteVolume(volumeId)); + assertTrue(volumeOption.get().delete(volumeId)); assertTrue(new RetryablePredicate(new Predicate() { @Override public boolean apply(VolumeApi volumeApi) { - return volumeOption.get().getVolume(volumeId) == null; + return volumeOption.get().get(volumeId) == null; } }, 180 * 1000L).apply(volumeOption.get())); } @@ -92,14 +92,14 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { public void testCreateVolume() { if (volumeOption.isPresent()) { - testVolume = volumeOption.get().createVolume( + testVolume = volumeOption.get().create( 1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume") .availabilityZone(zone)); assertTrue(new RetryablePredicate(new Predicate() { @Override public boolean apply(VolumeApi volumeApi) { - return volumeOption.get().getVolume(testVolume.getId()).getStatus() == Volume.Status.AVAILABLE; + return volumeOption.get().get(testVolume.getId()).getStatus() == Volume.Status.AVAILABLE; } }, 180 * 1000L).apply(volumeOption.get())); } @@ -108,28 +108,28 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { @Test(dependsOnMethods = "testCreateVolume") public void testListVolumes() { if (volumeOption.isPresent()) { - Set volumes = volumeOption.get().listVolumes(); + Set volumes = volumeOption.get().list().toImmutableSet(); assertNotNull(volumes); boolean foundIt = false; for (Volume vol : volumes) { - Volume details = volumeOption.get().getVolume(vol.getId()); + Volume details = volumeOption.get().get(vol.getId()); assertNotNull(details); if (Objects.equal(details.getId(), testVolume.getId())) { foundIt = true; } } - assertTrue(foundIt, "Failed to find the volume we created in listVolumes() response"); + assertTrue(foundIt, "Failed to find the volume we created in list() response"); } } @Test(dependsOnMethods = "testCreateVolume") public void testListVolumesInDetail() { if (volumeOption.isPresent()) { - Set volumes = volumeOption.get().listVolumesInDetail(); + Set volumes = volumeOption.get().listInDetail().toImmutableSet(); assertNotNull(volumes); boolean foundIt = false; for (Volume vol : volumes) { - Volume details = volumeOption.get().getVolume(vol.getId()); + Volume details = volumeOption.get().get(vol.getId()); assertNotNull(details); assertNotNull(details.getId()); assertNotNull(details.getCreated()); @@ -144,7 +144,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { foundIt = true; } } - assertTrue(foundIt, "Failed to find the volume we previously created in listVolumesInDetail() response"); + assertTrue(foundIt, "Failed to find the volume we previously created in listInDetail() response"); } } @@ -174,7 +174,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { @Test(dependsOnMethods = "testCreateSnapshot") public void testListSnapshots() { if (volumeOption.isPresent()) { - Set snapshots = volumeOption.get().listSnapshots(); + Set snapshots = volumeOption.get().listSnapshots().toImmutableSet(); assertNotNull(snapshots); boolean foundIt = false; for (VolumeSnapshot snap : snapshots) { @@ -193,7 +193,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { @Test(dependsOnMethods = "testCreateSnapshot") public void testListSnapshotsInDetail() { if (volumeOption.isPresent()) { - Set snapshots = volumeOption.get().listSnapshotsInDetail(); + Set snapshots = volumeOption.get().listSnapshotsInDetail().toImmutableSet(); assertNotNull(snapshots); boolean foundIt = false; for (VolumeSnapshot snap : snapshots) { @@ -225,7 +225,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { try { final String serverId = server_id = createServerInZone(zone).getId(); - Set attachments = volumeOption.get().listAttachmentsOnServer(serverId); + Set attachments = volumeOption.get().listAttachmentsOnServer(serverId).toImmutableSet(); assertNotNull(attachments); final int before = attachments.size(); @@ -241,11 +241,11 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { } }, 60 * 1000L).apply(volumeOption.get())); - attachments = volumeOption.get().listAttachmentsOnServer(serverId); + attachments = volumeOption.get().listAttachmentsOnServer(serverId).toImmutableSet(); assertNotNull(attachments); assertEquals(attachments.size(), before + 1); - assertEquals(volumeOption.get().getVolume(testVolume.getId()).getStatus(), Volume.Status.IN_USE); + assertEquals(volumeOption.get().get(testVolume.getId()).getStatus(), Volume.Status.IN_USE); boolean foundIt = false; for (VolumeAttachment att : attachments) { @@ -274,7 +274,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { } finally { if (server_id != null) - novaContext.getApi().getServerApiForZone(zone).deleteServer(server_id); + novaContext.getApi().getServerApiForZone(zone).delete(server_id); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java index a62308adac..24574ef46a 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java @@ -57,7 +57,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_list.json")).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - Set types = api.listVolumeTypes(); + Set types = api.list().toImmutableSet(); assertEquals(types, ImmutableSet.of(testVolumeType())); } @@ -70,7 +70,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - VolumeType type = api.getVolumeType("8"); + VolumeType type = api.get("8"); assertEquals(type, testVolumeType()); } @@ -83,7 +83,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertNull(api.getVolumeType("8")); + assertNull(api.get("8")); } public void testCreateVolumeType() { @@ -97,7 +97,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - VolumeType type = api.createVolumeType("jclouds-test-1"); + VolumeType type = api.create("jclouds-test-1"); assertEquals(type, testVolumeType()); } @@ -112,7 +112,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - VolumeType type = api.createVolumeType("jclouds-test-1", CreateVolumeTypeOptions.NONE); + VolumeType type = api.create("jclouds-test-1", CreateVolumeTypeOptions.NONE); assertEquals(type, testVolumeType()); } @@ -127,7 +127,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - VolumeType type = api.createVolumeType("jclouds-test-1", CreateVolumeTypeOptions.Builder.specs(ImmutableMap.of("x", "y"))); + VolumeType type = api.create("jclouds-test-1", CreateVolumeTypeOptions.Builder.specs(ImmutableMap.of("x", "y"))); assertEquals(type, testVolumeType()); } @@ -140,7 +140,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.deleteVolumeType("8")); + assertTrue(api.delete("8")); } public void testDeleteVolumeTypeFailNotFound() { @@ -152,7 +152,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertFalse(api.deleteVolumeType("8")); + assertFalse(api.delete("8")); } public void testGetAllExtraSpecs() { @@ -164,7 +164,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_extra_specs.json")).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertEquals(api.getAllExtraSpecs("9"), ImmutableMap.of("test", "value1")); + assertEquals(api.getExtraSpecs("9"), ImmutableMap.of("test", "value1")); } public void testGetAllExtraSpecsFailNotFound() { @@ -176,7 +176,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(404).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.getAllExtraSpecs("9").isEmpty()); + assertTrue(api.getExtraSpecs("9").isEmpty()); } public void testSetAllExtraSpecs() { @@ -190,7 +190,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.setAllExtraSpecs("9", ImmutableMap.of("test1", "somevalue"))); + assertTrue(api.updateExtraSpecs("9", ImmutableMap.of("test1", "somevalue"))); } public void testSetExtraSpec() { @@ -204,7 +204,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest { HttpResponse.builder().statusCode(200).build() ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get(); - assertTrue(api.setExtraSpec("5", "test1", "somevalue")); + assertTrue(api.updateExtraSpec("5", "test1", "somevalue")); } public void testGetExtraSpec() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java index 6d87e17c07..941613ec50 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java @@ -65,11 +65,11 @@ public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest { if (volumeTypeOption.isPresent()) { if (testVolumeType != null) { final String id = testVolumeType.getId(); - assertTrue(volumeTypeOption.get().deleteVolumeType(id)); + assertTrue(volumeTypeOption.get().delete(id)); assertTrue(new RetryablePredicate(new Predicate() { @Override public boolean apply(VolumeTypeApi volumeApi) { - return volumeApi.getVolumeType(id) == null; + return volumeApi.get(id) == null; } }, 5 * 1000L).apply(volumeTypeOption.get())); } @@ -79,50 +79,50 @@ public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest { public void testCreateVolumeType() { if (volumeTypeOption.isPresent()) { - testVolumeType = volumeTypeOption.get().createVolumeType( + testVolumeType = volumeTypeOption.get().create( "jclouds-test-1", CreateVolumeTypeOptions.Builder.specs(ImmutableMap.of("test", "value1"))); assertTrue(new RetryablePredicate(new Predicate() { @Override public boolean apply(VolumeTypeApi volumeTypeApi) { - return volumeTypeApi.getVolumeType(testVolumeType.getId()) != null; + return volumeTypeApi.get(testVolumeType.getId()) != null; } }, 180 * 1000L).apply(volumeTypeOption.get())); - assertEquals(volumeTypeOption.get().getVolumeType(testVolumeType.getId()).getName(), "jclouds-test-1"); - assertEquals(volumeTypeOption.get().getVolumeType(testVolumeType.getId()).getExtraSpecs(), ImmutableMap.of("test", "value1")); + assertEquals(volumeTypeOption.get().get(testVolumeType.getId()).getName(), "jclouds-test-1"); + assertEquals(volumeTypeOption.get().get(testVolumeType.getId()).getExtraSpecs(), ImmutableMap.of("test", "value1")); } } @Test(dependsOnMethods = "testCreateVolumeType") public void testListVolumeTypes() { if (volumeTypeOption.isPresent()) { - Set volumeTypes = volumeTypeOption.get().listVolumeTypes(); + Set volumeTypes = volumeTypeOption.get().list().toImmutableSet(); assertNotNull(volumeTypes); boolean foundIt = false; for (VolumeType vt : volumeTypes) { - VolumeType details = volumeTypeOption.get().getVolumeType(vt.getId()); + VolumeType details = volumeTypeOption.get().get(vt.getId()); assertNotNull(details); if (Objects.equal(details.getId(), testVolumeType.getId())) { foundIt = true; } } - assertTrue(foundIt, "Failed to find the volume type we created in listVolumeTypes() response"); + assertTrue(foundIt, "Failed to find the volume type we created in list() response"); } } @Test(dependsOnMethods = "testCreateVolumeType") public void testExtraSpecs() { if (volumeTypeOption.isPresent()) { - assertEquals(volumeTypeOption.get().getAllExtraSpecs(testVolumeType.getId()), ImmutableMap.of("test", "value1")); + assertEquals(volumeTypeOption.get().getExtraSpecs(testVolumeType.getId()), ImmutableMap.of("test", "value1")); assertEquals(volumeTypeOption.get().getExtraSpec(testVolumeType.getId(), "test"), "value1"); - assertTrue(volumeTypeOption.get().setAllExtraSpecs(testVolumeType.getId(), ImmutableMap.of("test1", "wibble"))); + assertTrue(volumeTypeOption.get().updateExtraSpecs(testVolumeType.getId(), ImmutableMap.of("test1", "wibble"))); } } @Test(dependsOnMethods = "testCreateVolumeType") public void testUpdateIndividualSpec() { if (volumeTypeOption.isPresent()) { - assertTrue(volumeTypeOption.get().setExtraSpec(testVolumeType.getId(), "test1", "freddy")); + assertTrue(volumeTypeOption.get().updateExtraSpec(testVolumeType.getId(), "test1", "freddy")); assertEquals(volumeTypeOption.get().getExtraSpec(testVolumeType.getId(), "test1"), "freddy"); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiExpectTest.java index 12fa23a3e7..c4d6453023 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiExpectTest.java @@ -56,7 +56,7 @@ public class ExtensionApiExpectTest extends BaseNovaApiExpectTest { assertEquals(apiWhenExtensionsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExtensionsExist.getExtensionApiForZone("az-1.region-a.geo-1").listExtensions().toString(), + assertEquals(apiWhenExtensionsExist.getExtensionApiForZone("az-1.region-a.geo-1").list().toString(), new ParseExtensionListTest().expected().toString()); } @@ -73,7 +73,7 @@ public class ExtensionApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, listExtensions, listExtensionsResponse); - assertTrue(apiWhenNoServersExist.getExtensionApiForZone("az-1.region-a.geo-1").listExtensions().isEmpty()); + assertTrue(apiWhenNoServersExist.getExtensionApiForZone("az-1.region-a.geo-1").list().isEmpty()); } // TODO: gson deserializer for Multimap @@ -92,7 +92,7 @@ public class ExtensionApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenExtensionsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, getExtension, getExtensionResponse); - assertEquals(apiWhenExtensionsExist.getExtensionApiForZone("az-1.region-a.geo-1").getExtensionByAlias("RS-PIE") + assertEquals(apiWhenExtensionsExist.getExtensionApiForZone("az-1.region-a.geo-1").get("RS-PIE") .toString(), new ParseExtensionTest().expected().toString()); } @@ -110,7 +110,7 @@ public class ExtensionApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenNoExtensionsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, getExtension, getExtensionResponse); - assertNull(apiWhenNoExtensionsExist.getExtensionApiForZone("az-1.region-a.geo-1").getExtensionByAlias("RS-PIE")); + assertNull(apiWhenNoExtensionsExist.getExtensionApiForZone("az-1.region-a.geo-1").get("RS-PIE")); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java index 9a6d3e9b3e..2f1ef50f23 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java @@ -46,7 +46,7 @@ public class ExtensionApiLiveTest extends BaseNovaApiLiveTest { public void testListExtensions() throws Exception { for (String zoneId : zones) { ExtensionApi api = novaContext.getApi().getExtensionApiForZone(zoneId); - Set response = api.listExtensions(); + Set response = api.list(); assertNotNull(response); assertFalse(response.isEmpty()); for (Extension extension : response) { @@ -69,9 +69,9 @@ public class ExtensionApiLiveTest extends BaseNovaApiLiveTest { public void testGetExtensionByAlias() throws Exception { for (String zoneId : zones) { ExtensionApi api = novaContext.getApi().getExtensionApiForZone(zoneId); - Set response = api.listExtensions(); + Set response = api.list(); for (Extension extension : response) { - Extension details = api.getExtensionByAlias(extension.getId()); + Extension details = api.get(extension.getId()); assertNotNull(details); assertEquals(details.getId(), extension.getId()); assertEquals(details.getName(), extension.getName()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiExpectTest.java index 8f2b73c3b1..8b05f8cf8e 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiExpectTest.java @@ -56,7 +56,7 @@ public class FlavorApiExpectTest extends BaseNovaApiExpectTest { assertEquals(apiWhenFlavorsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenFlavorsExist.getFlavorApiForZone("az-1.region-a.geo-1").listFlavors().toString(), + assertEquals(apiWhenFlavorsExist.getFlavorApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseFlavorListTest().expected().toString()); } @@ -73,7 +73,7 @@ public class FlavorApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, listFlavors, listFlavorsResponse); - assertTrue(apiWhenNoServersExist.getFlavorApiForZone("az-1.region-a.geo-1").listFlavors().isEmpty()); + assertTrue(apiWhenNoServersExist.getFlavorApiForZone("az-1.region-a.geo-1").list().concat().isEmpty()); } // TODO: gson deserializer for Multimap @@ -93,7 +93,7 @@ public class FlavorApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, getFlavor, getFlavorResponse); assertEquals( - apiWhenFlavorsExist.getFlavorApiForZone("az-1.region-a.geo-1").getFlavor("52415800-8b69-11e0-9b19-734f1195ff37") + apiWhenFlavorsExist.getFlavorApiForZone("az-1.region-a.geo-1").get("52415800-8b69-11e0-9b19-734f1195ff37") .toString(), new ParseFlavorTest().expected().toString()); } @@ -111,7 +111,7 @@ public class FlavorApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenNoFlavorsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, getFlavor, getFlavorResponse); - assertNull(apiWhenNoFlavorsExist.getFlavorApiForZone("az-1.region-a.geo-1").getFlavor("123")); + assertNull(apiWhenNoFlavorsExist.getFlavorApiForZone("az-1.region-a.geo-1").get("123")); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiLiveTest.java index 6dbdb99330..a45e6bfce4 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/FlavorApiLiveTest.java @@ -47,7 +47,7 @@ public class FlavorApiLiveTest extends BaseNovaApiLiveTest { public void testListFlavors() throws Exception { for (String zoneId : zones) { FlavorApi api = novaContext.getApi().getFlavorApiForZone(zoneId); - Set response = api.listFlavors(); + Set response = api.list().concat().toImmutableSet(); assertNotNull(response); assertFalse(response.isEmpty()); for (Resource flavor : response) { @@ -67,7 +67,7 @@ public class FlavorApiLiveTest extends BaseNovaApiLiveTest { public void testListFlavorsInDetail() throws Exception { for (String zoneId : zones) { FlavorApi api = novaContext.getApi().getFlavorApiForZone(zoneId); - Set response = api.listFlavorsInDetail(); + Set response = api.listInDetail().concat().toImmutableSet(); assertNotNull(response); assertFalse(response.isEmpty()); for (Flavor flavor : response) { @@ -90,9 +90,9 @@ public class FlavorApiLiveTest extends BaseNovaApiLiveTest { public void testGetFlavorById() throws Exception { for (String zoneId : zones) { FlavorApi api = novaContext.getApi().getFlavorApiForZone(zoneId); - Set response = api.listFlavorsInDetail(); + Set response = api.listInDetail().concat().toImmutableSet(); for (Flavor flavor : response) { - Flavor details = api.getFlavor(flavor.getId()); + Flavor details = api.get(flavor.getId()); assertNotNull(details); assertEquals(details.getId(), flavor.getId()); assertEquals(details.getName(), flavor.getName()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java index 2b3768bcf8..705cf2a280 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java @@ -40,39 +40,39 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit", testName = "ImageAsyncApiTest") public class ImageApiExpectTest extends BaseNovaApiExpectTest { public void testListImagesWhenResponseIs2xx() throws Exception { - HttpRequest listImages = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listImagesResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/image_list.json")).build(); NovaApi apiWhenImagesExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, listImages, listImagesResponse); + responseWithKeystoneAccess, list, listResponse); assertEquals(apiWhenImagesExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenImagesExist.getImageApiForZone("az-1.region-a.geo-1").listImages().toString(), + assertEquals(apiWhenImagesExist.getImageApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseImageListTest().expected().toString()); } public void testListImagesWhenReponseIs404IsEmpty() throws Exception { - HttpRequest listImages = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listImagesResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, listImages, listImagesResponse); + responseWithKeystoneAccess, list, listResponse); - assertTrue(apiWhenNoServersExist.getImageApiForZone("az-1.region-a.geo-1").listImages().isEmpty()); + assertTrue(apiWhenNoServersExist.getImageApiForZone("az-1.region-a.geo-1").list().concat().isEmpty()); } public void testGetImageWhenResponseIs2xx() throws Exception { @@ -91,7 +91,7 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, getImage, getImageResponse); assertEquals( - apiWhenImagesExist.getImageApiForZone("az-1.region-a.geo-1").getImage("52415800-8b69-11e0-9b19-734f5736d2a2") + apiWhenImagesExist.getImageApiForZone("az-1.region-a.geo-1").get("52415800-8b69-11e0-9b19-734f5736d2a2") .toString(), new ParseImageTest().expected().toString()); } @@ -108,7 +108,7 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenNoImagesExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, getImage, getImageResponse); - assertNull(apiWhenNoImagesExist.getImageApiForZone("az-1.region-a.geo-1").getImage( + assertNull(apiWhenNoImagesExist.getImageApiForZone("az-1.region-a.geo-1").get( "52415800-8b69-11e0-9b19-734f5736d2a2")); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java index 7f9bc2b50d..7e59eea5cf 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java @@ -42,7 +42,7 @@ public class ImageApiLiveTest extends BaseNovaApiLiveTest { public void testListImages() throws Exception { for (String zoneId : zones) { ImageApi api = novaContext.getApi().getImageApiForZone(zoneId); - Set response = api.listImages(); + Set response = api.list().concat().toImmutableSet(); assertNotNull(response); assertFalse(response.isEmpty()); for (Resource image : response) { @@ -57,7 +57,7 @@ public class ImageApiLiveTest extends BaseNovaApiLiveTest { public void testListImagesInDetail() throws Exception { for (String zoneId : novaContext.getApi().getConfiguredZones()) { ImageApi api = novaContext.getApi().getImageApiForZone(zoneId); - Set response = api.listImagesInDetail(); + Set response = api.listInDetail().concat().toImmutableSet(); assertNotNull(response); assertFalse(response.isEmpty()); for (Image image : response) { @@ -81,9 +81,9 @@ public class ImageApiLiveTest extends BaseNovaApiLiveTest { public void testGetImageById() throws Exception { for (String zoneId : novaContext.getApi().getConfiguredZones()) { ImageApi api = novaContext.getApi().getImageApiForZone(zoneId); - Set response = api.listImagesInDetail(); + Set response = api.listInDetail().concat().toImmutableSet(); for (Image image : response) { - Image details = api.getImage(image.getId()); + Image details = api.get(image.getId()); assertNotNull(details); assertEquals(details.getId(), image.getId()); assertEquals(details.getName(), image.getName()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java index 897ee0192b..967aeea409 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java @@ -58,7 +58,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().toString(), + assertEquals(apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseServerListTest().expected().toString()); } @@ -75,7 +75,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, listServers, listServersResponse); - assertTrue(apiWhenNoServersExist.getServerApiForZone("az-1.region-a.geo-1").listServers().isEmpty()); + assertTrue(apiWhenNoServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().isEmpty()); } public void testCreateServerWhenResponseIs202() throws Exception { @@ -96,7 +96,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWithNewServer = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, createServer, createServerResponse); - assertEquals(apiWithNewServer.getServerApiForZone("az-1.region-a.geo-1").createServer("test-e92", "1241", "100").toString(), + assertEquals(apiWithNewServer.getServerApiForZone("az-1.region-a.geo-1").create("test-e92", "1241", "100").toString(), new ParseCreatedServerTest().expected().toString()); } @@ -120,7 +120,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWithNewServer = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, createServer, createServerResponse); - assertEquals(apiWithNewServer.getServerApiForZone("az-1.region-a.geo-1").createServer("test-e92", "1241", + assertEquals(apiWithNewServer.getServerApiForZone("az-1.region-a.geo-1").create("test-e92", "1241", "100", new CreateServerOptions().securityGroupNames("group1", "group2")).toString(), new ParseCreatedServerTest().expected().toString()); } @@ -196,7 +196,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, stopServer, stopServerResponse); - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").stopServer(serverId); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").stop(serverId); } public void testStopServerWhenResponseIs404() throws Exception { @@ -218,7 +218,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, stopServer, stopServerResponse); try { - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").stopServer(serverId); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").stop(serverId); fail("Expected an exception."); } catch (Exception e) { ; @@ -243,7 +243,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, startServer, startServerResponse); - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").startServer(serverId); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").start(serverId); } public void testStartServerWhenResponseIs404() throws Exception { @@ -264,7 +264,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, startServer, startServerResponse); try { - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").startServer(serverId); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").start(serverId); fail("Expected an exception."); } catch (Exception e) { ; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java index b8d78ed364..6d47cd88e1 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java @@ -44,7 +44,7 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest { public void testListServers() throws Exception { for (String zoneId : zones) { ServerApi api = novaContext.getApi().getServerApiForZone(zoneId); - Set response = api.listServers(); + Set response = api.list().concat().toImmutableSet(); assertNotNull(response); assertFalse(response.isEmpty()); assert null != response; @@ -59,7 +59,7 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest { public void testListServersInDetail() throws Exception { for (String zoneId : zones) { ServerApi api = novaContext.getApi().getServerApiForZone(zoneId); - Set response = api.listServersInDetail(); + Set response = api.listInDetail().concat().toImmutableSet(); assertNotNull(response); assertFalse(response.isEmpty()); for (Server server : response) { @@ -72,9 +72,9 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest { public void testGetServerById() throws Exception { for (String zoneId : zones) { ServerApi api = novaContext.getApi().getServerApiForZone(zoneId); - Set response = api.listServers(); + Set response = api.list().concat().toImmutableSet(); for (Resource server : response) { - Server details = api.getServer(server.getId()); + Server details = api.get(server.getId()); assertEquals(details.getId(), server.getId()); assertEquals(details.getName(), server.getName()); assertEquals(details.getLinks(), server.getLinks()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/CreateSecurityGroupIfNeededTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/CreateSecurityGroupIfNeededTest.java index 4965d2cb60..4c38df007e 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/CreateSecurityGroupIfNeededTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/CreateSecurityGroupIfNeededTest.java @@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "unit", testName = "CreateSecurityGroupIfNeededTest") public class CreateSecurityGroupIfNeededTest extends BaseNovaApiExpectTest { - HttpRequest createSecurityGroup = HttpRequest.builder().method("POST").endpoint( + HttpRequest create = HttpRequest.builder().method("POST").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()) @@ -61,13 +61,13 @@ public class CreateSecurityGroupIfNeededTest extends BaseNovaApiExpectTest { builder.put(extensionsOfNovaRequest, extensionsOfNovaResponse); int groupId = 2769; - HttpResponse createSecurityGroupResponse = HttpResponse.builder().statusCode(200) + HttpResponse createResponse = HttpResponse.builder().statusCode(200) .payload( payloadFromStringWithContentType( String.format("{\"security_group\": {\"rules\": [], \"tenant_id\": \"37936628937291\", \"id\": %s, \"name\": \"jclouds_mygroup\", \"description\": \"jclouds_mygroup\"}}", groupId), "application/json; charset=UTF-8")).build(); - builder.put(createSecurityGroup, createSecurityGroupResponse); + builder.put(create, createResponse); int ruleId = 10331; @@ -138,23 +138,23 @@ public class CreateSecurityGroupIfNeededTest extends BaseNovaApiExpectTest { builder.put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess); builder.put(extensionsOfNovaRequest, extensionsOfNovaResponse); - HttpResponse createSecurityGroupResponse = HttpResponse.builder().statusCode(400) + HttpResponse createResponse = HttpResponse.builder().statusCode(400) .payload( payloadFromStringWithContentType( "{\"badRequest\": {\"message\": \"Security group test already exists\", \"code\": 400}}", "application/json; charset=UTF-8")).build(); - builder.put(createSecurityGroup, createSecurityGroupResponse); + builder.put(create, createResponse); - HttpRequest listSecurityGroups = HttpRequest.builder().method("GET").endpoint( + HttpRequest list = HttpRequest.builder().method("GET").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).build(); - HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse listResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygroup_list_details_computeservice_typical.json")).build(); - builder.put(listSecurityGroups, listSecurityGroupsResponse); + builder.put(list, listResponse); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(builder.build()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java index e386bf4ad1..8bdba651cb 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java @@ -46,17 +46,17 @@ import com.google.common.collect.Iterables; public class FindSecurityGroupWithNameAndReturnTrueExpectTest extends BaseNovaApiExpectTest { public void testUpdateReferenceWhenSecurityGroupListContainsGroupName() throws Exception { - HttpRequest listSecurityGroups = HttpRequest.builder().method("GET").endpoint( + HttpRequest list = HttpRequest.builder().method("GET").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).build(); - HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse listResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygroup_list.json")).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listSecurityGroups, - listSecurityGroupsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, + listResponse); FindSecurityGroupWithNameAndReturnTrue predicate = new FindSecurityGroupWithNameAndReturnTrue( apiWhenSecurityGroupsExist); @@ -74,17 +74,17 @@ public class FindSecurityGroupWithNameAndReturnTrueExpectTest extends BaseNovaAp } public void testDoesNotUpdateReferenceWhenSecurityGroupListMissingGroupName() throws Exception { - HttpRequest listSecurityGroups = HttpRequest.builder().method("GET").endpoint( + HttpRequest list = HttpRequest.builder().method("GET").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).build(); - HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse listResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/securitygroup_list.json")).build(); NovaApi apiWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listSecurityGroups, - listSecurityGroupsResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, + listResponse); FindSecurityGroupWithNameAndReturnTrue predicate = new FindSecurityGroupWithNameAndReturnTrue( apiWhenSecurityGroupsExist); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java index 2d90bd10ea..a108eef9ec 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java @@ -82,9 +82,9 @@ public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { protected Server createServerInZone(String zoneId) { ServerApi serverApi = novaContext.getApi().getServerApiForZone(zoneId); - ServerCreated server = serverApi.createServer("test", imageIdForZone(zoneId), flavorRefForZone(zoneId)); + ServerCreated server = serverApi.create("test", imageIdForZone(zoneId), flavorRefForZone(zoneId)); blockUntilServerInState(server.getId(), serverApi, Status.ACTIVE); - return serverApi.getServer(server.getId()); + return serverApi.get(server.getId()); } /** @@ -93,10 +93,10 @@ public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { */ protected void blockUntilServerInState(String serverId, ServerApi api, Status status) { Server currentDetails = null; - for (currentDetails = api.getServer(serverId); currentDetails.getStatus() != status || + for (currentDetails = api.get(serverId); currentDetails.getStatus() != status || (currentDetails.getExtendedStatus().isPresent() && currentDetails.getExtendedStatus().get().getTaskState() != null); currentDetails = api - .getServer(serverId)) { + .get(serverId)) { System.out.printf("blocking on status %s%n%s%n", status, currentDetails); try { Thread.sleep(5 * 1000); @@ -108,12 +108,12 @@ public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { protected String imageIdForZone(String zoneId) { ImageApi imageApi = novaContext.getApi().getImageApiForZone(zoneId); - return Iterables.getLast(imageApi.listImages()).getId(); + return Iterables.getLast(imageApi.list().concat()).getId(); } protected String flavorRefForZone(String zoneId) { FlavorApi flavorApi = novaContext.getApi().getFlavorApiForZone(zoneId); - return DEFAULT_FLAVOR_ORDERING.min(flavorApi.listFlavorsInDetail()).getId(); + return DEFAULT_FLAVOR_ORDERING.min(flavorApi.listInDetail().concat()).getId(); } static final Ordering DEFAULT_FLAVOR_ORDERING = new Ordering() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaComputeServiceContextExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaComputeServiceContextExpectTest.java index 7c56fb1ca8..fdf5fae0a5 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaComputeServiceContextExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaComputeServiceContextExpectTest.java @@ -39,12 +39,12 @@ import com.google.inject.Module; public abstract class BaseNovaComputeServiceContextExpectTest extends BaseNovaExpectTest implements Function { - protected final HttpRequest listImagesDetail = HttpRequest.builder().method("GET").endpoint( + protected final HttpRequest listDetail = HttpRequest.builder().method("GET").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/detail")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).build(); - protected final HttpResponse listImagesDetailResponse = HttpResponse.builder().statusCode(200).payload( + protected final HttpResponse listDetailResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/image_list_detail.json")).build(); protected final HttpRequest listFlavorsDetail = HttpRequest.builder().method("GET").endpoint( diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseKeyPairListTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseKeyPairListTest.java index bc30d5b001..34769989d0 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseKeyPairListTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseKeyPairListTest.java @@ -18,9 +18,6 @@ */ package org.jclouds.openstack.nova.v2_0.parse; -import java.util.Map; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.core.MediaType; @@ -28,11 +25,12 @@ import org.jclouds.json.BaseItemParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v2_0.config.NovaParserModule; import org.jclouds.openstack.nova.v2_0.domain.KeyPair; -import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.openstack.nova.v2_0.functions.internal.ParseKeyPairs; +import org.jclouds.rest.annotations.ResponseParser; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; import com.google.inject.Guice; import com.google.inject.Injector; @@ -41,7 +39,7 @@ import com.google.inject.Injector; * @author Michael Arnold */ @Test(groups = "unit", testName = "ParseKeyPairListTest") -public class ParseKeyPairListTest extends BaseItemParserTest>> { +public class ParseKeyPairListTest extends BaseItemParserTest> { @Override public String resource() { @@ -49,26 +47,20 @@ public class ParseKeyPairListTest extends BaseItemParserTest> expected() { - Map kp1 = Maps.newHashMap(); - kp1.put( - "keypair", + public FluentIterable expected() { + return FluentIterable.from(ImmutableSet.of( KeyPair .builder() .publicKey( "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQCy9EC3O7Ff80vPEfAHDQob61PGwcpYc5KE7tEZnZhrB9n0NyHPRm0E0M+ls3fcTa04HDi+R0DzmRwoyhHQJyI658v8kWZZcuvFjKCcsgsSh/dzdX0xTreLIzSOzt5U7RnZYfshP5cmxtF99yrEY3M/swdin0L+fXsTSkR1B42STQ== nova@nv-aw2az1-api0001") - .name("default").fingerprint("ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c").build()); - Map kp2 = Maps.newHashMap(); - kp2.put( - "keypair", + .name("default").fingerprint("ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c").build(), KeyPair .builder() .publicKey( "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001") - .name("testkeypair").fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4").build()); - return ImmutableSet.of(kp1, kp2); + .name("testkeypair").fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4").build())); } protected Injector injector() { diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApi.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApi.java index e1a4867740..6f0cd99852 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApi.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApi.java @@ -23,8 +23,8 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpoint; +import org.jclouds.location.Zone; +import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.openstack.glance.v1_0.features.ImageApi; import org.jclouds.openstack.v2_0.features.ExtensionApi; import org.jclouds.rest.annotations.Delegate; @@ -44,23 +44,23 @@ import com.google.inject.Provides; public interface GlanceApi { /** * - * @return the Region codes configured + * @return the Zone codes configured */ @Provides - @Region - Set getConfiguredRegions(); + @Zone + Set getConfiguredZones(); /** * Provides synchronous access to Extension features. */ @Delegate - ExtensionApi getExtensionApiForRegion( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + ExtensionApi getExtensionApiForZone( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** * Provides synchronous access to Image features. */ @Delegate - ImageApi getImageApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + ImageApi getImageApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); } diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApiMetadata.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApiMetadata.java index 6669d59c8f..9086048425 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApiMetadata.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceApiMetadata.java @@ -28,7 +28,7 @@ import org.jclouds.apis.ApiMetadata; import org.jclouds.openstack.glance.v1_0.config.GlanceRestClientModule; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.BaseRestApiMetadata; @@ -86,7 +86,7 @@ public class GlanceApiMetadata extends BaseRestApiMetadata { .defaultProperties(GlanceApiMetadata.defaultProperties()) .defaultModules(ImmutableSet.>builder() .add(KeystoneAuthenticationModule.class) - .add(RegionModule.class) + .add(ZoneModule.class) .add(GlanceRestClientModule.class).build()); } diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceAsyncApi.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceAsyncApi.java index d494d7a418..b36ab4421c 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceAsyncApi.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/GlanceAsyncApi.java @@ -21,8 +21,8 @@ package org.jclouds.openstack.glance.v1_0; import java.util.Set; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpoint; +import org.jclouds.location.Zone; +import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.openstack.glance.v1_0.features.ImageAsyncApi; import org.jclouds.openstack.v2_0.features.ExtensionAsyncApi; import org.jclouds.rest.annotations.Delegate; @@ -41,23 +41,23 @@ import com.google.inject.Provides; public interface GlanceAsyncApi { /** * - * @return the Region codes configured + * @return the Zone codes configured */ @Provides - @Region - Set getConfiguredRegions(); + @Zone + Set getConfiguredZones(); /** * Provides asynchronous access to Extension features. */ @Delegate - ExtensionAsyncApi getExtensionApiForRegion( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + ExtensionAsyncApi getExtensionApiForZone( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** * Provides asynchronous access to Image features. */ @Delegate - ImageAsyncApi getImageApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + ImageAsyncApi getImageApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); } diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/config/GlanceRestClientModule.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/config/GlanceRestClientModule.java index e6d266a052..e5bda4af23 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/config/GlanceRestClientModule.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/config/GlanceRestClientModule.java @@ -96,7 +96,7 @@ public class GlanceRestClientModule>() { @Override public Set load(String key) throws Exception { - return glanceApi.get().getExtensionApiForRegion(key).listExtensions(); + return glanceApi.get().getExtensionApiForZone(key).list(); } }); } diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageApi.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageApi.java index b24e368359..0aceab60ab 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageApi.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageApi.java @@ -19,9 +19,9 @@ package org.jclouds.openstack.glance.v1_0.features; import java.io.InputStream; -import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; import org.jclouds.io.Payload; import org.jclouds.javax.annotation.Nullable; @@ -30,6 +30,7 @@ import org.jclouds.openstack.glance.v1_0.domain.ImageDetails; import org.jclouds.openstack.glance.v1_0.options.CreateImageOptions; import org.jclouds.openstack.glance.v1_0.options.ListImageOptions; import org.jclouds.openstack.glance.v1_0.options.UpdateImageOptions; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; /** * Image Services @@ -41,21 +42,31 @@ import org.jclouds.openstack.glance.v1_0.options.UpdateImageOptions; */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface ImageApi { - /** - * Returns a set of brief metadata about images - */ - Set list(ListImageOptions... options); /** - * Returns a set of detailed metadata about images + * List all images (IDs, names, links) + * + * @return all images (IDs, names, links) */ - Set listInDetail(ListImageOptions... options); + PagedIterable list(); + + PaginatedCollection list(ListImageOptions options); + + /** + * List all images (all details) + * + * @return all images (all details) + */ + PagedIterable listInDetail(); + + PaginatedCollection listInDetail(ListImageOptions options); + /** * Return metadata about an image with id */ @Nullable - ImageDetails show(String id); + ImageDetails get(String id); /** * Return image data for image with id @@ -104,5 +115,5 @@ public interface ImageApi { * * @return true if successful */ - Boolean delete(String id); + boolean delete(String id); } diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageAsyncApi.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageAsyncApi.java index c4b41caf2c..31c7b5d974 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageAsyncApi.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/features/ImageAsyncApi.java @@ -19,7 +19,6 @@ package org.jclouds.openstack.glance.v1_0.features; import java.io.InputStream; -import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -33,20 +32,26 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.jclouds.collect.PagedIterable; import org.jclouds.io.Payload; import org.jclouds.openstack.glance.v1_0.domain.Image; import org.jclouds.openstack.glance.v1_0.domain.ImageDetails; import org.jclouds.openstack.glance.v1_0.functions.ParseImageDetailsFromHeaders; +import org.jclouds.openstack.glance.v1_0.functions.internal.ParseImageDetails; +import org.jclouds.openstack.glance.v1_0.functions.internal.ParseImages; import org.jclouds.openstack.glance.v1_0.options.CreateImageOptions; import org.jclouds.openstack.glance.v1_0.options.ListImageOptions; import org.jclouds.openstack.glance.v1_0.options.UpdateImageOptions; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -65,34 +70,58 @@ import com.google.common.util.concurrent.ListenableFuture; @RequestFilters(AuthenticateRequest.class) public interface ImageAsyncApi { + /** - * @see ImageApi#list + * @see ImageApi#list() */ @GET - @SelectJson("images") @Consumes(MediaType.APPLICATION_JSON) @Path("/images") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> list(ListImageOptions... options); - + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImages.class) + @Transform(ParseImages.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** @see ImageApi#list(ListImageOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/images") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImages.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> list(ListImageOptions options); + /** - * @see ImageApi#listInDetail + * @see ImageApi#listInDetail() */ @GET - @SelectJson("images") @Consumes(MediaType.APPLICATION_JSON) @Path("/images/detail") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listInDetail(ListImageOptions... options); + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImageDetails.class) + @Transform(ParseImageDetails.ToPagedIterable.class) + @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> listInDetail(); + + /** @see ImageApi#listInDetail(ListImageOptions) */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Path("/images/detail") + @RequestFilters(AuthenticateRequest.class) + @ResponseParser(ParseImageDetails.class) + @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) + ListenableFuture> listInDetail(ListImageOptions options); + /** - * @see ImageApi#show + * @see ImageApi#get */ @HEAD @Path("/images/{id}") @ResponseParser(ParseImageDetailsFromHeaders.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture show(@PathParam("id") String id); + ListenableFuture get(@PathParam("id") String id); /** * @see ImageApi#getAsStream diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImageDetails.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImageDetails.java new file mode 100644 index 0000000000..b111370720 --- /dev/null +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImageDetails.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.glance.v1_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.glance.v1_0.options.ListImageOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.glance.v1_0.GlanceApi; +import org.jclouds.openstack.glance.v1_0.domain.ImageDetails; +import org.jclouds.openstack.glance.v1_0.features.ImageApi; +import org.jclouds.openstack.glance.v1_0.functions.internal.ParseImageDetails.Images; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseImageDetails extends ParseJson> { + static class Images extends PaginatedCollection { + + @ConstructorProperties({ "images", "images_links" }) + protected Images(Iterable images, Iterable images_links) { + super(images, images_links); + } + + } + + @Inject + public ParseImageDetails(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final GlanceApi api; + + @Inject + protected ToPagedIterable(GlanceApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final ImageApi imageApi = api.getImageApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(imageApi.listInDetail(marker(input.toString()))); + } + + @Override + public String toString() { + return "listInDetail()"; + } + }; + } + + } + +} diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImages.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImages.java new file mode 100644 index 0000000000..0b8ea223fc --- /dev/null +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/internal/ParseImages.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.glance.v1_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.openstack.glance.v1_0.options.ListImageOptions.Builder.marker; + +import java.beans.ConstructorProperties; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; +import org.jclouds.openstack.glance.v1_0.GlanceApi; +import org.jclouds.openstack.glance.v1_0.domain.Image; +import org.jclouds.openstack.glance.v1_0.features.ImageApi; +import org.jclouds.openstack.glance.v1_0.functions.internal.ParseImages.Images; +import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +/** + * boiler plate until we determine a better way + * + * @author Adrian Cole + */ +@Beta +@Singleton +public class ParseImages extends ParseJson> { + static class Images extends PaginatedCollection { + + @ConstructorProperties({ "images", "images_links" }) + protected Images(Iterable images, Iterable images_links) { + super(images, images_links); + } + + } + + @Inject + public ParseImages(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends CallerArg0ToPagedIterable { + + private final GlanceApi api; + + @Inject + protected ToPagedIterable(GlanceApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> markerToNextForCallingArg0(final String zone) { + final ImageApi imageApi = api.getImageApiForZone(zone); + return new Function>() { + + @SuppressWarnings("unchecked") + @Override + public IterableWithMarker apply(Object input) { + return IterableWithMarker.class.cast(imageApi.list(marker(input.toString()))); + } + + @Override + public String toString() { + return "list()"; + } + }; + } + + } + +} diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/options/ListImageOptions.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/options/ListImageOptions.java index 2df3f430c2..0328e90b4a 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/options/ListImageOptions.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/options/ListImageOptions.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.glance.v1_0.options; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; import static org.jclouds.openstack.glance.v1_0.options.ImageField.CONTAINER_FORMAT; import static org.jclouds.openstack.glance.v1_0.options.ImageField.DISK_FORMAT; import static org.jclouds.openstack.glance.v1_0.options.ImageField.IS_PUBLIC; @@ -31,10 +29,12 @@ import static org.jclouds.openstack.glance.v1_0.options.ImageField.SIZE_MAX; import static org.jclouds.openstack.glance.v1_0.options.ImageField.SIZE_MIN; import static org.jclouds.openstack.glance.v1_0.options.ImageField.STATUS; -import org.jclouds.http.options.BaseHttpRequestOptions; +import java.util.Date; + import org.jclouds.openstack.glance.v1_0.domain.ContainerFormat; import org.jclouds.openstack.glance.v1_0.domain.DiskFormat; import org.jclouds.openstack.glance.v1_0.domain.Image.Status; +import org.jclouds.openstack.v2_0.options.PaginationOptions; /** *

Usage The recommended way to instantiate a ListImageOptions object is to statically import @@ -51,27 +51,9 @@ import org.jclouds.openstack.glance.v1_0.domain.Image.Status; * @author Adam Lowe * @see */ -public class ListImageOptions extends BaseHttpRequestOptions { +public class ListImageOptions extends PaginationOptions { public static final ListImageOptions NONE = new ListImageOptions(); - /** - * Given a string value x, return object names greater in value than the specified marker. - */ - public ListImageOptions marker(String marker) { - queryParameters.put("marker", checkNotNull(marker, "marker")); - return this; - } - - /** - * For an integer value n, limits the number of results to n values. - */ - public ListImageOptions limit(int limit) { - checkState(limit >= 0, "limit must be >= 0"); - checkState(limit <= 10000, "limit must be <= 10000"); - queryParameters.put("limit", Integer.toString(limit)); - return this; - } - /** * Return only those images having a matching name attribute */ @@ -267,8 +249,22 @@ public class ListImageOptions extends BaseHttpRequestOptions { * @see ListImageOptions#marker */ public static ListImageOptions marker(String marker) { - ListImageOptions options = new ListImageOptions(); - return options.marker(marker); + return new ListImageOptions().marker(marker); } } + + @Override + public ListImageOptions changesSince(Date ifModifiedSince) { + return ListImageOptions.class.cast(super.changesSince(ifModifiedSince)); + } + + @Override + public ListImageOptions marker(String marker) { + return ListImageOptions.class.cast(super.marker(marker)); + } + + @Override + public ListImageOptions limit(int limit) { + return ListImageOptions.class.cast(super.limit(limit)); + } } diff --git a/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiExpectTest.java b/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiExpectTest.java index a6df24ba1d..6eed0ebc87 100644 --- a/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiExpectTest.java +++ b/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiExpectTest.java @@ -64,9 +64,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, list, listResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").list().toString(), + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").list().concat().toString(), new ParseImagesTest().expected().toString()); } @@ -81,7 +81,7 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenNoExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, list, listResponse); - assertTrue(apiWhenNoExist.getImageApiForRegion("az-1.region-a.geo-1").list().isEmpty()); + assertTrue(apiWhenNoExist.getImageApiForZone("az-1.region-a.geo-1").list().concat().isEmpty()); } public void testListInDetailWhenResponseIs2xx() throws Exception { @@ -97,9 +97,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExistInDetail = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, listInDetail, listInDetailResponse); - assertEquals(apiWhenExistInDetail.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExistInDetail.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExistInDetail.getImageApiForRegion("az-1.region-a.geo-1").listInDetail().toString(), + assertEquals(apiWhenExistInDetail.getImageApiForZone("az-1.region-a.geo-1").listInDetail().concat().toString(), new ParseImagesInDetailTest().expected().toString()); } @@ -115,7 +115,7 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenNoExistInDetail = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, listInDetail, listInDetailResponse); - assertTrue(apiWhenNoExistInDetail.getImageApiForRegion("az-1.region-a.geo-1").listInDetail().isEmpty()); + assertTrue(apiWhenNoExistInDetail.getImageApiForZone("az-1.region-a.geo-1").listInDetail().concat().isEmpty()); } public void testShowWhenResponseIs2xx() throws Exception { @@ -131,9 +131,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, show, showResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").show("fcc451d0-f6e4-4824-ad8f-70ec12326d07").toString(), + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").get("fcc451d0-f6e4-4824-ad8f-70ec12326d07").toString(), new ParseImageDetailsFromHeadersTest().expected().toString()); } @@ -148,7 +148,7 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenNoExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, show, showResponse); - assertNull(apiWhenNoExist.getImageApiForRegion("az-1.region-a.geo-1").show("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); + assertNull(apiWhenNoExist.getImageApiForZone("az-1.region-a.geo-1").get("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); } @@ -163,9 +163,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, getResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(Strings2.toStringAndClose(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").getAsStream("fcc451d0-f6e4-4824-ad8f-70ec12326d07")), + assertEquals(Strings2.toStringAndClose(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").getAsStream("fcc451d0-f6e4-4824-ad8f-70ec12326d07")), "foo"); } @@ -180,7 +180,7 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenNoExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, getResponse); - assertNull(apiWhenNoExist.getImageApiForRegion("az-1.region-a.geo-1").getAsStream("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); + assertNull(apiWhenNoExist.getImageApiForZone("az-1.region-a.geo-1").getAsStream("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); } public void testCreateWhenResponseIs2xx() throws Exception { @@ -197,9 +197,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, createResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").create("test", new StringPayload("somedata")), + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").create("test", new StringPayload("somedata")), new ParseImageDetailsTest().expected()); } @@ -218,9 +218,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, createResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").create("test", new StringPayload("somedata")); + apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").create("test", new StringPayload("somedata")); } public void testReserveWhenResponseIs2xx() throws Exception { @@ -236,9 +236,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, createResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").reserve("test"), new ParseImageDetailsTest().expected()); + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").reserve("test"), new ParseImageDetailsTest().expected()); } @Test(expectedExceptions = AuthorizationException.class) @@ -255,9 +255,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, createResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").reserve("test"); + apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").reserve("test"); } public void testUpdateMetadataWhenResponseIs2xx() throws Exception { @@ -282,9 +282,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, updateResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1") + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1") .update("fcc451d0-f6e4-4824-ad8f-70ec12326d07", UpdateImageOptions.Builder.name("newname"), UpdateImageOptions.Builder.isPublic(true), @@ -313,9 +313,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, updateResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1") + apiWhenExist.getImageApiForZone("az-1.region-a.geo-1") .update("fcc451d0-f6e4-4824-ad8f-70ec12326d07", UpdateImageOptions.Builder.name("newname"), UpdateImageOptions.Builder.isPublic(true)); @@ -336,9 +336,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, updateResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").upload("fcc451d0-f6e4-4824-ad8f-70ec12326d07", + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").upload("fcc451d0-f6e4-4824-ad8f-70ec12326d07", new StringPayload("somenewdata")), new ParseImageDetailsTest().expected()); } @@ -360,9 +360,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, updateResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertEquals(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").upload("fcc451d0-f6e4-4824-ad8f-70ec12326d07", + assertEquals(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").upload("fcc451d0-f6e4-4824-ad8f-70ec12326d07", new StringPayload("somenewdata"), UpdateImageOptions.Builder.name("anothernewname")), new ParseImageDetailsTest().expected()); } @@ -383,9 +383,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, updateResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").upload("fcc451d0-f6e4-4824-ad8f-70ec12326d07", + apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").upload("fcc451d0-f6e4-4824-ad8f-70ec12326d07", new StringPayload("somenewdata"), UpdateImageOptions.Builder.name("anothernewname")); } @@ -399,9 +399,9 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, getResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertTrue(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").delete("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); + assertTrue(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").delete("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); } public void testDeleteWhenResponseIs4xx() throws Exception { @@ -415,8 +415,8 @@ public class ImageApiExpectTest extends BaseGlanceApiExpectTest { GlanceApi apiWhenExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, get, getResponse); - assertEquals(apiWhenExist.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1")); + assertEquals(apiWhenExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1")); - assertFalse(apiWhenExist.getImageApiForRegion("az-1.region-a.geo-1").delete("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); + assertFalse(apiWhenExist.getImageApiForZone("az-1.region-a.geo-1").delete("fcc451d0-f6e4-4824-ad8f-70ec12326d07")); } } diff --git a/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiLiveTest.java b/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiLiveTest.java index ef457545fb..765cc52fc2 100644 --- a/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiLiveTest.java +++ b/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/features/ImageApiLiveTest.java @@ -47,9 +47,9 @@ public class ImageApiLiveTest extends BaseGlanceApiLiveTest { @Test public void testList() throws Exception { - for (String zoneId : glanceContext.getApi().getConfiguredRegions()) { - ImageApi api = glanceContext.getApi().getImageApiForRegion(zoneId); - Set response = api.list(ListImageOptions.Builder.limit(100)); + for (String zoneId : glanceContext.getApi().getConfiguredZones()) { + ImageApi api = glanceContext.getApi().getImageApiForZone(zoneId); + Set response = api.list().concat().toImmutableSet(); assert null != response; for (Image image : response) { checkImage(image); @@ -65,13 +65,13 @@ public class ImageApiLiveTest extends BaseGlanceApiLiveTest { @Test public void testListInDetail() throws Exception { - for (String zoneId : glanceContext.getApi().getConfiguredRegions()) { - ImageApi api = glanceContext.getApi().getImageApiForRegion(zoneId); - Set response = api.listInDetail(); + for (String zoneId : glanceContext.getApi().getConfiguredZones()) { + ImageApi api = glanceContext.getApi().getImageApiForZone(zoneId); + Set response = api.listInDetail().concat().toImmutableSet(); assert null != response; for (ImageDetails image : response) { checkImage(image); - ImageDetails newDetails = api.show(image.getId()); + ImageDetails newDetails = api.get(image.getId()); checkImageDetails(newDetails); checkImageDetailsEqual(image, newDetails); } @@ -93,8 +93,8 @@ public class ImageApiLiveTest extends BaseGlanceApiLiveTest { @Test public void testCreateUpdateAndDeleteImage() { StringPayload imageData = new StringPayload("This isn't really an image!"); - for (String zoneId : glanceContext.getApi().getConfiguredRegions()) { - ImageApi api = glanceContext.getApi().getImageApiForRegion(zoneId); + for (String zoneId : glanceContext.getApi().getConfiguredZones()) { + ImageApi api = glanceContext.getApi().getImageApiForZone(zoneId); ImageDetails details = api.create("jclouds-live-test", imageData, diskFormat(DiskFormat.RAW), containerFormat(ContainerFormat.BARE)); assertEquals(details.getName(), "jclouds-live-test"); assertEquals(details.getSize().get().longValue(), imageData.getRawContent().length()); @@ -103,7 +103,9 @@ public class ImageApiLiveTest extends BaseGlanceApiLiveTest { assertEquals(details.getName(), "jclouds-live-test2"); assertEquals(details.getMinDisk(), 10); - Image fromListing = Iterables.getOnlyElement(api.list(ListImageOptions.Builder.name("jclouds-live-test2"), ListImageOptions.Builder.limit(2), ListImageOptions.Builder.containerFormat(ContainerFormat.BARE))); + Image fromListing = api.list( + ListImageOptions.Builder.containerFormat(ContainerFormat.BARE).name("jclouds-live-test2").limit(2)) + .get(0); assertEquals(fromListing.getId(), details.getId()); assertEquals(fromListing.getSize(), details.getSize()); @@ -118,8 +120,8 @@ public class ImageApiLiveTest extends BaseGlanceApiLiveTest { @Test public void testReserveUploadAndDeleteImage() { StringPayload imageData = new StringPayload("This isn't an image!"); - for (String zoneId : glanceContext.getApi().getConfiguredRegions()) { - ImageApi api = glanceContext.getApi().getImageApiForRegion(zoneId); + for (String zoneId : glanceContext.getApi().getConfiguredZones()) { + ImageApi api = glanceContext.getApi().getImageApiForZone(zoneId); ImageDetails details = api.reserve("jclouds-live-res-test", diskFormat(DiskFormat.RAW), containerFormat(ContainerFormat.BARE)); assertEquals(details.getName(), "jclouds-live-res-test"); @@ -128,7 +130,7 @@ public class ImageApiLiveTest extends BaseGlanceApiLiveTest { assertEquals(details.getSize().get().longValue(), imageData.getRawContent().length()); assertEquals(details.getMinDisk(), 10); - Image fromListing = Iterables.getOnlyElement(api.list(ListImageOptions.Builder.name("jclouds-live-res-test2"), ListImageOptions.Builder.limit(2), ListImageOptions.Builder.containerFormat(ContainerFormat.BARE))); + Image fromListing = Iterables.getOnlyElement(api.list(ListImageOptions.Builder.name("jclouds-live-res-test2").limit(2).containerFormat(ContainerFormat.BARE))); assertEquals(fromListing.getId(), details.getId()); assertEquals(fromListing.getSize(), details.getSize()); diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApi.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApi.java index 2f9a5ed1e0..b2b24ee111 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApi.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApi.java @@ -26,8 +26,7 @@ import javax.ws.rs.PathParam; import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpoint; +import org.jclouds.location.Zone; import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.openstack.quantum.v1_0.features.NetworkApi; import org.jclouds.openstack.quantum.v1_0.features.PortApi; @@ -48,30 +47,30 @@ import com.google.inject.Provides; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface QuantumApi { /** - * @return the Region codes configured + * @return the Zone codes configured */ @Provides - @Region - Set getConfiguredRegions(); + @Zone + Set getConfiguredZones(); /** * Provides synchronous access to Extension features. */ @Delegate - ExtensionApi getExtensionApiForRegion( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + ExtensionApi getExtensionApiForZone( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** * Provides synchronous access to Network features. */ @Delegate - NetworkApi getNetworkApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + NetworkApi getNetworkApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** * Provides synchronous access to Port features. */ @Delegate @Path("/networks/{net}") - PortApi getPortApiForRegionAndNetwork(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, + PortApi getPortApiForZoneAndNetwork(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("net") String networkId); } diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApiMetadata.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApiMetadata.java index 9d38d93e9c..9e986d7028 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApiMetadata.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumApiMetadata.java @@ -27,7 +27,7 @@ import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule; import org.jclouds.openstack.quantum.v1_0.config.QuantumRestClientModule; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.rest.RestContext; @@ -85,7 +85,7 @@ public class QuantumApiMetadata extends BaseRestApiMetadata { .defaultProperties(QuantumApiMetadata.defaultProperties()) .defaultModules(ImmutableSet.>builder() .add(KeystoneAuthenticationModule.class) - .add(RegionModule.class) + .add(ZoneModule.class) .add(QuantumRestClientModule.class).build()); } diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumAsyncApi.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumAsyncApi.java index 0ea08a3960..4a6ccd897a 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumAsyncApi.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/QuantumAsyncApi.java @@ -24,8 +24,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpoint; +import org.jclouds.location.Zone; +import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.openstack.quantum.v1_0.features.NetworkAsyncApi; import org.jclouds.openstack.quantum.v1_0.features.PortAsyncApi; import org.jclouds.openstack.v2_0.features.ExtensionAsyncApi; @@ -45,30 +45,30 @@ import com.google.inject.Provides; public interface QuantumAsyncApi { /** * - * @return the Region codes configured + * @return the Zone codes configured */ @Provides - @Region - Set getConfiguredRegions(); + @Zone + Set getConfiguredZones(); /** * Provides asynchronous access to Extension features. */ @Delegate - ExtensionAsyncApi getExtensionApiForRegion( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + ExtensionAsyncApi getExtensionApiForZone( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** * Provides asynchronous access to Network features. */ @Delegate - NetworkAsyncApi getNetworkApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); + NetworkAsyncApi getNetworkApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** * Provides asynchronous access to Port features. */ @Delegate @Path("/networks/{net}") - PortAsyncApi getPortApiForRegionAndNetwork(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, + PortAsyncApi getPortApiForZoneAndNetwork(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("net") String networkId); } diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/config/QuantumRestClientModule.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/config/QuantumRestClientModule.java index 4b7be5ba64..4290fa1f52 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/config/QuantumRestClientModule.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/config/QuantumRestClientModule.java @@ -70,6 +70,7 @@ public class QuantumRestClientModule>() { @Override public Set load(String key) throws Exception { - return quantumApi.get().getExtensionApiForRegion(key).listExtensions(); + return quantumApi.get().getExtensionApiForZone(key).list(); } }); } diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApi.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApi.java index 116a23eef7..795118202a 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApi.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.quantum.v1_0.features; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -26,6 +25,8 @@ import org.jclouds.openstack.quantum.v1_0.domain.Network; import org.jclouds.openstack.quantum.v1_0.domain.NetworkDetails; import org.jclouds.openstack.quantum.v1_0.domain.Reference; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Network operations on the openstack quantum API. *

@@ -44,12 +45,12 @@ public interface NetworkApi { * Returns the list of all networks currently defined in Quantum for the current tenant. The list provides the unique * identifier of each network configured for the tenant. */ - Set listReferences(); + FluentIterable listReferences(); /** * Returns all networks currently defined in Quantum for the current tenant. */ - Set list(); + FluentIterable list(); /** * Returns the specific network. diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkAsyncApi.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkAsyncApi.java index ffb680528c..64687a5502 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkAsyncApi.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/NetworkAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.quantum.v1_0.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -40,9 +38,10 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.WrapWith; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -63,8 +62,8 @@ public interface NetworkAsyncApi { */ @GET @SelectJson("networks") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listReferences(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listReferences(); /** * @see NetworkApi#list @@ -72,8 +71,8 @@ public interface NetworkAsyncApi { @GET @SelectJson("networks") @Path("/detail") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> list(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** * @see NetworkApi#get diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortApi.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortApi.java index 5f65506caf..b4a1680e6e 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortApi.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.quantum.v1_0.features; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -27,6 +26,8 @@ import org.jclouds.openstack.quantum.v1_0.domain.Port; import org.jclouds.openstack.quantum.v1_0.domain.PortDetails; import org.jclouds.openstack.quantum.v1_0.domain.Reference; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Port operations on the openstack quantum API. *

@@ -44,12 +45,12 @@ public interface PortApi { /** * Returns the list of all ports currently defined in Quantum for the requested network */ - Set listReferences(); + FluentIterable listReferences(); /** * Returns the set of ports currently defined in Quantum for the requested network. */ - Set list(); + FluentIterable list(); /** * Returns a specific port. diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortAsyncApi.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortAsyncApi.java index a11b474b1d..fccae571b5 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortAsyncApi.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/features/PortAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.quantum.v1_0.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -40,9 +38,10 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.WrapWith; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -63,8 +62,8 @@ public interface PortAsyncApi { */ @GET @SelectJson("ports") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listReferences(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listReferences(); /** * @see PortApi#list @@ -72,8 +71,8 @@ public interface PortAsyncApi { @GET @SelectJson("ports") @Path("/detail") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> list(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** * @see PortApi#get diff --git a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiExpectTest.java b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiExpectTest.java index bf23dfb041..16190fa39a 100644 --- a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiExpectTest.java +++ b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiExpectTest.java @@ -53,9 +53,9 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_network_refs.json", APPLICATION_JSON)).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); - Set nets = api.listReferences(); + Set nets = api.listReferences().toImmutableSet(); assertEquals(nets, listOfNetworkRefs()); } @@ -64,7 +64,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks").build(), HttpResponse.builder().statusCode(404).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); assertTrue(api.listReferences().isEmpty()); } @@ -74,9 +74,9 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/detail").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_networks.json", APPLICATION_JSON)).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); - Set nets = api.list(); + Set nets = api.list().toImmutableSet(); assertEquals(nets, listOfNetworks()); } @@ -85,7 +85,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/detail").build(), HttpResponse.builder().statusCode(404).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); assertTrue(api.list().isEmpty()); } @@ -95,7 +95,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/network.json", APPLICATION_JSON)).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); Network net = api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertEquals(net, new ParseNetworkTest().expected()); @@ -106,7 +106,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(), HttpResponse.builder().statusCode(404).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); assertNull(api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a")); } @@ -116,7 +116,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/detail").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/network_details.json", APPLICATION_JSON)).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); NetworkDetails net = api.getDetails("16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertEquals(net, new ParseNetworkDetailsTest().expected()); @@ -127,7 +127,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/detail").build(), HttpResponse.builder().statusCode(404).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); assertNull(api.getDetails("16dba3bc-f3fa-4775-afdc-237e12c72f6a")); } @@ -138,7 +138,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { authenticatedGET().endpoint(endpoint + "/tenants/3456/networks").method("POST") .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\"}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"network\":{\"id\":\"12345\"}}", APPLICATION_JSON)).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); Reference net = api.create("another-test"); assertEquals(net, Reference.builder().id("12345").build()); @@ -151,7 +151,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { authenticatedGET().endpoint(endpoint + "/tenants/3456/networks").method("POST") .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\"}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(401).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); api.create("another-test"); } @@ -162,7 +162,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/12345").method("PUT") .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\"}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(200).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); assertTrue(api.rename("12345", "another-test")); } @@ -174,7 +174,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/12345").method("PUT") .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\"}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(404).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); api.rename("12345", "another-test"); } @@ -184,7 +184,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/12345").method("DELETE").build(), HttpResponse.builder().statusCode(200).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); assertTrue(api.delete("12345")); } @@ -195,7 +195,7 @@ public class NetworkApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/12345").method("DELETE").build(), HttpResponse.builder().statusCode(403).build()) - .getNetworkApiForRegion("region-a.geo-1"); + .getNetworkApiForZone("region-a.geo-1"); api.delete("12345"); } diff --git a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiLiveTest.java b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiLiveTest.java index 5add5bf041..6f5cdb115b 100644 --- a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiLiveTest.java +++ b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/NetworkApiLiveTest.java @@ -41,9 +41,9 @@ import com.google.common.collect.ImmutableList; public class NetworkApiLiveTest extends BaseQuantumApiLiveTest { public void testListNetworks() { - for (String regionId : quantumContext.getApi().getConfiguredRegions()) { - Set ids = quantumContext.getApi().getNetworkApiForRegion(regionId).listReferences(); - Set networks = quantumContext.getApi().getNetworkApiForRegion(regionId).list(); + for (String zoneId : quantumContext.getApi().getConfiguredZones()) { + Set ids = quantumContext.getApi().getNetworkApiForZone(zoneId).listReferences().toImmutableSet(); + Set networks = quantumContext.getApi().getNetworkApiForZone(zoneId).list().toImmutableSet(); assertNotNull(ids); assertEquals(ids.size(), networks.size()); for (Network network : networks) { @@ -54,8 +54,8 @@ public class NetworkApiLiveTest extends BaseQuantumApiLiveTest { } public void testCreateUpdateAndDeleteNetwork() { - for (String regionId : quantumContext.getApi().getConfiguredRegions()) { - NetworkApi api = quantumContext.getApi().getNetworkApiForRegion(regionId); + for (String zoneId : quantumContext.getApi().getConfiguredZones()) { + NetworkApi api = quantumContext.getApi().getNetworkApiForZone(zoneId); Reference net = api.create("jclouds-test"); assertNotNull(net); diff --git a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiExpectTest.java b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiExpectTest.java index 02a61a1c3d..47764d3fab 100644 --- a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiExpectTest.java +++ b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiExpectTest.java @@ -54,9 +54,9 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/1a104cf5-cb18-4d35-9407-2fd2646d9d0b/ports").build(), HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"ports\": [{\"id\": \"a6058a59-fa8c-46cc-bac8-08904e6ff0a5\"}]}", APPLICATION_JSON)).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); - Set nets = api.listReferences(); + Set nets = api.listReferences().toImmutableSet(); assertEquals(nets, ImmutableSet.of(Reference.builder().id("a6058a59-fa8c-46cc-bac8-08904e6ff0a5").build())); } @@ -65,7 +65,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/1a104cf5-cb18-4d35-9407-2fd2646d9d0b/ports").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); assertTrue(api.listReferences().isEmpty()); } @@ -75,9 +75,9 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/1a104cf5-cb18-4d35-9407-2fd2646d9d0b/ports/detail").build(), HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"ports\": [{\"state\": \"DOWN\", \"id\": \"814ae4bb-33d9-425f-8ee2-13a5c90b1465\"}]}", APPLICATION_JSON)).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); - Set nets = api.list(); + Set nets = api.list().toImmutableSet(); assertEquals(nets, ImmutableSet.of(Port.builder().state(Port.State.DOWN).id("814ae4bb-33d9-425f-8ee2-13a5c90b1465").build())); } @@ -86,7 +86,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/1a104cf5-cb18-4d35-9407-2fd2646d9d0b/ports/detail").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "1a104cf5-cb18-4d35-9407-2fd2646d9d0b"); assertTrue(api.list().isEmpty()); } @@ -96,7 +96,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/646c123b-871a-4124-9fa2-a94f04a582df").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/port.json", APPLICATION_JSON)).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); Port port = api.get("646c123b-871a-4124-9fa2-a94f04a582df"); assertEquals(port, new ParsePortTest().expected()); @@ -107,7 +107,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/646c123b-871a-4124-9fa2-a94f04a582df").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertNull(api.get("646c123b-871a-4124-9fa2-a94f04a582df")); } @@ -117,7 +117,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/646c123b-871a-4124-9fa2-a94f04a582df/detail").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/port_details.json", APPLICATION_JSON)).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); PortDetails net = api.getDetails("646c123b-871a-4124-9fa2-a94f04a582df"); assertEquals(net, new ParsePortDetailsTest().expected()); @@ -128,7 +128,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/646c123b-871a-4124-9fa2-a94f04a582df/detail").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertNull(api.getDetails("646c123b-871a-4124-9fa2-a94f04a582df")); } @@ -138,7 +138,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports").method("POST").build(), HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"port\":{\"id\":\"12345\"}}", APPLICATION_JSON)).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); Reference port = api.create(); assertEquals(port, Reference.builder().id("12345").build()); @@ -150,7 +150,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports").method("POST").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); api.create(); } @@ -161,7 +161,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/77777").method("PUT") .payload(payloadFromStringWithContentType("{\"port\":{\"state\":\"ACTIVE\"}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(200).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertTrue(api.updateState("77777", Port.State.ACTIVE)); } @@ -173,7 +173,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/77777").method("PUT") .payload(payloadFromStringWithContentType("{\"port\":{\"state\":\"ACTIVE\"}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(401).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); api.updateState("77777", Port.State.ACTIVE); } @@ -183,7 +183,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/77777/attachment").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/attachment.json", APPLICATION_JSON)).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); Attachment attachment = api.showAttachment("77777"); assertEquals(attachment, Attachment.builder().id("jclouds-live-test").build()); @@ -194,7 +194,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/77777/attachment").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertNull(api.showAttachment("77777")); } @@ -206,7 +206,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { .payload(payloadFromStringWithContentType("{\"attachment\":{\"id\":\"jclouds-live-test\"}}", MediaType.APPLICATION_JSON)) .method("PUT").build(), HttpResponse.builder().statusCode(200).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertTrue(api.plugAttachment("77777", "jclouds-live-test")); } @@ -219,7 +219,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { .payload(payloadFromStringWithContentType("{\"attachment\":{\"id\":\"jclouds-live-test\"}}", MediaType.APPLICATION_JSON)) .method("PUT").build(), HttpResponse.builder().statusCode(403).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); api.plugAttachment("77777", "jclouds-live-test"); } @@ -228,7 +228,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/77777/attachment").method("DELETE").build(), HttpResponse.builder().statusCode(200).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); assertTrue(api.unplugAttachment("77777")); } @@ -239,7 +239,7 @@ public class PortApiExpectTest extends BaseQuantumApiExpectTest { keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint + "/tenants/3456/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a/ports/77777/attachment").method("DELETE").build(), HttpResponse.builder().statusCode(404).build()) - .getPortApiForRegionAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); + .getPortApiForZoneAndNetwork("region-a.geo-1", "16dba3bc-f3fa-4775-afdc-237e12c72f6a"); api.unplugAttachment("77777"); } diff --git a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiLiveTest.java b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiLiveTest.java index b179061fe0..baf37ffcc8 100644 --- a/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiLiveTest.java +++ b/labs/openstack-quantum/src/test/java/org/jclouds/openstack/quantum/v1_0/features/PortApiLiveTest.java @@ -44,13 +44,13 @@ import com.google.common.collect.Iterables; public class PortApiLiveTest extends BaseQuantumApiLiveTest { public void testListPorts() { - for (String regionId : quantumContext.getApi().getConfiguredRegions()) { - NetworkApi netApi = quantumContext.getApi().getNetworkApiForRegion(regionId); - Set nets = netApi.listReferences(); + for (String zoneId : quantumContext.getApi().getConfiguredZones()) { + NetworkApi netApi = quantumContext.getApi().getNetworkApiForZone(zoneId); + Set nets = netApi.listReferences().toImmutableSet(); for(Reference net : nets) { - PortApi portApi = quantumContext.getApi().getPortApiForRegionAndNetwork(regionId, net.getId()); - Set portRefs = portApi.listReferences(); - Set ports = portApi.list(); + PortApi portApi = quantumContext.getApi().getPortApiForZoneAndNetwork(zoneId, net.getId()); + Set portRefs = portApi.listReferences().toImmutableSet(); + Set ports = portApi.list().toImmutableSet(); assertEquals(portRefs.size(), ports.size()); for (Port port : ports) { @@ -61,11 +61,11 @@ public class PortApiLiveTest extends BaseQuantumApiLiveTest { } public void testCreateUpdateAndDeletePort() { - for (String regionId : quantumContext.getApi().getConfiguredRegions()) { - NetworkApi netApi = quantumContext.getApi().getNetworkApiForRegion(regionId); + for (String zoneId : quantumContext.getApi().getConfiguredZones()) { + NetworkApi netApi = quantumContext.getApi().getNetworkApiForZone(zoneId); Reference net = netApi.create("jclouds-port-test"); assertNotNull(net); - PortApi portApi = quantumContext.getApi().getPortApiForRegionAndNetwork(regionId, net.getId()); + PortApi portApi = quantumContext.getApi().getPortApiForZoneAndNetwork(zoneId, net.getId()); Reference portRef = portApi.create(); assertNotNull(portRef); @@ -109,12 +109,12 @@ public class PortApiLiveTest extends BaseQuantumApiLiveTest { @Test(enabled=false) // assuming attachmentId matters in the wild public void testAttachAndDetachPort() { - for (String regionId : quantumContext.getApi().getConfiguredRegions()) { - NetworkApi netApi = quantumContext.getApi().getNetworkApiForRegion(regionId); + for (String zoneId : quantumContext.getApi().getConfiguredZones()) { + NetworkApi netApi = quantumContext.getApi().getNetworkApiForZone(zoneId); Reference net = netApi.create("jclouds-attach-test"); assertNotNull(net); - PortApi portApi = quantumContext.getApi().getPortApiForRegionAndNetwork(regionId, net.getId()); + PortApi portApi = quantumContext.getApi().getPortApiForZoneAndNetwork(zoneId, net.getId()); Reference port = portApi.create(); assertNotNull(port); diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftRestClientModule.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftRestClientModule.java index a0489d09d5..fe022ae57b 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftRestClientModule.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftRestClientModule.java @@ -73,6 +73,7 @@ public class SwiftRestClientModule .put(ObjectApi.class, ObjectAsyncApi.class) .build(); + @SuppressWarnings("unchecked") public SwiftRestClientModule() { super(TypeToken.class.cast(TypeToken.of(SwiftApi.class)), TypeToken.class.cast(TypeToken.of(SwiftAsyncApi.class)), DELEGATE_MAP); } @@ -102,7 +103,7 @@ public class SwiftRestClientModule .build(new CacheLoader>() { @Override public Set load(String key) throws Exception { - return swiftApi.get().getExtensionApiForRegion(key).listExtensions(); + return swiftApi.get().getExtensionApiForRegion(key).list(); } }); } diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java similarity index 82% rename from labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java rename to labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java index b3e70dab84..db428965da 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java @@ -12,7 +12,7 @@ import com.google.common.base.Objects.ToStringHelper; * @author Adrian Cole * @see api doc */ -public class AccountMetadata { +public class Account { public static Builder builder() { return new Builder(); @@ -27,7 +27,7 @@ public class AccountMetadata { protected long bytesUsed; /** - * @see AccountMetadata#getContainerCount() + * @see Account#getContainerCount() */ public Builder containerCount(int containerCount) { this.containerCount = containerCount; @@ -35,18 +35,18 @@ public class AccountMetadata { } /** - * @see AccountMetadata#getBytesUsed() + * @see Account#getBytesUsed() */ public Builder bytesUsed(long bytesUsed) { this.bytesUsed = bytesUsed; return this; } - public AccountMetadata build() { - return new AccountMetadata(containerCount, bytesUsed); + public Account build() { + return new Account(containerCount, bytesUsed); } - public Builder fromAccountMetadata(AccountMetadata from) { + public Builder fromAccountMetadata(Account from) { return containerCount(from.getContainerCount()).bytesUsed(from.getBytesUsed()); } } @@ -55,7 +55,7 @@ public class AccountMetadata { protected long bytesUsed; @ConstructorProperties({"containerCount", "bytesUsed"}) - protected AccountMetadata(int containerCount, long bytesUsed) { + protected Account(int containerCount, long bytesUsed) { this.containerCount = containerCount; this.bytesUsed = bytesUsed; } @@ -80,8 +80,8 @@ public class AccountMetadata { if (this == object) { return true; } - if (object instanceof AccountMetadata) { - final AccountMetadata other = AccountMetadata.class.cast(object); + if (object instanceof Account) { + final Account other = Account.class.cast(object); return equal(getContainerCount(), other.getContainerCount()) && equal(getBytesUsed(), other.getBytesUsed()); } else { return false; diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java similarity index 81% rename from labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java rename to labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java index 1cbff854b0..ef459e6d62 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java @@ -19,14 +19,14 @@ import com.google.common.base.Objects.ToStringHelper; * href="http://docs.openstack.org/api/openstack-object-storage/1.0/content/s_listcontainers.html">api * doc */ -public class ContainerMetadata implements Comparable { +public class Container implements Comparable { public static Builder builder() { return new Builder(); } public Builder toBuilder() { - return builder().fromAccountMetadata(this); + return builder().fromContainer(this); } public static class Builder { @@ -35,7 +35,7 @@ public class ContainerMetadata implements Comparable { protected int bytes; /** - * @see ContainerMetadata#getName() + * @see Container#getName() */ public Builder name(String name) { this.name = checkNotNull(name, "name"); @@ -43,7 +43,7 @@ public class ContainerMetadata implements Comparable { } /** - * @see ContainerMetadata#getCount() + * @see Container#getCount() */ public Builder count(int count) { this.count = count; @@ -51,18 +51,18 @@ public class ContainerMetadata implements Comparable { } /** - * @see ContainerMetadata#getBytes() + * @see Container#getBytes() */ public Builder bytes(int bytes) { this.bytes = bytes; return this; } - public ContainerMetadata build() { - return new ContainerMetadata(name, count, bytes); + public Container build() { + return new Container(name, count, bytes); } - public Builder fromAccountMetadata(ContainerMetadata from) { + public Builder fromContainer(Container from) { return name(from.getName()).count(from.getCount()).bytes(from.getBytes()); } } @@ -72,7 +72,7 @@ public class ContainerMetadata implements Comparable { protected int bytes; @ConstructorProperties({"name", "count", "bytes"}) - protected ContainerMetadata(String name, int count, int bytes) { + protected Container(String name, int count, int bytes) { this.name = checkNotNull(name, "name"); this.count = count; this.bytes = bytes; @@ -106,8 +106,8 @@ public class ContainerMetadata implements Comparable { if (this == object) { return true; } - if (object instanceof ContainerMetadata) { - final ContainerMetadata other = ContainerMetadata.class.cast(object); + if (object instanceof Container) { + final Container other = Container.class.cast(object); return equal(getName(), other.getName()) && equal(getCount(), other.getCount()) && equal(getBytes(), other.getBytes()); } else { @@ -130,7 +130,7 @@ public class ContainerMetadata implements Comparable { } @Override - public int compareTo(ContainerMetadata that) { + public int compareTo(Container that) { if (that == null) return 1; if (this == that) diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java index 1cf2e2b664..78d8a31f04 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java @@ -18,13 +18,10 @@ */ package org.jclouds.openstack.swift.v1.features; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.openstack.swift.v1.domain.AccountMetadata; -import org.jclouds.openstack.swift.v1.domain.ContainerMetadata; -import org.jclouds.openstack.swift.v1.options.ListContainersOptions; +import org.jclouds.openstack.swift.v1.domain.Account; /** * Storage Account Services @@ -37,26 +34,12 @@ import org.jclouds.openstack.swift.v1.options.ListContainersOptions; */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface AccountApi { + /** * Retrieve Account Metadata * * @return account metadata including container count and bytes used */ - AccountMetadata getAccountMetadata(); - - /** - * @see #listContainers(ListContainersOptions) - */ - Set listContainers(); - - /** - * retrieve a list of existing storage containers ordered by name. The sort order for the name is - * based on a binary comparison, a single built-in collating sequence that compares string data - * using SQLite's memcmp() function, regardless of text encoding. - * - * @param options - * @return a list of existing storage containers ordered by name. - */ - Set listContainers(ListContainersOptions options); + Account get(); } diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountAsyncApi.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountAsyncApi.java index de64deef66..9473428a5b 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountAsyncApi.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountAsyncApi.java @@ -18,25 +18,15 @@ */ package org.jclouds.openstack.swift.v1.features; -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.HEAD; import javax.ws.rs.Path; -import javax.ws.rs.core.MediaType; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.v1.domain.AccountMetadata; -import org.jclouds.openstack.swift.v1.domain.ContainerMetadata; +import org.jclouds.openstack.swift.v1.domain.Account; import org.jclouds.openstack.swift.v1.functions.ParseAccountMetadataResponseFromHeaders; -import org.jclouds.openstack.swift.v1.options.ListContainersOptions; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -54,30 +44,11 @@ import com.google.common.util.concurrent.ListenableFuture; public interface AccountAsyncApi { /** - * @see AccountApi#getAccountMetadata + * @see AccountApi#get */ @HEAD @ResponseParser(ParseAccountMetadataResponseFromHeaders.class) @Path("/") - ListenableFuture getAccountMetadata(); + ListenableFuture get(); - /** - * @see AccountApi#listContainers() - */ - @GET - @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "format", values = "json") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - @Path("/") - ListenableFuture> listContainers(); - - /** - * @see AccountApi#listContainers(ListContainersOptions) - */ - @GET - @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "format", values = "json") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - @Path("/") - ListenableFuture> listContainers(ListContainersOptions options); } diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java index 7da668efc8..f87e2b4ad1 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java @@ -21,6 +21,10 @@ package org.jclouds.openstack.swift.v1.features; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.swift.v1.domain.Container; +import org.jclouds.openstack.swift.v1.options.ListContainersOptions; + +import com.google.common.collect.FluentIterable; /** * Storage Container Services @@ -34,4 +38,19 @@ import org.jclouds.concurrent.Timeout; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface ContainerApi { + /** + * @see #list(ListContainersOptions) + */ + FluentIterable list(); + + /** + * retrieve a list of existing storage containers ordered by name. The sort order for the name is + * based on a binary comparison, a single built-in collating sequence that compares string data + * using SQLite's memcmp() function, regardless of text encoding. + * + * @param options + * @return a list of existing storage containers ordered by name. + */ + FluentIterable list(ListContainersOptions options); + } diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerAsyncApi.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerAsyncApi.java index 996d6a2007..b5978b1088 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerAsyncApi.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerAsyncApi.java @@ -18,9 +18,22 @@ */ package org.jclouds.openstack.swift.v1.features; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.openstack.swift.v1.domain.Container; +import org.jclouds.openstack.swift.v1.options.ListContainersOptions; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; + +import com.google.common.collect.FluentIterable; +import com.google.common.util.concurrent.ListenableFuture; /** * Storage Container Services @@ -35,4 +48,23 @@ import org.jclouds.rest.annotations.SkipEncoding; @RequestFilters(AuthenticateRequest.class) public interface ContainerAsyncApi { + /** + * @see ContainerApi#list() + */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @QueryParams(keys = "format", values = "json") + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + @Path("/") + ListenableFuture> list(); + + /** + * @see ContainerApi#list(ListContainersOptions) + */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @QueryParams(keys = "format", values = "json") + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + @Path("/") + ListenableFuture> list(ListContainersOptions options); } diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountMetadataResponseFromHeaders.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountMetadataResponseFromHeaders.java index e01ccadfed..d0271e6966 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountMetadataResponseFromHeaders.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountMetadataResponseFromHeaders.java @@ -19,22 +19,22 @@ package org.jclouds.openstack.swift.v1.functions; import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.swift.v1.domain.AccountMetadata; +import org.jclouds.openstack.swift.v1.domain.Account; import com.google.common.base.Function; /** - * This parses {@link AccountMetadata} from HTTP headers. + * This parses {@link Account} from HTTP headers. * * @author James Murty */ -public class ParseAccountMetadataResponseFromHeaders implements Function { +public class ParseAccountMetadataResponseFromHeaders implements Function { /** - * parses the http response headers to create a new {@link AccountMetadata} object. + * parses the http response headers to create a new {@link Account} object. */ - public AccountMetadata apply(HttpResponse from) { - return AccountMetadata.builder() + public Account apply(HttpResponse from) { + return Account.builder() .bytesUsed(Long.parseLong(from.getFirstHeaderOrNull("X-Account-Bytes-Used"))) .containerCount(Integer.parseInt(from.getFirstHeaderOrNull("X-Account-Container-Count"))) .build(); diff --git a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/PasswordAuthenticationExpectTest.java b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/PasswordAuthenticationExpectTest.java index 1678c1499a..fa0006e92f 100644 --- a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/PasswordAuthenticationExpectTest.java +++ b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/PasswordAuthenticationExpectTest.java @@ -50,22 +50,22 @@ public class PasswordAuthenticationExpectTest extends BaseSwiftApiExpectTest { } public void testListContainersWhenResponseIs2xx() throws Exception { - HttpRequest listContainers = HttpRequest + HttpRequest list = HttpRequest .builder() .method("GET") .endpoint("https://objects.jclouds.org/v1.0/40806637803162/?format=json") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listContainersResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/container_list.json")).build(); SwiftApi apiWhenContainersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, - responseWithKeystoneAccess, listContainers, listContainersResponse); + responseWithKeystoneAccess, list, listResponse); assertEquals(apiWhenContainersExist.getConfiguredRegions(), ImmutableSet.of("region-a.geo-1")); - assertEquals(apiWhenContainersExist.getAccountApiForRegion("region-a.geo-1").listContainers().toString(), + assertEquals(apiWhenContainersExist.getContainerApiForRegion("region-a.geo-1").list().toString(), new ParseContainerListTest().expected().toString()); } diff --git a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiExpectTest.java b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiExpectTest.java index edf50af3e9..edffd00ebf 100644 --- a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiExpectTest.java +++ b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiExpectTest.java @@ -23,13 +23,10 @@ import static org.testng.Assert.assertEquals; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.AccountMetadata; +import org.jclouds.openstack.swift.v1.domain.Account; import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiExpectTest; -import org.jclouds.openstack.swift.v1.parse.ParseContainerListTest; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; - /** * @author Adrian Cole */ @@ -38,59 +35,23 @@ public class AccountApiExpectTest extends BaseSwiftApiExpectTest { public void testGetAccountMetadataWhenResponseIs2xx() throws Exception { - HttpRequest getAccountMetadata = HttpRequest + HttpRequest get = HttpRequest .builder() .method("HEAD") .endpoint("https://objects.jclouds.org/v1.0/40806637803162/") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listContainersResponse = HttpResponse.builder().statusCode(204) + HttpResponse listResponse = HttpResponse.builder().statusCode(204) .addHeader("X-Account-Container-Count", "3") .addHeader("X-Account-Bytes-Used", "323479").build(); - SwiftApi apiWhenContainersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, - responseWithKeystoneAccess, getAccountMetadata, listContainersResponse); + SwiftApi apiWhenExists = requestsSendResponses(keystoneAuthWithUsernameAndPassword, + responseWithKeystoneAccess, get, listResponse); assertEquals( - apiWhenContainersExist.getAccountApiForRegion("region-a.geo-1").getAccountMetadata(), - AccountMetadata.builder().containerCount(3).bytesUsed(323479).build()); + apiWhenExists.getAccountApiForRegion("region-a.geo-1").get(), + Account.builder().containerCount(3).bytesUsed(323479).build()); } - public void testListContainersWhenResponseIs2xx() throws Exception { - - HttpRequest listContainers = HttpRequest - .builder() - .method("GET") - .endpoint("https://objects.jclouds.org/v1.0/40806637803162/?format=json") - .addHeader("Accept", "application/json") - .addHeader("X-Auth-Token", authToken).build(); - - HttpResponse listContainersResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/container_list.json")).build(); - - SwiftApi apiWhenContainersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, - responseWithKeystoneAccess, listContainers, listContainersResponse); - - assertEquals( - apiWhenContainersExist.getAccountApiForRegion("region-a.geo-1").listContainers() - .toString(), new ParseContainerListTest().expected().toString()); - } - - public void testListContainersWhenResponseIs404() throws Exception { - HttpRequest listContainers = HttpRequest - .builder() - .method("GET") - .endpoint("https://objects.jclouds.org/v1.0/40806637803162/?format=json") - .addHeader("Accept", "application/json") - .addHeader("X-Auth-Token", authToken).build(); - - HttpResponse listContainersResponse = HttpResponse.builder().statusCode(404).build(); - - SwiftApi apiWhenNoContainersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, - responseWithKeystoneAccess, listContainers, listContainersResponse); - - assertEquals(apiWhenNoContainersExist.getAccountApiForRegion("region-a.geo-1").listContainers(), ImmutableSet.of()); - - } } diff --git a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java index 8521c0e236..6232d6dbdf 100644 --- a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java +++ b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java @@ -21,10 +21,7 @@ package org.jclouds.openstack.swift.v1.features; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.util.Set; - -import org.jclouds.openstack.swift.v1.domain.AccountMetadata; -import org.jclouds.openstack.swift.v1.domain.ContainerMetadata; +import org.jclouds.openstack.swift.v1.domain.Account; import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; import org.testng.annotations.Test; @@ -38,24 +35,11 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest { public void testGetAccountMetadata() throws Exception { for (String regionId : swiftContext.getApi().getConfiguredRegions()) { AccountApi api = swiftContext.getApi().getAccountApiForRegion(regionId); - AccountMetadata account = api.getAccountMetadata(); + Account account = api.get(); assertNotNull(account); assertTrue(account.getContainerCount() >= 0); assertTrue(account.getBytesUsed() >= 0); } } - @Test - public void testListContainers() throws Exception { - for (String regionId : swiftContext.getApi().getConfiguredRegions()) { - AccountApi api = swiftContext.getApi().getAccountApiForRegion(regionId); - Set response = api.listContainers(); - assertNotNull(response); - for (ContainerMetadata container : response) { - assertNotNull(container.getName()); - assertTrue(container.getCount() >= 0); - assertTrue(container.getBytes() >= 0); - } - } - } } diff --git a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiExpectTest.java b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiExpectTest.java index 0982343a51..eec3a43d2e 100644 --- a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiExpectTest.java +++ b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiExpectTest.java @@ -18,14 +18,59 @@ */ package org.jclouds.openstack.swift.v1.features; +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.v1.SwiftApi; import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiExpectTest; +import org.jclouds.openstack.swift.v1.parse.ParseContainerListTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + /** * * @author Adrian Cole */ @Test(groups = "unit", testName = "ContainerAsyncApiTest") public class ContainerApiExpectTest extends BaseSwiftApiExpectTest { + public void testListContainersWhenResponseIs2xx() throws Exception { + + HttpRequest list = HttpRequest + .builder() + .method("GET") + .endpoint("https://objects.jclouds.org/v1.0/40806637803162/?format=json") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/container_list.json")).build(); + + SwiftApi apiWhenContainersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, + responseWithKeystoneAccess, list, listResponse); + + assertEquals( + apiWhenContainersExist.getContainerApiForRegion("region-a.geo-1").list() + .toString(), new ParseContainerListTest().expected().toString()); + } + + public void testListContainersWhenResponseIs404() throws Exception { + HttpRequest list = HttpRequest + .builder() + .method("GET") + .endpoint("https://objects.jclouds.org/v1.0/40806637803162/?format=json") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); + + SwiftApi apiWhenNoContainersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, + responseWithKeystoneAccess, list, listResponse); + + assertEquals(apiWhenNoContainersExist.getContainerApiForRegion("region-a.geo-1").list().toImmutableSet(), + ImmutableSet.of()); + + } } diff --git a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java index 909e8bdefc..031ef21dab 100644 --- a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java +++ b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java @@ -18,9 +18,15 @@ */ package org.jclouds.openstack.swift.v1.features; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.openstack.swift.v1.domain.Container; import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; + /** * * @author Adrian Cole @@ -28,4 +34,17 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "ContainerApiLiveTest") public class ContainerApiLiveTest extends BaseSwiftApiLiveTest { + @Test + public void testListContainers() throws Exception { + for (String regionId : swiftContext.getApi().getConfiguredRegions()) { + ContainerApi api = swiftContext.getApi().getContainerApiForRegion(regionId); + FluentIterable response = api.list(); + assertNotNull(response); + for (Container container : response) { + assertNotNull(container.getName()); + assertTrue(container.getCount() >= 0); + assertTrue(container.getBytes() >= 0); + } + } + } } diff --git a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/parse/ParseContainerListTest.java b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/parse/ParseContainerListTest.java index 3c583121c4..7cc36c3aab 100644 --- a/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/parse/ParseContainerListTest.java +++ b/labs/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/parse/ParseContainerListTest.java @@ -24,7 +24,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.core.MediaType; import org.jclouds.json.BaseSetParserTest; -import org.jclouds.openstack.swift.v1.domain.ContainerMetadata; +import org.jclouds.openstack.swift.v1.domain.Container; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "unit", testName = "ParseContainerListTest") -public class ParseContainerListTest extends BaseSetParserTest { +public class ParseContainerListTest extends BaseSetParserTest { @Override public String resource() { @@ -43,14 +43,14 @@ public class ParseContainerListTest extends BaseSetParserTest @Override @Consumes(MediaType.APPLICATION_JSON) - public Set expected() { + public Set expected() { return ImmutableSet - .of(ContainerMetadata.builder() + .of(Container.builder() .name("test_container_1") .count(2) .bytes(78) .build(), - ContainerMetadata.builder() + Container.builder() .name("test_container_2") .count(1) .bytes(17) diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApi.java similarity index 79% rename from providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java rename to providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApi.java index 92dc16c51c..80395a11c8 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApi.java @@ -18,15 +18,18 @@ */ package org.jclouds.hpcloud.objectstorage; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient; +import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerApi; +import org.jclouds.location.Region; import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.rest.annotations.Delegate; import com.google.common.base.Optional; import com.google.common.util.concurrent.ListenableFuture; +import com.google.inject.Provides; /** * Provides synchronous access to HP Cloud Object Storage via the REST API. @@ -36,17 +39,24 @@ import com.google.common.util.concurrent.ListenableFuture; * will be backend in an {@link java.util.concurrent.ExecutionException} as documented in * {@link ListenableFuture#get()}. * - * @see org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient + * @see HPCloudObjectStorageAsyncApi * @see HP Cloud Object * Storage API * @author Jeremy Daggett */ @Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) -public interface HPCloudObjectStorageClient extends CommonSwiftClient { +public interface HPCloudObjectStorageApi extends CommonSwiftClient { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); /** * Provides synchronous access to CDN features. */ @Delegate - Optional getCDNExtension(); + Optional getCDNExtension(); } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java index 522bd4c164..4586f48b19 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java @@ -42,7 +42,7 @@ public class HPCloudObjectStorageApiMetadata extends SwiftKeystoneApiMetadata { /** The serialVersionUID */ private static final long serialVersionUID = 820062881469203616L; - public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { private static final long serialVersionUID = -5070937833892503232L; }; @@ -70,7 +70,7 @@ public class HPCloudObjectStorageApiMetadata extends SwiftKeystoneApiMetadata { public static class Builder extends SwiftKeystoneApiMetadata.Builder { protected Builder(){ - super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class); + super(HPCloudObjectStorageApi.class, HPCloudObjectStorageAsyncApi.class); id("hpcloud-objectstorage") .endpointName("identity service url ending in /v2.0/") .defaultEndpoint("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/") diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncApi.java similarity index 85% rename from providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java rename to providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncApi.java index ae49064228..19b647516b 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncApi.java @@ -27,7 +27,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; -import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNAsyncClient; +import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerAsyncApi; +import org.jclouds.location.Region; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.Storage; @@ -43,6 +44,7 @@ import org.jclouds.rest.annotations.SkipEncoding; import com.google.common.base.Optional; import com.google.common.util.concurrent.ListenableFuture; +import com.google.inject.Provides; /** * Provides asynchronous access to HP Cloud Object Storage via the REST API. @@ -52,7 +54,7 @@ import com.google.common.util.concurrent.ListenableFuture; * will be backend in an {@link java.util.concurrent.ExecutionException} as documented in * {@link ListenableFuture#get()}. * - * @see HPCloudObjectStorageClient + * @see HPCloudObjectStorageApi * @see HP Cloud Object * Storage API * @author Jeremy Daggett @@ -60,7 +62,14 @@ import com.google.common.util.concurrent.ListenableFuture; @SkipEncoding('/') @RequestFilters(AuthenticateRequest.class) @Endpoint(Storage.class) -public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient { +public interface HPCloudObjectStorageAsyncApi extends CommonSwiftAsyncClient { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); /** * @see org.jclouds.openstack.swift.CommonSwiftClient#listContainers @@ -80,9 +89,9 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient ListenableFuture deleteContainerIfEmpty(@PathParam("container") String container); /** - * Provides synchronous access to CDN features. + * Provides asynchronous access to CDN features. */ @Delegate - Optional getCDNExtension(); + Optional getCDNExtension(); } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java index 847eb686ea..15f95a099b 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java @@ -35,8 +35,8 @@ import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.collect.Memoized; import org.jclouds.concurrent.Futures; import org.jclouds.domain.Location; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncClient; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; import org.jclouds.hpcloud.objectstorage.blobstore.functions.EnableCDNAndCache; import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; @@ -57,22 +57,22 @@ import com.google.common.util.concurrent.ListenableFuture; */ @Singleton public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore { - private final EnableCDNAndCache enableCDNAndCache; + private final EnableCDNAndCache enableAndCache; @Inject protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, - @Memoized Supplier> locations, HPCloudObjectStorageClient sync, HPCloudObjectStorageAsyncClient async, + @Memoized Supplier> locations, HPCloudObjectStorageApi sync, HPCloudObjectStorageAsyncApi async, ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, - Provider fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache, + Provider fetchBlobMetadataProvider, EnableCDNAndCache enableAndCache, Provider multipartUploadStrategy) { super(context, blobUtils, service, defaultLocation, locations, sync, async, container2ResourceMd, container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy); - this.enableCDNAndCache = enableCDNAndCache; + this.enableAndCache = enableAndCache; } @Override @@ -86,7 +86,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore { @Override public Boolean apply(Boolean input) { if (Boolean.TRUE.equals(input)) { - return enableCDNAndCache.apply(container) != null; + return enableAndCache.apply(container) != null; } return false; } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java index 556ff74416..b2f6ffa392 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java @@ -11,7 +11,7 @@ import javax.inject.Singleton; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.functions.BlobToHttpGetOptions; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi; import org.jclouds.http.HttpRequest; import org.jclouds.http.options.GetOptions; import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; @@ -23,7 +23,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; */ @Singleton public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner { - private final RestAnnotationProcessor processor; + private final RestAnnotationProcessor processor; private final BlobToObject blobToObject; private final BlobToHttpGetOptions blob2HttpGetOptions; @@ -32,15 +32,15 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner private final Method createMethod; @Inject - public HPCloudObjectStorageBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, + public HPCloudObjectStorageBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); - this.getMethod = HPCloudObjectStorageAsyncClient.class.getMethod("getObject", String.class, String.class, + this.getMethod = HPCloudObjectStorageAsyncApi.class.getMethod("getObject", String.class, String.class, GetOptions[].class); - this.deleteMethod = HPCloudObjectStorageAsyncClient.class.getMethod("removeObject", String.class, String.class); - this.createMethod = HPCloudObjectStorageAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); + this.deleteMethod = HPCloudObjectStorageAsyncApi.class.getMethod("removeObject", String.class, String.class); + this.createMethod = HPCloudObjectStorageAsyncApi.class.getMethod("putObject", String.class, SwiftObject.class); } @Override diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java index 365cb294d0..eeb058c439 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java @@ -31,7 +31,7 @@ import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.collect.Memoized; import org.jclouds.domain.Location; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; import org.jclouds.hpcloud.objectstorage.blobstore.functions.EnableCDNAndCache; import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; @@ -51,21 +51,21 @@ import com.google.common.base.Supplier; @Singleton public class HPCloudObjectStorageBlobStore extends SwiftBlobStore { - private EnableCDNAndCache enableCDNAndCache; + private EnableCDNAndCache enableAndCache; @Inject protected HPCloudObjectStorageBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, - HPCloudObjectStorageClient sync, ContainerToResourceMetadata container2ResourceMd, + HPCloudObjectStorageApi sync, ContainerToResourceMetadata container2ResourceMd, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, - Provider fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache, + Provider fetchBlobMetadataProvider, EnableCDNAndCache enableAndCache, Provider multipartUploadStrategy) { super(context, blobUtils, defaultLocation, locations, sync, container2ResourceMd, container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy); - this.enableCDNAndCache = enableCDNAndCache; + this.enableAndCache = enableAndCache; } @@ -75,7 +75,7 @@ public class HPCloudObjectStorageBlobStore extends SwiftBlobStore { return createContainerInLocation(location, container); } finally { if (options.isPublicRead()) - enableCDNAndCache.apply(container); + enableAndCache.apply(container); } } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java index bfc73bd50e..5b91f497d7 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java @@ -33,13 +33,13 @@ import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.config.BlobStoreMapModule; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageAsyncBlobStore; import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobRequestSigner; import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobStore; import org.jclouds.hpcloud.objectstorage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata; -import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; -import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient; +import org.jclouds.hpcloud.objectstorage.domain.CDNContainer; +import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerApi; import org.jclouds.http.HttpResponseException; import org.jclouds.logging.Logger; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; @@ -64,19 +64,19 @@ public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreCo @Resource protected Logger logger = Logger.NULL; - private final HPCloudObjectStorageClient client; + private final HPCloudObjectStorageApi client; @Inject - public GetCDNMetadata(HPCloudObjectStorageClient client) { + public GetCDNMetadata(HPCloudObjectStorageApi client) { this.client = client; } @Override public URI load(String container) { - Optional cdnExtension = client.getCDNExtension(); + Optional cdnExtension = client.getCDNExtension(); checkArgument(cdnExtension.isPresent(), "CDN is required, but the extension is not available!"); try { - ContainerCDNMetadata md = cdnExtension.get().getCDNMetadata(container); + CDNContainer md = cdnExtension.get().get(container); return md != null ? md.getCDNUri() : null; } catch (HttpResponseException e) { // TODO: this is due to beta status @@ -90,7 +90,7 @@ public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreCo @Override public String toString() { - return "getCDNMetadata()"; + return "get()"; } } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java index c24d3f4d80..74c7585a1c 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java @@ -25,8 +25,8 @@ import java.net.URI; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; -import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; +import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerApi; import com.google.common.base.Function; import com.google.common.base.Optional; @@ -39,19 +39,19 @@ import com.google.common.cache.LoadingCache; @Singleton public class EnableCDNAndCache implements Function { private final LoadingCache cdnContainer; - private final HPCloudObjectStorageClient sync; + private final HPCloudObjectStorageApi sync; @Inject - public EnableCDNAndCache(HPCloudObjectStorageClient sync, LoadingCache cdnContainer) { + public EnableCDNAndCache(HPCloudObjectStorageApi sync, LoadingCache cdnContainer) { this.sync = sync; this.cdnContainer = cdnContainer; } @Override public URI apply(String input) { - Optional cdnExtension = sync.getCDNExtension(); + Optional cdnExtension = sync.getCDNExtension(); checkArgument(cdnExtension.isPresent(), "CDN is required, but the extension is not available!"); - URI uri = cdnExtension.get().enableCDN(input); + URI uri = cdnExtension.get().enable(input); cdnContainer.put(input, uri); return uri; } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java index 38fc722774..dc28e2fb72 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java @@ -25,10 +25,10 @@ import java.util.Map; import javax.inject.Singleton; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncClient; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; -import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNAsyncClient; -import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; +import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerAsyncApi; +import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerApi; import org.jclouds.hpcloud.services.HPExtensionCDN; import org.jclouds.hpcloud.services.HPExtensionServiceType; import org.jclouds.location.suppliers.RegionIdToURISupplier; @@ -50,18 +50,18 @@ import com.google.inject.Scopes; */ @ConfiguresRestClient public class HPCloudObjectStorageRestClientModule extends - SwiftRestClientModule { + SwiftRestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder().put( - HPCloudCDNClient.class, HPCloudCDNAsyncClient.class).build(); + CDNContainerApi.class, CDNContainerAsyncApi.class).build(); public HPCloudObjectStorageRestClientModule() { - super(TypeToken.of(HPCloudObjectStorageClient.class), TypeToken.of(HPCloudObjectStorageAsyncClient.class), + super(TypeToken.of(HPCloudObjectStorageApi.class), TypeToken.of(HPCloudObjectStorageAsyncApi.class), DELEGATE_MAP); } protected void bindResolvedClientsToCommonSwift() { - bind(CommonSwiftClient.class).to(HPCloudObjectStorageClient.class).in(Scopes.SINGLETON); - bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncClient.class).in(Scopes.SINGLETON); + bind(CommonSwiftClient.class).to(HPCloudObjectStorageApi.class).in(Scopes.SINGLETON); + bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncApi.class).in(Scopes.SINGLETON); } @Provides diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/CDNContainer.java similarity index 54% rename from providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java rename to providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/CDNContainer.java index b931ded516..832b276e31 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/CDNContainer.java @@ -24,23 +24,20 @@ import java.net.URI; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; +import com.google.common.base.Strings; import com.google.common.base.Objects.ToStringHelper; -/** - * @author James Murty - */ -public class ContainerCDNMetadata implements Comparable { +public class CDNContainer implements Comparable { - public static Builder builder() { - return new ConcreteBuilder(); + public static Builder builder() { + return new Builder(); } - public Builder toBuilder() { - return new ConcreteBuilder().fromContainerCDNMetadata(this); + public Builder toBuilder() { + return builder().fromCDNContainer(this); } - public static abstract class Builder> { - protected abstract T self(); + public static class Builder { protected String name; protected boolean cdnEnabled; @@ -51,82 +48,70 @@ public class ContainerCDNMetadata implements Comparable { protected boolean logRetention; /** - * @see ContainerCDNMetadata#getName() + * @see CDNContainer#getName() */ - public T name(String name) { + public Builder name(String name) { this.name = name; - return self(); - } - - /** - * @see ContainerCDNMetadata#isCDNEnabled() - */ - public T CDNEnabled(boolean cdnEnabled) { - this.cdnEnabled = cdnEnabled; - return self(); - } - - /** - * @see ContainerCDNMetadata#getTTL - */ - public T ttl(long ttl) { - this.ttl = ttl; - return self(); - } - - /** - * @see ContainerCDNMetadata#getCDNUri() - */ - public T CDNUri(URI CDNUri) { - this.CDNUri = CDNUri; - return self(); - } - - /** - * @see ContainerCDNMetadata#getReferrerAcl() - */ - public T referrerAcl(String referrerAcl) { - this.referrerAcl = referrerAcl; - return self(); - } - - /** - * @see ContainerCDNMetadata#getUseragentAcl() - */ - public T useragent_acl(String useragentAcl) { - this.useragentAcl = useragentAcl; - return self(); - } - - /** - * @see ContainerCDNMetadata#isLogRetention() - */ - public T logRetention(boolean logRetention) { - this.logRetention = logRetention; - return self(); - } - - public ContainerCDNMetadata build() { - return new ContainerCDNMetadata(name, cdnEnabled, ttl, CDNUri, referrerAcl, useragentAcl, logRetention); - } - - public T fromContainerCDNMetadata(ContainerCDNMetadata in) { - return this - .name(in.getName()) - .CDNEnabled(in.isCDNEnabled()) - .ttl(in.getTTL()) - .CDNUri(in.getCDNUri()) - .referrerAcl(in.getReferrerAcl()) - .useragent_acl(in.getUseragentAcl()) - .logRetention(in.isLogRetention()); - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { return this; } + + /** + * @see CDNContainer#isCDNEnabled() + */ + public Builder CDNEnabled(boolean cdnEnabled) { + this.cdnEnabled = cdnEnabled; + return this; + } + + /** + * @see CDNContainer#getTTL + */ + public Builder ttl(long ttl) { + this.ttl = ttl; + return this; + } + + /** + * @see CDNContainer#getCDNUri() + */ + public Builder CDNUri(URI CDNUri) { + this.CDNUri = CDNUri; + return this; + } + + /** + * @see CDNContainer#getReferrerAcl() + */ + public Builder referrerAcl(String referrerAcl) { + this.referrerAcl = referrerAcl; + return this; + } + + /** + * @see CDNContainer#getUseragentAcl() + */ + public Builder useragent_acl(String useragentAcl) { + this.useragentAcl = useragentAcl; + return this; + } + + /** + * @see CDNContainer#isLogRetention() + */ + public Builder logRetention(boolean logRetention) { + this.logRetention = logRetention; + return this; + } + + public CDNContainer build() { + return new CDNContainer(name, cdnEnabled, ttl, CDNUri, referrerAcl, useragentAcl, logRetention); + } + + public Builder fromCDNContainer(CDNContainer in) { + return this.name(in.getName()).CDNEnabled(in.isCDNEnabled()).ttl(in.getTTL()).CDNUri(in.getCDNUri()) + .referrerAcl(in.getReferrerAcl()).useragent_acl(in.getUseragentAcl()) + .logRetention(in.isLogRetention()); + } } private final String name; @@ -137,23 +122,21 @@ public class ContainerCDNMetadata implements Comparable { private final String useragentAcl; private final boolean logRetention; - @ConstructorProperties({ - "name", "cdn_enabled", "ttl", "x-cdn-uri", "referrer_acl", "useragent_acl", "log_retention" - }) - protected ContainerCDNMetadata(@Nullable String name, boolean cdnEnabled, long ttl, @Nullable URI CDNUri, - @Nullable String referrerAcl, @Nullable String useragentAcl, boolean logRetention) { - this.name = name; + @ConstructorProperties({ "name", "cdn_enabled", "ttl", "cdn_uri", "referrer_acl", "useragent_acl", "log_retention" }) + protected CDNContainer(@Nullable String name, boolean cdnEnabled, long ttl, @Nullable URI CDNUri, + @Nullable String referrerAcl, @Nullable String useragentAcl, boolean logRetention) { + this.name = Strings.emptyToNull(name); this.cdnEnabled = cdnEnabled; this.ttl = ttl; this.CDNUri = CDNUri; - this.referrerAcl = referrerAcl; - this.useragentAcl = useragentAcl; + this.referrerAcl = Strings.emptyToNull(referrerAcl); + this.useragentAcl = Strings.emptyToNull(useragentAcl); this.logRetention = logRetention; } /** * Beware: The container name is not available from HEAD CDN responses and will be null. - * + * * @return the name of the container to which these CDN settings apply. */ @Nullable @@ -195,16 +178,18 @@ public class ContainerCDNMetadata implements Comparable { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ContainerCDNMetadata that = ContainerCDNMetadata.class.cast(obj); + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + CDNContainer that = CDNContainer.class.cast(obj); return Objects.equal(this.name, that.name) && Objects.equal(this.CDNUri, that.CDNUri); } protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("name", name).add("cdnEnabled", cdnEnabled).add("ttl", ttl).add("CDNUri", CDNUri) - .add("referrerAcl", referrerAcl).add("useragentAcl", useragentAcl).add("logRetention", logRetention); + return Objects.toStringHelper(this).omitNullValues().add("name", name).add("cdnEnabled", cdnEnabled) + .add("ttl", ttl).add("CDNUri", CDNUri).add("referrerAcl", referrerAcl).add("useragentAcl", useragentAcl) + .add("logRetention", logRetention); } @Override @@ -212,7 +197,7 @@ public class ContainerCDNMetadata implements Comparable { return string().toString(); } - public int compareTo(ContainerCDNMetadata o) { + public int compareTo(CDNContainer o) { if (getName() == null) return -1; return (this == o) ? 0 : getName().compareTo(o.getName()); diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/HPCloudCDNClient.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/CDNContainerApi.java similarity index 74% rename from providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/HPCloudCDNClient.java rename to providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/CDNContainerApi.java index d55090ae3b..a659fa14ee 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/HPCloudCDNClient.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/CDNContainerApi.java @@ -19,14 +19,14 @@ package org.jclouds.hpcloud.objectstorage.extensions; import java.net.URI; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.domain.CDNContainer; import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions; import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -36,30 +36,28 @@ import com.google.common.util.concurrent.ListenableFuture; * All commands return a ListenableFuture of the result. Any exceptions incurred during processing * will be backend in an {@link java.util.concurrent.ExecutionException} as documented in {@link ListenableFuture#get()}. * - * @see org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient + * @see org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi * @see HP Cloud Object * Storage API + * @see CDNContainerAsyncApi * @author Jeremy Daggett */ +@Beta @Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) -public interface HPCloudCDNClient { - - @Beta - Set listCDNContainers(ListCDNContainerOptions... options); - - @Beta - ContainerCDNMetadata getCDNMetadata(String container); - - @Beta - URI enableCDN(String container, long ttl); - - @Beta - URI enableCDN(String container); - - @Beta - URI updateCDN(String container, long ttl); +public interface CDNContainerApi { - @Beta - boolean disableCDN(String container); + FluentIterable list(); + + FluentIterable list(ListCDNContainerOptions options); + + CDNContainer get(String container); + + URI enable(String container, long ttl); + + URI enable(String container); + + URI update(String container, long ttl); + + boolean disable(String container); } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/HPCloudCDNAsyncClient.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/CDNContainerAsyncApi.java similarity index 60% rename from providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/HPCloudCDNAsyncClient.java rename to providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/CDNContainerAsyncApi.java index c61019d5b0..554c19dbc2 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/HPCloudCDNAsyncClient.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/extensions/CDNContainerAsyncApi.java @@ -19,7 +19,6 @@ package org.jclouds.hpcloud.objectstorage.extensions; import java.net.URI; -import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -32,10 +31,10 @@ import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; -import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; -import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; +import org.jclouds.hpcloud.objectstorage.domain.CDNContainer; +import org.jclouds.hpcloud.objectstorage.functions.ParseCDNContainerFromHeaders; import org.jclouds.hpcloud.objectstorage.functions.ParseCDNUriFromHeaders; -import org.jclouds.hpcloud.objectstorage.functions.ParseContainerCDNMetadataFromHeaders; import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions; import org.jclouds.hpcloud.objectstorage.reference.HPCloudObjectStorageHeaders; import org.jclouds.hpcloud.services.HPExtensionCDN; @@ -47,84 +46,99 @@ import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** * Provides asynchronous access to HP Cloud Object Storage via the REST API. * - *

All commands return a ListenableFuture of the result. Any exceptions incurred - * during processing will be backend in an {@link java.util.concurrent.ExecutionException} as documented in + *

+ * All commands return a ListenableFuture of the result. Any exceptions incurred during processing + * will be backend in an {@link java.util.concurrent.ExecutionException} as documented in * {@link ListenableFuture#get()}. * - * @see HPCloudObjectStorageClient - * @see HP Cloud Object Storage API + * @see HPCloudObjectStorageApi + * @see HP Cloud Object + * Storage API * @author Jeremy Daggett */ @SkipEncoding('/') @RequestFilters(AuthenticateRequest.class) @Endpoint(HPExtensionCDN.class) -public interface HPCloudCDNAsyncClient { - +public interface CDNContainerAsyncApi { /** - * @see HPCloudObjectStorageClient#listCDNContainers(ListCDNContainerOptions...) + * @see HPCloudObjectStorageApi#list() */ @Beta @GET @Consumes(MediaType.APPLICATION_JSON) @QueryParams(keys = "format", values = "json") + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) @Path("/") - ListenableFuture> listCDNContainers(ListCDNContainerOptions... options); - + ListenableFuture> list(); + /** - * @see HPCloudObjectStorageClient#getCDNMetadata(String) + * @see HPCloudObjectStorageApi#list(ListCDNContainerOptions) + */ + @Beta + @GET + @Consumes(MediaType.APPLICATION_JSON) + @QueryParams(keys = "format", values = "json") + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + @Path("/") + ListenableFuture> list(ListCDNContainerOptions options); + + /** + * @see HPCloudObjectStorageApi#get(String) */ @Beta @HEAD - @ResponseParser(ParseContainerCDNMetadataFromHeaders.class) + @ResponseParser(ParseCDNContainerFromHeaders.class) @ExceptionParser(ReturnNullOnContainerNotFound.class) @Path("/{container}") - ListenableFuture getCDNMetadata(@PathParam("container") String container); + ListenableFuture get(@PathParam("container") String container); /** - * @see HPCloudObjectStorageClient#enableCDN(String, long) + * @see HPCloudObjectStorageApi#enable(String, long) */ @Beta @PUT @Path("/{container}") @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True") @ResponseParser(ParseCDNUriFromHeaders.class) - ListenableFuture enableCDN(@PathParam("container") String container, - @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); + ListenableFuture enable(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); /** - * @see HPCloudObjectStorageClient#enableCDN(String) + * @see HPCloudObjectStorageApi#enable(String) */ @Beta @PUT @Path("/{container}") @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True") @ResponseParser(ParseCDNUriFromHeaders.class) - ListenableFuture enableCDN(@PathParam("container") String container); + ListenableFuture enable(@PathParam("container") String container); /** - * @see HPCloudObjectStorageClient#updateCDN(String, long) + * @see HPCloudObjectStorageApi#update(String, long) */ @Beta @POST @Path("/{container}") @ResponseParser(ParseCDNUriFromHeaders.class) - ListenableFuture updateCDN(@PathParam("container") String container, - @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); + ListenableFuture update(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); /** - * @see HPCloudObjectStorageClient#disableCDN(String) + * @see HPCloudObjectStorageApi#disable(String) */ @Beta @PUT @Path("/{container}") @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False") - ListenableFuture disableCDN(@PathParam("container") String container); + ListenableFuture disable(@PathParam("container") String container); } diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseCDNContainerFromHeaders.java similarity index 81% rename from providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.java rename to providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseCDNContainerFromHeaders.java index 386cb00ce6..96e63f0c07 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseCDNContainerFromHeaders.java @@ -24,7 +24,7 @@ import static com.google.common.collect.Lists.newArrayList; import java.net.URI; import java.util.List; -import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.domain.CDNContainer; import org.jclouds.hpcloud.objectstorage.reference.HPCloudObjectStorageHeaders; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -39,15 +39,15 @@ import com.google.common.base.Splitter; * * @author James Murty */ -public class ParseContainerCDNMetadataFromHeaders implements - Function, InvocationContext { +public class ParseCDNContainerFromHeaders implements + Function, InvocationContext { private HttpRequest request; /** - * parses the http response headers to create a new {@link ContainerCDNMetadata} object. + * parses the http response headers to create a new {@link CDNContainer} object. */ - public ContainerCDNMetadata apply(final HttpResponse from) { + public CDNContainer apply(final HttpResponse from) { String cdnUri = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_URI), HPCloudObjectStorageHeaders.CDN_URI); String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_TTL), @@ -61,14 +61,14 @@ public class ParseContainerCDNMetadataFromHeaders implements // just need the name from the path List parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath())); - return ContainerCDNMetadata.builder().name(parts.get(parts.size() - 1)) + return CDNContainer.builder().name(parts.get(parts.size() - 1)) .CDNEnabled(Boolean.parseBoolean(cdnEnabled)).ttl(Long.parseLong(cdnTTL)).CDNUri(URI.create(cdnUri)) .build(); } } @Override - public ParseContainerCDNMetadataFromHeaders setContext(HttpRequest request) { + public ParseCDNContainerFromHeaders setContext(HttpRequest request) { this.request = request; return this; } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java index 36b7256355..ccb1918f23 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java @@ -22,27 +22,28 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import java.net.URI; -import java.util.Set; -import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.domain.CDNContainer; import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions; import org.jclouds.openstack.swift.CommonSwiftClientLiveTest; import org.jclouds.openstack.swift.domain.SwiftObject; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; + /** * * @author Adrian Cole */ @Test(groups = "live", testName = "HPCloudObjectStorageClientLiveTest") -public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { +public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { public HPCloudObjectStorageClientLiveTest(){ provider = "hpcloud-objectstorage"; } @Override - public HPCloudObjectStorageClient getApi() { + public HPCloudObjectStorageApi getApi() { return view.unwrap(HPCloudObjectStorageApiMetadata.CONTEXT_TOKEN).getApi(); } @@ -61,49 +62,49 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes final String containerNameWithoutCDN = getContainerName(); try { try { - getApi().getCDNExtension().get().disableCDN(containerNameWithCDN); - getApi().getCDNExtension().get().disableCDN(containerNameWithoutCDN); + getApi().getCDNExtension().get().disable(containerNameWithCDN); + getApi().getCDNExtension().get().disable(containerNameWithoutCDN); } catch (Exception e) { e.printStackTrace(); } - ContainerCDNMetadata cdnMetadata = null; + CDNContainer cdnMetadata = null; // Enable CDN with PUT for one container - final URI cdnUri = getApi().getCDNExtension().get().enableCDN(containerNameWithCDN); + final URI cdnUri = getApi().getCDNExtension().get().enable(containerNameWithCDN); assertTrue(cdnUri != null); // Confirm CDN is enabled via HEAD request and has default TTL - cdnMetadata = getApi().getCDNExtension().get().getCDNMetadata(containerNameWithCDN); + cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN); assertTrue(cdnMetadata.isCDNEnabled()); assertEquals(cdnMetadata.getCDNUri(), cdnUri); - cdnMetadata = getApi().getCDNExtension().get().getCDNMetadata(containerNameWithoutCDN); + cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithoutCDN); assert cdnMetadata == null || !cdnMetadata.isCDNEnabled() : containerNameWithoutCDN + " should not have metadata"; - assert getApi().getCDNExtension().get().getCDNMetadata("DoesNotExist") == null; + assert getApi().getCDNExtension().get().get("DoesNotExist") == null; // List CDN metadata for containers, and ensure all CDN info is // available for enabled // container - Set cdnMetadataList = getApi().getCDNExtension().get().listCDNContainers(); + FluentIterable cdnMetadataList = getApi().getCDNExtension().get().list(); assertTrue(cdnMetadataList.size() >= 1); final long initialTTL = cdnMetadata.getTTL(); - assertTrue(cdnMetadataList.contains(ContainerCDNMetadata.builder().name(containerNameWithCDN) + assertTrue(cdnMetadataList.contains(CDNContainer.builder().name(containerNameWithCDN) .CDNEnabled(true).ttl(initialTTL).CDNUri(cdnUri).build())); /* * Test listing with options FIXFIX cdnMetadataList = - * getApi().listCDNContainers(ListCDNContainerOptions.Builder.enabledOnly()); - * assertTrue(Iterables.all(cdnMetadataList, new Predicate() { public - * boolean apply(ContainerCDNMetadata cdnMetadata) { return cdnMetadata.isCDNEnabled(); } + * getApi().list(ListCDNContainerOptions.Builder.enabledOnly()); + * assertTrue(Iterables.all(cdnMetadataList, new Predicate() { public + * boolean apply(CDNContainer cdnMetadata) { return cdnMetadata.isCDNEnabled(); } * })); */ - cdnMetadataList = getApi().getCDNExtension().get().listCDNContainers( + cdnMetadataList = getApi().getCDNExtension().get().list( ListCDNContainerOptions.Builder.afterMarker( containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1)).maxResults(1)); assertEquals(cdnMetadataList.size(), 1); @@ -111,9 +112,9 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes // Enable CDN with PUT for the same container, this time with a custom // TTL long ttl = 4000; - getApi().getCDNExtension().get().enableCDN(containerNameWithCDN, ttl); + getApi().getCDNExtension().get().enable(containerNameWithCDN, ttl); - cdnMetadata = getApi().getCDNExtension().get().getCDNMetadata(containerNameWithCDN); + cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN); assertTrue(cdnMetadata.isCDNEnabled()); @@ -121,23 +122,23 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes // Check POST by updating TTL settings ttl = minimumTTL; - getApi().getCDNExtension().get().updateCDN(containerNameWithCDN, minimumTTL); + getApi().getCDNExtension().get().update(containerNameWithCDN, minimumTTL); - cdnMetadata = getApi().getCDNExtension().get().getCDNMetadata(containerNameWithCDN); + cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN); assertTrue(cdnMetadata.isCDNEnabled()); assertEquals(cdnMetadata.getTTL(), minimumTTL); // Confirm that minimum allowed value for TTL is 3600, lower values are // ignored. - getApi().getCDNExtension().get().updateCDN(containerNameWithCDN, 3599L); - cdnMetadata = getApi().getCDNExtension().get().getCDNMetadata(containerNameWithCDN); + getApi().getCDNExtension().get().update(containerNameWithCDN, 3599L); + cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN); assertEquals(cdnMetadata.getTTL(), 3599L); // Disable CDN with POST - assertTrue(getApi().getCDNExtension().get().disableCDN(containerNameWithCDN)); + assertTrue(getApi().getCDNExtension().get().disable(containerNameWithCDN)); - cdnMetadata = getApi().getCDNExtension().get().getCDNMetadata(containerNameWithCDN); + cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN); assertEquals(cdnMetadata.isCDNEnabled(), false); } catch (Exception e) { e.printStackTrace(); diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java deleted file mode 100644 index b3194b566e..0000000000 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.hpcloud.objectstorage.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.URI; -import java.util.Set; -import java.util.SortedSet; - -import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.config.GsonModule; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code ParseContainerCDNMetadataListFromJsonResponse} - * - * @author Jeremy Daggett - */ -@Test(groups = "unit") -public class ParseContainerCDNMetadataListFromJsonResponseTest { - Injector i = Guice.createInjector(new GsonModule()); - - @Test - public void testApplyInputStream() { - - InputStream is = getClass().getResourceAsStream("/test_list_cdn.json"); - - Set expects = ImmutableSet.of( - ContainerCDNMetadata.builder().name("hpcloud-blobstore.testCDNOperationsContainerWithCDN").CDNEnabled(false).ttl(3600) - .CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(), - ContainerCDNMetadata.builder().name("hpcloud-blobstore5").CDNEnabled(true).ttl(28800) - .CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(), - ContainerCDNMetadata.builder().name("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN").CDNEnabled(false).ttl(3600) - .CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build()); - - ParseJson> parser = i.getInstance( - Key.get(new TypeLiteral>>() { - })); - - assertEquals(parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()), expects); - } -} diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/parse/CDNContainersTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/parse/CDNContainersTest.java new file mode 100644 index 0000000000..389b031513 --- /dev/null +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/parse/CDNContainersTest.java @@ -0,0 +1,55 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.hpcloud.objectstorage.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.hpcloud.objectstorage.domain.CDNContainer; +import org.jclouds.json.BaseItemParserTest; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "CDNContainersTest") +public class CDNContainersTest extends BaseItemParserTest> { + + @Override + public String resource() { + return "/test_list_cdn.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public FluentIterable expected() { + return FluentIterable.from(ImmutableSet.of( + CDNContainer.builder().name("hpcloud-blobstore.testCDNOperationsContainerWithCDN").CDNEnabled(false) + .ttl(3600).CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(), + CDNContainer.builder().name("hpcloud-blobstore5").CDNEnabled(true).ttl(28800) + .CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build(), + CDNContainer.builder().name("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN").CDNEnabled(false) + .ttl(3600).CDNUri(URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")).build())); + } +} From 085bc43d4883e359a0966a0b2e7a3a9f617c705a Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Sun, 16 Sep 2012 18:34:55 +0100 Subject: [PATCH 32/60] Allow for slightly inaccurate system timers in SQSErrorRetryHandlerTest (see https://groups.google.com/d/topic/jclouds-dev/uQsqlR-CEOQ/discussion) --- .../org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apis/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java index b5b9bfcb64..d9de520019 100644 --- a/apis/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java +++ b/apis/sqs/src/test/java/org/jclouds/sqs/handlers/SQSErrorRetryHandlerTest.java @@ -64,7 +64,8 @@ public class SQSErrorRetryHandlerTest { Stopwatch watch = new Stopwatch().start(); assertTrue(retry.shouldRetryRequestOnError(command, response, error)); assertEquals(command.getFailureCount(), 60); - assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) >= 100); + // allow for slightly inaccurate system timers + assertTrue(watch.stop().elapsedTime(TimeUnit.MILLISECONDS) >= 98); } From 080d142ae1699f48b0908148c7c46ffbe3e21a68 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Sun, 16 Sep 2012 17:07:17 +0300 Subject: [PATCH 33/60] Generic support for Swift TempUrl middleware --- .../cloudfiles/CloudFilesAsyncClient.java | 16 --- .../jclouds/cloudfiles/CloudFilesClient.java | 21 --- .../CloudFilesBlobRequestSigner.java | 124 ------------------ .../CloudFilesBlobStoreContextModule.java | 22 +--- .../reference/CloudFilesHeaders.java | 2 - .../cloudfiles/CloudFilesClientTest.java | 72 ---------- .../blobstore/CloudFilesBlobSignerTest.java | 83 ------------ .../integration/CloudFilesBlobLiveTest.java | 6 +- .../CloudFilesBlobSignerLiveTest.java | 64 --------- .../swift/CommonSwiftAsyncClient.java | 3 +- .../openstack/swift}/TemporaryUrlKey.java | 2 +- .../blobstore/SwiftBlobRequestSigner.java | 69 ++++++++-- .../config/SwiftBlobStoreContextModule.java | 32 ++++- .../swift/extensions/TemporaryUrlKeyApi.java | 51 +++++++ .../extensions/TemporaryUrlKeyAsyncApi.java | 60 +++++++++ .../ParseTemporaryUrlKeyFromHeaders.java | 13 +- .../swift/reference/SwiftHeaders.java | 3 + .../swift/CommonSwiftClientTest.java | 25 +++- .../blobstore/SwiftBlobRequestSignerTest.java | 48 +++++-- .../integration/SwiftBlobLiveTest.java | 5 + .../integration/SwiftBlobSignerLiveTest.java | 7 +- .../swift/internal/StubSwiftAsyncClient.java | 4 +- .../internal/BaseBlobSignerLiveTest.java | 105 ++++++++++++--- 23 files changed, 377 insertions(+), 460 deletions(-) delete mode 100644 apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java delete mode 100644 apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java delete mode 100644 apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java rename apis/{cloudfiles/src/main/java/org/jclouds/cloudfiles => swift/src/main/java/org/jclouds/openstack/swift}/TemporaryUrlKey.java (97%) create mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java create mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java rename apis/{cloudfiles/src/main/java/org/jclouds/cloudfiles => swift/src/main/java/org/jclouds/openstack/swift}/functions/ParseTemporaryUrlKeyFromHeaders.java (71%) diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java index aa3c9aaf8d..6e2ca5ab5d 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesAsyncClient.java @@ -39,7 +39,6 @@ import org.jclouds.cloudfiles.binders.BindIterableToHeadersWithPurgeCDNObjectEma import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.cloudfiles.functions.ParseCdnUriFromHeaders; import org.jclouds.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders; -import org.jclouds.cloudfiles.functions.ParseTemporaryUrlKeyFromHeaders; import org.jclouds.cloudfiles.options.ListCdnContainerOptions; import org.jclouds.cloudfiles.reference.CloudFilesHeaders; import org.jclouds.openstack.filters.AuthenticateRequest; @@ -202,19 +201,4 @@ public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient { @Headers(keys = CloudFilesHeaders.CDN_WEBSITE_ERROR, values = "{error}") ListenableFuture setCDNStaticWebsiteError(@PathParam("container") String container, @PathParam("error") String error); - - /** - * @see CloudFilesClient#getTemporaryUrlKey - */ - @HEAD - @Path("/") - @ResponseParser(ParseTemporaryUrlKeyFromHeaders.class) - ListenableFuture getTemporaryUrlKey(); - - /** - * @see CloudFilesClient#setTemporaryUrlKey - */ - @POST - @Path("/") - ListenableFuture setTemporaryUrlKey(@HeaderParam(CloudFilesHeaders.ACCOUNT_TEMPORARY_URL_KEY) String key); } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java index 23e3dd3abb..8a40c3ed23 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/CloudFilesClient.java @@ -105,25 +105,4 @@ public interface CloudFilesClient extends CommonSwiftClient { * http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Error_Pages_for_Static_Website-dle4005.html */ boolean setCDNStaticWebsiteError(String container, String error); - - /** - * Retrieve the key used to generate Temporary object access URLs - * - * @see - * @return shared secret key - */ - String getTemporaryUrlKey(); - - /** - * To create a Temporary URL you must first set a key as account metadata. - * - * Once the key is set, you should not change it while you still want others to be - * able to access your temporary URL. If you change it, the TempURL becomes invalid - * (within 60 seconds, which is the cache time for a key) and others will not be allowed - * to access it. - * - * @see - * @param temporaryUrlKey - */ - void setTemporaryUrlKey(String temporaryUrlKey); } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java deleted file mode 100644 index b6b9d7136a..0000000000 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobRequestSigner.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.jclouds.cloudfiles.blobstore; - -import com.google.common.base.Throwables; -import com.google.inject.Provider; -import org.jclouds.blobstore.BlobRequestSigner; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.functions.BlobToHttpGetOptions; -import org.jclouds.cloudfiles.CloudFilesAsyncClient; -import org.jclouds.cloudfiles.TemporaryUrlKey; -import org.jclouds.crypto.Crypto; -import org.jclouds.crypto.CryptoStreams; -import org.jclouds.date.TimeStamp; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.options.GetOptions; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; -import org.jclouds.openstack.swift.domain.SwiftObject; -import org.jclouds.rest.internal.RestAnnotationProcessor; - -import javax.inject.Inject; -import java.lang.reflect.Method; -import java.security.InvalidKeyException; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Predicates.instanceOf; -import static com.google.common.collect.Iterables.filter; -import static org.jclouds.blobstore.util.BlobStoreUtils.cleanRequest; - -public class CloudFilesBlobRequestSigner implements BlobRequestSigner { - - private final RestAnnotationProcessor processor; - private final Crypto crypto; - - private final Provider unixEpochTimestampProvider; - private final Provider temporaryUrlKeyProvider; - - private final BlobToObject blobToObject; - private final BlobToHttpGetOptions blob2HttpGetOptions; - - private final Method getMethod; - private final Method deleteMethod; - private final Method createMethod; - - @Inject - public CloudFilesBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, - BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, - @TimeStamp Provider unixEpochTimestampProvider, - @TemporaryUrlKey Provider temporaryUrlKeyProvider) throws SecurityException, NoSuchMethodException { - this.processor = checkNotNull(processor, "processor"); - this.crypto = checkNotNull(crypto, "crypto"); - - this.unixEpochTimestampProvider = checkNotNull(unixEpochTimestampProvider, "unixEpochTimestampProvider"); - this.temporaryUrlKeyProvider = checkNotNull(temporaryUrlKeyProvider, "temporaryUrlKeyProvider"); - - this.blobToObject = checkNotNull(blobToObject, "blobToObject"); - this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); - - this.getMethod = CloudFilesAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); - this.deleteMethod = CloudFilesAsyncClient.class.getMethod("removeObject", String.class, String.class); - this.createMethod = CloudFilesAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); - } - - @Override - public HttpRequest signGetBlob(String container, String name) { - return cleanRequest(processor.createRequest(getMethod, container, name)); - } - - @Override - public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { - return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); - } - - @Override - public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { - HttpRequest request = processor.createRequest(getMethod, container, name); - return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); - } - - @Override - public HttpRequest signPutBlob(String container, Blob blob) { - return cleanRequest(processor.createRequest(createMethod, container, blobToObject.apply(blob))); - } - - @Override - public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { - HttpRequest request = processor.createRequest(createMethod, container, blobToObject.apply(blob)); - return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); - } - - @Override - public HttpRequest signRemoveBlob(String container, String name) { - return cleanRequest(processor.createRequest(deleteMethod, container, name)); - } - - private HttpRequest signForTemporaryAccess(HttpRequest request, long timeInSeconds) { - HttpRequest.Builder builder = request.toBuilder(); - builder.filters(filter(request.getFilters(), instanceOf(AuthenticateRequest.class))); - - String key = temporaryUrlKeyProvider.get(); - long expiresInSeconds = unixEpochTimestampProvider.get() + timeInSeconds; - - builder.addQueryParam("temp_url_sig", createSignature(key, createStringToSign( - request.getMethod().toUpperCase(), request, expiresInSeconds))); - builder.addQueryParam("temp_url_expires", "" + expiresInSeconds); - - return builder.build(); - } - - private String createStringToSign(String method, HttpRequest request, long expiresInSeconds) { - checkArgument(method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("PUT")); - return String.format("%s\n%d\n%s", method.toUpperCase(), expiresInSeconds, - request.getEndpoint().getPath()); - } - - private String createSignature(String key, String stringToSign) { - try { - return CryptoStreams.hex(crypto.hmacSHA1(key.getBytes()).doFinal(stringToSign.getBytes())); - - } catch (InvalidKeyException e) { - throw Throwables.propagate(e); - } - } -} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java index 011a3054cf..edacb1d321 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java @@ -25,14 +25,14 @@ import javax.inject.Singleton; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.cloudfiles.CloudFilesClient; -import org.jclouds.cloudfiles.TemporaryUrlKey; +import org.jclouds.openstack.swift.TemporaryUrlKey; import org.jclouds.cloudfiles.blobstore.CloudFilesAsyncBlobStore; -import org.jclouds.cloudfiles.blobstore.CloudFilesBlobRequestSigner; import org.jclouds.cloudfiles.blobstore.CloudFilesBlobStore; import org.jclouds.cloudfiles.blobstore.functions.CloudFilesObjectToBlobMetadata; import org.jclouds.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.date.TimeStamp; import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; +import org.jclouds.openstack.swift.blobstore.SwiftBlobRequestSigner; import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; @@ -64,28 +64,12 @@ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModul }); } - @Provides - @TimeStamp - protected Long unixEpochTimestampProvider() { - return System.currentTimeMillis() / 1000; /* convert to seconds */ - } - - @Provides - @TemporaryUrlKey - protected String temporaryUrlKeyProvider(CloudFilesClient client) { - return client.getTemporaryUrlKey(); - } - @Override protected void configure() { super.configure(); bind(SwiftBlobStore.class).to(CloudFilesBlobStore.class); bind(SwiftAsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class); bind(ObjectToBlobMetadata.class).to(CloudFilesObjectToBlobMetadata.class); - } - - @Override - protected void configureRequestSigner() { - bind(BlobRequestSigner.class).to(CloudFilesBlobRequestSigner.class); + bind(BlobRequestSigner.class).to(SwiftBlobRequestSigner.class); } } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java index 10547a5f06..e3fbf27ff9 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/reference/CloudFilesHeaders.java @@ -30,8 +30,6 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders; */ public interface CloudFilesHeaders extends SwiftHeaders { - public static final String ACCOUNT_TEMPORARY_URL_KEY = "X-Account-Meta-Temp-Url-Key"; - public static final String CDN_ENABLED = "X-CDN-Enabled"; public static final String CDN_LOG_RETENTION = "X-Log-Retention"; public static final String CDN_TTL = "X-TTL"; diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java deleted file mode 100644 index f09b74dc51..0000000000 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/CloudFilesClientTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudfiles; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; -import org.jclouds.apis.ApiMetadata; -import org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule; -import org.jclouds.cloudfiles.config.CloudFilesRestClientModule; -import org.jclouds.openstack.internal.TestOpenStackAuthenticationModule; -import org.jclouds.openstack.swift.CommonSwiftClientTest; -import org.jclouds.openstack.swift.SwiftApiMetadata; -import org.jclouds.openstack.swift.SwiftAsyncClient; -import org.jclouds.openstack.swift.config.SwiftRestClientModule; -import org.jclouds.rest.HttpClient; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.testng.annotations.Test; - -import java.util.Properties; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - -/** - * @author Andrei Savu - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "CloudFilesClientTest") -public class CloudFilesClientTest extends CommonSwiftClientTest { - - public static final long UNIX_EPOCH_TIMESTAMP = 123456789L; - public static final String TEMPORARY_URL_KEY = "get-or-set-X-Account-Meta-Temp-Url-Key"; - - protected String provider = "cloudfiles"; - - public static class FixedCloudFilesBlobStoreContextModule extends CloudFilesBlobStoreContextModule { - @Override - protected Long unixEpochTimestampProvider() { - return UNIX_EPOCH_TIMESTAMP; - } - - @Override - protected String temporaryUrlKeyProvider(CloudFilesClient _) { - return TEMPORARY_URL_KEY; - } - } - - @Override - protected ApiMetadata createApiMetadata() { - return new CloudFilesApiMetadata().toBuilder().defaultModules( - ImmutableSet.>of(StorageEndpointModule.class, - CloudFilesRestClientModule.class, FixedCloudFilesBlobStoreContextModule.class)).build(); - } -} diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java deleted file mode 100644 index 7bdcdaefc4..0000000000 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/CloudFilesBlobSignerTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.jclouds.cloudfiles.blobstore; - -import org.jclouds.blobstore.BlobRequestSigner; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.cloudfiles.CloudFilesClientTest; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.util.Date; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - -/** - * @author Andrei Savu - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "CloudFilesBlobSignerTest") -public class CloudFilesBlobSignerTest extends CloudFilesClientTest { - - private BlobRequestSigner signer; - private Blob.Factory blobFactory; - - public void testSignGetBlobWithTime() { - HttpRequest request = signer.signGetBlob("container", "name", 120); - - assertRequestLineEquals(request, "GET http://storage/container/name?" + - "temp_url_sig=4759d99d13c826bba0af2c9f0c526ca53c95abaf&temp_url_expires=123456909 HTTP/1.1"); - assertFalse(request.getHeaders().containsKey("X-Auth-Token")); - assertPayloadEquals(request, null, null, false); - - assertEquals(request.getFilters().size(), 0); - } - - public void testSignPutBlobWithTime() throws Exception { - Blob blob = blobFactory.create(null); - - blob.getMetadata().setName("name"); - blob.setPayload(""); - blob.getPayload().getContentMetadata().setContentLength(2l); - blob.getPayload().getContentMetadata().setContentMD5(new byte[]{0, 2, 4, 8}); - blob.getPayload().getContentMetadata().setContentType("text/plain"); - blob.getPayload().getContentMetadata().setExpires(new Date(1000)); - - HttpRequest request = signer.signPutBlob("container", blob, 120 /* seconds */); - - assertRequestLineEquals(request, "PUT http://storage/container/name?" + - "temp_url_sig=490690286130adac9e7144d85b320a00b1bf9e2b&temp_url_expires=123456909 HTTP/1.1"); - - assertFalse(request.getHeaders().containsKey("X-Auth-Token")); - assertContentHeadersEqual(request, "text/plain", null, null, null, (long) 2l, new byte[]{0, 2, 4, 8}, new Date(1000)); - - assertEquals(request.getFilters().size(), 0); - } - - @BeforeClass - protected void setupFactory() throws IOException { - super.setupFactory(); - this.blobFactory = injector.getInstance(Blob.Factory.class); - this.signer = injector.getInstance(BlobRequestSigner.class); - } -} diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java index 14de7f6200..360c307c4e 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobLiveTest.java @@ -18,9 +18,8 @@ */ package org.jclouds.cloudfiles.blobstore.integration; -import org.jclouds.cloudfiles.CloudFilesApiMetadata; -import org.jclouds.cloudfiles.CloudFilesClient; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobLiveTest; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; import org.testng.annotations.Test; import java.util.UUID; @@ -33,12 +32,13 @@ import static org.testng.Assert.assertNotNull; */ @Test(groups = {"live"}) public class CloudFilesBlobLiveTest extends SwiftBlobLiveTest { + public CloudFilesBlobLiveTest() { provider = "cloudfiles"; } public void testGetAndSetTemporaryUrlKey() { - CloudFilesClient client = view.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi(); + TemporaryUrlKeyApi client = view.utils().injector().getInstance(TemporaryUrlKeyApi.class); String currentSecretKey = client.getTemporaryUrlKey(); assertNotNull(currentSecretKey); diff --git a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java index 9ced14fa93..d67142e575 100644 --- a/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/blobstore/integration/CloudFilesBlobSignerLiveTest.java @@ -18,19 +18,9 @@ */ package org.jclouds.cloudfiles.blobstore.integration; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.http.HttpRequest; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobSignerLiveTest; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.util.Strings2; import org.testng.annotations.Test; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; - /** * @author Adrian Cole */ @@ -39,58 +29,4 @@ public class CloudFilesBlobSignerLiveTest extends SwiftBlobSignerLiveTest { public CloudFilesBlobSignerLiveTest() { provider = "cloudfiles"; } - - @Test - public void testSignGetUrlWithTime() throws InterruptedException, IOException { - String name = "hello"; - String text = "fooooooooooooooooooooooo"; - - Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); - String container = getContainerName(); - try { - view.getBlobStore().putBlob(container, blob); - assertConsistencyAwareContainerSize(container, 1); - HttpRequest request = view.getSigner().signGetBlob(container, name, 3 /* seconds */); - - assertEquals(request.getFilters().size(), 0); - assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); - - TimeUnit.SECONDS.sleep(4); - try { - Strings2.toString(view.utils().http().invoke(request).getPayload()); - fail("Temporary URL did not expire as expected"); - } catch (AuthorizationException expected) { - } - } finally { - returnContainer(container); - } - } - - @Test - public void testSignPutUrlWithTime() throws Exception { - String name = "hello"; - String text = "fooooooooooooooooooooooo"; - - Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); - String container = getContainerName(); - try { - HttpRequest request = view.getSigner().signPutBlob(container, blob, 3 /* seconds */); - assertEquals(request.getFilters().size(), 0); - - Strings2.toString(view.utils().http().invoke(request).getPayload()); - assertConsistencyAwareContainerSize(container, 1); - - view.getBlobStore().removeBlob(container, name); - assertConsistencyAwareContainerSize(container, 0); - - TimeUnit.SECONDS.sleep(4); - try { - Strings2.toString(view.utils().http().invoke(request).getPayload()); - fail("Temporary URL did not expire as expected"); - } catch (AuthorizationException expected) { - } - } finally { - returnContainer(container); - } - } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java index b7a9b9fa8c..c7f7ef8ea1 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java @@ -25,6 +25,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HEAD; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -54,6 +55,7 @@ import org.jclouds.openstack.swift.functions.ParseContainerMetadataFromHeaders; import org.jclouds.openstack.swift.functions.ParseObjectFromHeadersAndHttpContent; import org.jclouds.openstack.swift.functions.ParseObjectInfoFromHeaders; import org.jclouds.openstack.swift.functions.ParseObjectInfoListFromJsonResponse; +import org.jclouds.openstack.swift.functions.ParseTemporaryUrlKeyFromHeaders; import org.jclouds.openstack.swift.functions.ReturnTrueOn404FalseOn409; import org.jclouds.openstack.swift.options.CreateContainerOptions; import org.jclouds.openstack.swift.options.ListContainerOptions; @@ -248,5 +250,4 @@ public interface CommonSwiftAsyncClient { @Headers(keys = "X-Object-Manifest", values="{container}/{name}") ListenableFuture putObjectManifest(@PathParam("container") String container, @PathParam("name") String name); - } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/TemporaryUrlKey.java similarity index 97% rename from apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java rename to apis/swift/src/main/java/org/jclouds/openstack/swift/TemporaryUrlKey.java index 15b7d43e1c..7cb011bd74 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/TemporaryUrlKey.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/TemporaryUrlKey.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudfiles; +package org.jclouds.openstack.swift; import javax.inject.Qualifier; import java.lang.annotation.ElementType; diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java index d3986f8e7e..4da0517a2a 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java @@ -18,32 +18,46 @@ */ package org.jclouds.openstack.swift.blobstore; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.instanceOf; +import static com.google.common.collect.Iterables.filter; import static org.jclouds.blobstore.util.BlobStoreUtils.cleanRequest; import java.lang.reflect.Method; +import java.security.InvalidKeyException; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.base.Throwables; +import com.google.inject.Provider; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.crypto.Crypto; +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.options.GetOptions; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; +import org.jclouds.openstack.swift.TemporaryUrlKey; import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; import org.jclouds.openstack.swift.domain.SwiftObject; import org.jclouds.rest.internal.RestAnnotationProcessor; /** - * * @author Adrian Cole */ @Singleton public class SwiftBlobRequestSigner implements BlobRequestSigner { private final RestAnnotationProcessor processor; + private final Crypto crypto; + + private final Provider unixEpochTimestampProvider; + private final Provider temporaryUrlKeyProvider; private final BlobToObject blobToObject; private final BlobToHttpGetOptions blob2HttpGetOptions; @@ -54,14 +68,19 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { @Inject public SwiftBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, - BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { + BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, @TimeStamp Provider unixEpochTimestampProvider, + @TemporaryUrlKey Provider temporaryUrlKeyProvider) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); + this.crypto = checkNotNull(crypto, "crypto"); + + this.unixEpochTimestampProvider = checkNotNull(unixEpochTimestampProvider, "unixEpochTimestampProvider"); + this.temporaryUrlKeyProvider = checkNotNull(temporaryUrlKeyProvider, "temporaryUrlKeyProvider"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class, - GetOptions[].class); + GetOptions[].class); this.deleteMethod = CommonSwiftAsyncClient.class.getMethod("removeObject", String.class, String.class); this.createMethod = CommonSwiftAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); } @@ -73,7 +92,13 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { @Override public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { - throw new UnsupportedOperationException(); + HttpRequest request = processor.createRequest(getMethod, container, name); + return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); + } + + @Override + public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { + return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); } @Override @@ -83,7 +108,8 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { @Override public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { - throw new UnsupportedOperationException(); + HttpRequest request = processor.createRequest(createMethod, container, blobToObject.apply(blob)); + return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); } @Override @@ -91,8 +117,35 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(deleteMethod, container, name)); } - @Override - public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { - return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); + private HttpRequest signForTemporaryAccess(HttpRequest request, long timeInSeconds) { + HttpRequest.Builder builder = request.toBuilder(); + builder.filters(filter(request.getFilters(), instanceOf(AuthenticateRequest.class))); + + String key = temporaryUrlKeyProvider.get(); + if (key == null) { + throw new UnsupportedOperationException(); + } + long expiresInSeconds = unixEpochTimestampProvider.get() + timeInSeconds; + + builder.addQueryParam("temp_url_sig", createSignature(key, createStringToSign( + request.getMethod().toUpperCase(), request, expiresInSeconds))); + builder.addQueryParam("temp_url_expires", "" + expiresInSeconds); + + return builder.build(); + } + + private String createStringToSign(String method, HttpRequest request, long expiresInSeconds) { + checkArgument(method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("PUT")); + return String.format("%s\n%d\n%s", method.toUpperCase(), expiresInSeconds, + request.getEndpoint().getPath()); + } + + private String createSignature(String key, String stringToSign) { + try { + return CryptoStreams.hex(crypto.hmacSHA1(key.getBytes()).doFinal(stringToSign.getBytes())); + + } catch (InvalidKeyException e) { + throw Throwables.propagate(e); + } } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java index 6b60d81071..ae9ce38aa8 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java @@ -18,17 +18,26 @@ */ package org.jclouds.openstack.swift.blobstore.config; +import com.google.inject.Provides; import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.config.BlobStoreMapModule; +import org.jclouds.date.TimeStamp; +import org.jclouds.openstack.swift.TemporaryUrlKey; import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; import org.jclouds.openstack.swift.blobstore.SwiftBlobRequestSigner; import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import com.google.inject.AbstractModule; import com.google.inject.Scopes; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyAsyncApi; + +import java.util.UUID; + +import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; /** * Configures the {@link CloudFilesBlobStoreContext}; requires {@link SwiftAsyncBlobStore} @@ -38,16 +47,31 @@ import com.google.inject.Scopes; */ public class SwiftBlobStoreContextModule extends AbstractModule { + @Provides + @TimeStamp + protected Long unixEpochTimestampProvider() { + return System.currentTimeMillis() / 1000; /* convert to seconds */ + } + + @Provides + @TemporaryUrlKey + protected String temporaryUrlKeyProvider(TemporaryUrlKeyApi client) { + String key = client.getTemporaryUrlKey(); + if (key == null) { + client.setTemporaryUrlKey(UUID.randomUUID().toString()); + return client.getTemporaryUrlKey(); + } + return key; + } + + @Override protected void configure() { install(new BlobStoreMapModule()); bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT); bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON); - configureRequestSigner(); - } - - protected void configureRequestSigner() { bind(BlobRequestSigner.class).to(SwiftBlobRequestSigner.class); + bindClientAndAsyncClient(binder(), TemporaryUrlKeyApi.class, TemporaryUrlKeyAsyncApi.class); } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java new file mode 100644 index 0000000000..b8a9f48b65 --- /dev/null +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.swift.extensions; + +import org.jclouds.concurrent.Timeout; + +import java.util.concurrent.TimeUnit; + +/** + * @author Andrei Savu + * @see + */ +@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) +public interface TemporaryUrlKeyApi { + /** + * Retrieve the key used to generate Temporary object access URLs + * + * @return shared secret key or null + * @see + */ + String getTemporaryUrlKey(); + + /** + * To create a Temporary URL you must first set a key as account metadata. + *

+ * Once the key is set, you should not change it while you still want others to be + * able to access your temporary URL. If you change it, the TempURL becomes invalid + * (within 60 seconds, which is the cache time for a key) and others will not be allowed + * to access it. + * + * @param temporaryUrlKey + * @see + */ + void setTemporaryUrlKey(String temporaryUrlKey); +} diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java new file mode 100644 index 0000000000..352c7197ce --- /dev/null +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.swift.extensions; + +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.swift.Storage; +import org.jclouds.openstack.swift.functions.ParseTemporaryUrlKeyFromHeaders; +import org.jclouds.openstack.swift.reference.SwiftHeaders; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SkipEncoding; + +import javax.ws.rs.HEAD; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * @author Andrei Savu + * @see TemporaryUrlKeyApi + */ +@SkipEncoding('/') +@RequestFilters(AuthenticateRequest.class) +@Endpoint(Storage.class) +public interface TemporaryUrlKeyAsyncApi { + + /** + * @see TemporaryUrlKeyApi#getTemporaryUrlKey + */ + @HEAD + @Path("/") + @ResponseParser(ParseTemporaryUrlKeyFromHeaders.class) + ListenableFuture getTemporaryUrlKey(); + + /** + * @see TemporaryUrlKeyApi#setTemporaryUrlKey + */ + @POST + @Path("/") + ListenableFuture setTemporaryUrlKey(@HeaderParam(SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY) String key); + +} diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/functions/ParseTemporaryUrlKeyFromHeaders.java similarity index 71% rename from apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java rename to apis/swift/src/main/java/org/jclouds/openstack/swift/functions/ParseTemporaryUrlKeyFromHeaders.java index fc360aaccf..c126fca7ee 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/functions/ParseTemporaryUrlKeyFromHeaders.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/functions/ParseTemporaryUrlKeyFromHeaders.java @@ -16,13 +16,15 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.cloudfiles.functions; +package org.jclouds.openstack.swift.functions; import com.google.common.base.Function; +import com.google.common.collect.Multimap; import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.reference.SwiftHeaders; import static com.google.common.collect.Iterables.getOnlyElement; -import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.ACCOUNT_TEMPORARY_URL_KEY; +import static org.jclouds.openstack.swift.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY; /** * @author Andrei Savu @@ -31,6 +33,11 @@ public class ParseTemporaryUrlKeyFromHeaders implements Function headers = httpResponse.getHeaders(); + if (headers.containsKey(ACCOUNT_TEMPORARY_URL_KEY)) { + return getOnlyElement(headers.get(ACCOUNT_TEMPORARY_URL_KEY)); + } else { + return null; + } } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/reference/SwiftHeaders.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/reference/SwiftHeaders.java index 3e8d37d2fb..73e104257f 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/reference/SwiftHeaders.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/reference/SwiftHeaders.java @@ -24,12 +24,15 @@ package org.jclouds.openstack.swift.reference; */ public interface SwiftHeaders { + public static final String ACCOUNT_TEMPORARY_URL_KEY = "X-Account-Meta-Temp-Url-Key"; public static final String ACCOUNT_BYTES_USED = "X-Account-Bytes-Used"; public static final String ACCOUNT_CONTAINER_COUNT = "X-Account-Container-Count"; + public static final String CONTAINER_BYTES_USED = "X-Container-Bytes-Used"; public static final String CONTAINER_OBJECT_COUNT = "X-Container-Object-Count"; public static final String CONTAINER_METADATA_PREFIX = "X-Container-Meta-"; public static final String CONTAINER_DELETE_METADATA_PREFIX = "X-Remove-Container-Meta-"; + public static final String USER_METADATA_PREFIX = "X-Object-Meta-"; public static final String OBJECT_COPY_FROM = "X-Copy-From"; diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java index a8d3815445..6e7308eab8 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java @@ -34,6 +34,7 @@ import org.jclouds.openstack.internal.TestOpenStackAuthenticationModule; import org.jclouds.openstack.reference.AuthHeaders; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -46,13 +47,17 @@ import com.google.inject.TypeLiteral; /** * Tests behavior of {@code BindSwiftObjectMetadataToRequest} - * + * * @author Adrian Cole */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "SwiftClientTest") +@Test(groups = "unit", testName = "CommonSwiftClientTest") public abstract class CommonSwiftClientTest extends BaseAsyncClientTest { + public static final long UNIX_EPOCH_TIMESTAMP = 123456789L; + + public static final String TEMPORARY_URL_KEY = "get-or-set-X-Account-Meta-Temp-Url-Key"; + @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { @@ -74,11 +79,23 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest> of(StorageEndpointModule.class, SwiftRestClientModule.class, - SwiftBlobStoreContextModule.class)).build(); + ImmutableSet.>of(StorageEndpointModule.class, SwiftRestClientModule.class, + FixedSwiftBlobStoreContextModule.class)).build(); } @Override diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java index 7c3c82ce4a..f16199ec10 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSignerTest.java @@ -19,6 +19,7 @@ package org.jclouds.openstack.swift.blobstore; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import java.io.IOException; import java.util.Date; @@ -43,8 +44,7 @@ public class SwiftBlobRequestSignerTest extends CommonSwiftClientTest { private BlobRequestSigner signer; private Factory blobFactory; - public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, - NoSuchMethodException, IOException { + public void testSignGetBlob() throws Exception { HttpRequest request = signer.signGetBlob("container", "name"); assertRequestLineEquals(request, "GET http://storage/container/name HTTP/1.1"); @@ -54,19 +54,18 @@ public class SwiftBlobRequestSignerTest extends CommonSwiftClientTest { assertEquals(request.getFilters().size(), 0); } - public void testSignRemoveBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, - NoSuchMethodException, IOException { - HttpRequest request = signer.signRemoveBlob("container", "name"); + public void testSignGetBlobWithTime() { + HttpRequest request = signer.signGetBlob("container", "name", 120); - assertRequestLineEquals(request, "DELETE http://storage/container/name HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "X-Auth-Token: testtoken\n"); + assertRequestLineEquals(request, "GET http://storage/container/name?" + + "temp_url_sig=4759d99d13c826bba0af2c9f0c526ca53c95abaf&temp_url_expires=123456909 HTTP/1.1"); + assertFalse(request.getHeaders().containsKey("X-Auth-Token")); assertPayloadEquals(request, null, null, false); assertEquals(request.getFilters().size(), 0); } - public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, - NoSuchMethodException, IOException { + public void testSignPutBlob() throws Exception { Blob blob = blobFactory.create(null); blob.getMetadata().setName("name"); blob.setPayload(""); @@ -84,6 +83,37 @@ public class SwiftBlobRequestSignerTest extends CommonSwiftClientTest { assertEquals(request.getFilters().size(), 0); } + public void testSignPutBlobWithTime() throws Exception { + Blob blob = blobFactory.create(null); + + blob.getMetadata().setName("name"); + blob.setPayload(""); + blob.getPayload().getContentMetadata().setContentLength(2l); + blob.getPayload().getContentMetadata().setContentMD5(new byte[]{0, 2, 4, 8}); + blob.getPayload().getContentMetadata().setContentType("text/plain"); + blob.getPayload().getContentMetadata().setExpires(new Date(1000)); + + HttpRequest request = signer.signPutBlob("container", blob, 120 /* seconds */); + + assertRequestLineEquals(request, "PUT http://storage/container/name?" + + "temp_url_sig=490690286130adac9e7144d85b320a00b1bf9e2b&temp_url_expires=123456909 HTTP/1.1"); + + assertFalse(request.getHeaders().containsKey("X-Auth-Token")); + assertContentHeadersEqual(request, "text/plain", null, null, null, (long) 2l, new byte[]{0, 2, 4, 8}, new Date(1000)); + + assertEquals(request.getFilters().size(), 0); + } + + public void testSignRemoveBlob() throws Exception { + HttpRequest request = signer.signRemoveBlob("container", "name"); + + assertRequestLineEquals(request, "DELETE http://storage/container/name HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "X-Auth-Token: testtoken\n"); + assertPayloadEquals(request, null, null, false); + + assertEquals(request.getFilters().size(), 0); + } + @BeforeClass protected void setupFactory() throws IOException { super.setupFactory(); diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java index 5aa1b4931c..c1b0ff7a67 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobLiveTest.java @@ -19,11 +19,16 @@ package org.jclouds.openstack.swift.blobstore.integration; import java.util.Properties; +import java.util.UUID; import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + /** * * @author James Murty diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java index 392a38024e..9c6ed48d16 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobSignerLiveTest.java @@ -18,17 +18,16 @@ */ package org.jclouds.openstack.swift.blobstore.integration; -import java.util.Properties; - import org.jclouds.blobstore.integration.internal.BaseBlobSignerLiveTest; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.testng.annotations.Test; +import java.util.Properties; + /** - * * @author Adrian Cole */ -@Test(groups = { "live" }) +@Test(groups = {"live"}) public class SwiftBlobSignerLiveTest extends BaseBlobSignerLiveTest { @Override diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java index 1341de2b0c..2d0fb1584a 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java @@ -31,6 +31,7 @@ import java.util.concurrent.ExecutorService; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import javax.ws.rs.HeaderParam; import org.jclouds.Constants; import org.jclouds.blobstore.LocalAsyncBlobStore; @@ -60,6 +61,7 @@ import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.openstack.swift.reference.SwiftHeaders; /** * Implementation of {@link SwiftAsyncClient} which keeps all data in a local Map object. @@ -201,7 +203,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient { return null; } - public ListenableFuture setObjectInfo(String container, String key, Map userMetadata) { + public ListenableFuture setObjectInfo(String container, String key, Map userMetadata) { throw new UnsupportedOperationException(); } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java index 200f4399b6..bee7e726f1 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java @@ -20,41 +20,28 @@ package org.jclouds.blobstore.integration.internal; import static org.jclouds.blobstore.options.GetOptions.Builder.range; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; import org.jclouds.blobstore.domain.Blob; import org.jclouds.http.HttpRequest; +import org.jclouds.rest.AuthorizationException; import org.jclouds.util.Strings2; +import org.testng.SkipException; import org.testng.annotations.Test; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + /** * Tests integrated functionality of all signature commands. *

* Each test uses a different container name, so it should be perfectly fine to run in parallel. - * + * * @author Adrian Cole */ -@Test(groups = { "live" }) +@Test(groups = {"live"}) public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { - @Test - public void testSignRemoveUrl() throws Exception { - String name = "hello"; - String text = "fooooooooooooooooooooooo"; - - Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); - String container = getContainerName(); - try { - view.getBlobStore().putBlob(container, blob); - assertConsistencyAwareContainerSize(container, 1); - HttpRequest request = view.getSigner().signRemoveBlob(container, name); - assertEquals(request.getFilters().size(), 0); - view.utils().http().invoke(request); - assert !view.getBlobStore().blobExists(container, name); - } finally { - returnContainer(container); - } - } - @Test public void testSignGetUrl() throws Exception { String name = "hello"; @@ -91,6 +78,34 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { } } + @Test + public void testSignGetUrlWithTime() throws InterruptedException, IOException { + String name = "hello"; + String text = "fooooooooooooooooooooooo"; + + Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); + String container = getContainerName(); + try { + view.getBlobStore().putBlob(container, blob); + assertConsistencyAwareContainerSize(container, 1); + HttpRequest request = view.getSigner().signGetBlob(container, name, 3 /* seconds */); + + assertEquals(request.getFilters().size(), 0); + assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); + + TimeUnit.SECONDS.sleep(4); + try { + Strings2.toString(view.utils().http().invoke(request).getPayload()); + fail("Temporary URL did not expire as expected"); + } catch (AuthorizationException expected) { + } + } catch (UnsupportedOperationException ignore) { + throw new SkipException("signGetUrl with a time limit is not supported on " + provider); + } finally { + returnContainer(container); + } + } + @Test public void testSignPutUrl() throws Exception { String name = "hello"; @@ -108,4 +123,52 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { } } + @Test + public void testSignPutUrlWithTime() throws Exception { + String name = "hello"; + String text = "fooooooooooooooooooooooo"; + + Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); + String container = getContainerName(); + try { + HttpRequest request = view.getSigner().signPutBlob(container, blob, 3 /* seconds */); + assertEquals(request.getFilters().size(), 0); + + Strings2.toString(view.utils().http().invoke(request).getPayload()); + assertConsistencyAwareContainerSize(container, 1); + + view.getBlobStore().removeBlob(container, name); + assertConsistencyAwareContainerSize(container, 0); + + TimeUnit.SECONDS.sleep(4); + try { + Strings2.toString(view.utils().http().invoke(request).getPayload()); + fail("Temporary URL did not expire as expected"); + } catch (AuthorizationException expected) { + } + } catch (UnsupportedOperationException ignore) { + throw new SkipException("signPutUrl with a time limit is not supported on " + provider); + } finally { + returnContainer(container); + } + } + + @Test + public void testSignRemoveUrl() throws Exception { + String name = "hello"; + String text = "fooooooooooooooooooooooo"; + + Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); + String container = getContainerName(); + try { + view.getBlobStore().putBlob(container, blob); + assertConsistencyAwareContainerSize(container, 1); + HttpRequest request = view.getSigner().signRemoveBlob(container, name); + assertEquals(request.getFilters().size(), 0); + view.utils().http().invoke(request); + assert !view.getBlobStore().blobExists(container, name); + } finally { + returnContainer(container); + } + } } \ No newline at end of file From 3898f1eee20260ed46bc26b82a3956600aa0b1e8 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Sun, 16 Sep 2012 21:53:58 +0300 Subject: [PATCH 34/60] Removed two unused imports --- .../org/jclouds/openstack/swift/CommonSwiftAsyncClient.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java index c7f7ef8ea1..b31a92c1c2 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java @@ -25,7 +25,6 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HEAD; -import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -55,7 +54,6 @@ import org.jclouds.openstack.swift.functions.ParseContainerMetadataFromHeaders; import org.jclouds.openstack.swift.functions.ParseObjectFromHeadersAndHttpContent; import org.jclouds.openstack.swift.functions.ParseObjectInfoFromHeaders; import org.jclouds.openstack.swift.functions.ParseObjectInfoListFromJsonResponse; -import org.jclouds.openstack.swift.functions.ParseTemporaryUrlKeyFromHeaders; import org.jclouds.openstack.swift.functions.ReturnTrueOn404FalseOn409; import org.jclouds.openstack.swift.options.CreateContainerOptions; import org.jclouds.openstack.swift.options.ListContainerOptions; From 85b5006084adeb8bb72ee1be3218a72497418129 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 11:38:55 -0700 Subject: [PATCH 35/60] nicer NPE when null args are specified to ReST methods --- .../internal/RestAnnotationProcessor.java | 91 +++++++++---------- .../internal/RestAnnotationProcessorTest.java | 68 +++++++++++++- 2 files changed, 108 insertions(+), 51 deletions(-) diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 215821a815..ba42417faf 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -140,6 +140,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.Objects; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; @@ -1014,7 +1015,7 @@ public class RestAnnotationProcessor { Annotation[] annotations = request.getJavaMethod().getParameterAnnotations()[entry.getKey()]; for (Annotation a : annotations) { - if (Nullable.class.isAssignableFrom(a.annotationType())) + if (NULLABLE.apply(a)) continue OUTER; } Preconditions.checkNotNull(null, request.getJavaMethod().getName() + " parameter " + (entry.getKey() + 1)); @@ -1188,17 +1189,11 @@ public class RestAnnotationProcessor { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); String paramKey = ((PathParam) key).value(); - String paramValue; - if (extractors != null && extractors.size() > 0) { - ParamParser extractor = (ParamParser) extractors.iterator().next(); - paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); - } else { - paramValue = args[entry.getKey()].toString(); - } - pathParamValues.put(paramKey, paramValue); + Optional paramValue = getParamValue(method, args, extractors, entry, paramKey); + if (paramValue.isPresent()) + pathParamValues.put(paramKey, paramValue.get().toString()); } } - if (method.isAnnotationPresent(PathParam.class) && method.isAnnotationPresent(ParamParser.class)) { String paramKey = method.getAnnotation(PathParam.class).value(); String paramValue = injector.getInstance(method.getAnnotation(ParamParser.class).value()).apply(args); @@ -1208,6 +1203,33 @@ public class RestAnnotationProcessor { return pathParamValues; } + protected Optional getParamValue(Method method, Object[] args, Set extractors, + Entry> entry, String paramKey) { + Object arg = args[entry.getKey()]; + if (arg == null && containsNullable(method.getParameterAnnotations()[entry.getKey()])) + return Optional.absent(); + + checkNotNull(arg, "param{%s} for method %s.%s", paramKey, method.getDeclaringClass().getSimpleName(), + method.getName()); + if (extractors != null && extractors.size() > 0) { + ParamParser extractor = (ParamParser) extractors.iterator().next(); + return Optional.of(injector.getInstance(extractor.value()).apply(arg)); + } + return Optional.of(arg); + } + + private static final Predicate NULLABLE = new Predicate() { + + @Override + public boolean apply(Annotation in) { + return Nullable.class.isAssignableFrom(in.annotationType()); + } + }; + + private static boolean containsNullable(Annotation[] annotations) { + return Iterables.any(ImmutableSet.copyOf(annotations), NULLABLE); + } + private Multimap encodeValues(Multimap unencoded, char... skips) { Multimap encoded = LinkedHashMultimap.create(); for (Entry entry : unencoded.entries()) { @@ -1226,14 +1248,9 @@ public class RestAnnotationProcessor { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); String paramKey = ((MatrixParam) key).value(); - String paramValue; - if (extractors != null && extractors.size() > 0) { - ParamParser extractor = (ParamParser) extractors.iterator().next(); - paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); - } else { - paramValue = args[entry.getKey()].toString(); - } - matrixParamValues.put(paramKey, paramValue); + Optional paramValue = getParamValue(method, args, extractors, entry, paramKey); + if (paramValue.isPresent()) + matrixParamValues.put(paramKey, paramValue.get().toString()); } } @@ -1257,16 +1274,9 @@ public class RestAnnotationProcessor { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); String paramKey = ((FormParam) key).value(); - String paramValue; - if (extractors != null && extractors.size() > 0) { - ParamParser extractor = (ParamParser) extractors.iterator().next(); - paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); - } else { - Object pvo = args[entry.getKey()]; - Preconditions.checkNotNull(pvo, paramKey); - paramValue = pvo.toString(); - } - formParamValues.put(paramKey, paramValue); + Optional paramValue = getParamValue(method, args, extractors, entry, paramKey); + if (paramValue.isPresent()) + formParamValues.put(paramKey, paramValue.get().toString()); } } @@ -1289,16 +1299,9 @@ public class RestAnnotationProcessor { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); String paramKey = ((QueryParam) key).value(); - Object paramValue; - if (extractors != null && extractors.size() > 0) { - ParamParser extractor = (ParamParser) extractors.iterator().next(); - paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); - } else { - paramValue = args[entry.getKey()]; - } - if (paramValue != null) { - queryParamValues.put(paramKey, paramValue.toString()); - } + Optional paramValue = getParamValue(method, args, extractors, entry, paramKey); + if (paramValue.isPresent()) + queryParamValues.put(paramKey, paramValue.get().toString()); } } @@ -1321,15 +1324,9 @@ public class RestAnnotationProcessor { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); String paramKey = ((PayloadParam) key).value(); - Object paramValue; - if (extractors != null && extractors.size() > 0) { - ParamParser extractor = (ParamParser) extractors.iterator().next(); - paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); - } else { - paramValue = args[entry.getKey()] != null ? args[entry.getKey()] : null; - } - postParams.put(paramKey, paramValue); - + Optional paramValue = getParamValue(method, args, extractors, entry, paramKey); + if (paramValue.isPresent()) + postParams.put(paramKey, paramValue.get()); } } return postParams; diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index f14de94dd5..0bce56fcd5 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -499,6 +499,12 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) public void foo3(@QueryParam("robbie") String robbie) { } + + @FOO + @Path("/") + @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) + public void foo3Nullable(@Nullable @QueryParam("robbie") String robbie) { + } } public void testUnEncodeQuery() { @@ -537,6 +543,25 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=bar&fooble=baz&robbie=wonder"); assertEquals(request.getMethod(), "FOO"); } + + @Test + public void testNiceNPEQueryParam() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestQuery.class.getMethod("foo3", String.class); + try { + factory(TestPath.class).createRequest(method, (String) null); + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "param{robbie} for method TestQuery.foo3"); + } + } + + public void testNoNPEOnQueryParamWithNullable() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("foo3Nullable", String.class); + HttpRequest request = factory(TestPath.class).createRequest(method, (String) null); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), "foo=bar&fooble=baz"); + assertEquals(request.getMethod(), "FOO"); + } public interface TestPayloadParamVarargs { @POST @@ -578,7 +603,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "foo", "application/octet-stream", false); } - + public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class); HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, new TestHttpRequestOptions().payload("fooya")); @@ -1397,6 +1422,11 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Path("/{path}") public void onePath(@PathParam("path") String path) { } + + @GET + @Path("/{path}") + public void onePathNullable(@Nullable @PathParam("path") String path) { + } @GET @Path("/{path1}/{path2}") @@ -1435,7 +1465,17 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void onePathParamExtractorMethod(String path) { } } - + + @Test + public void testNiceNPEPathParam() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestPath.class.getMethod("onePath", String.class); + try { + factory(TestPath.class).createRequest(method, (String) null); + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "param{path} for method TestPath.onePath"); + } + } + @Test public void testPathParamExtractor() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPath.class.getMethod("onePathParamExtractor", String.class); @@ -1462,7 +1502,17 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); } - + + @Test + public void testNiceNPEMatrixParam() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestPath.class.getMethod("oneMatrixParamExtractor", String.class); + try { + factory(TestPath.class).createRequest(method, (String) null); + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "param{one} for method TestPath.oneMatrixParamExtractor"); + } + } + @Test public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPath.class.getMethod("oneFormParamExtractor", String.class); @@ -1471,7 +1521,17 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "one=l", "application/x-www-form-urlencoded", false); } - + + @Test + public void testNiceNPEFormParam() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestPath.class.getMethod("oneFormParamExtractor", String.class); + try { + factory(TestPath.class).createRequest(method, (String) null); + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "param{one} for method TestPath.oneFormParamExtractor"); + } + } + @Test public void testParamExtractorMethod() throws SecurityException, NoSuchMethodException { Method method = TestPath.class.getMethod("onePathParamExtractorMethod", String.class); From f7feb0248a20c82b098ab3c6be931e9067a184ac Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 12:23:39 -0700 Subject: [PATCH 36/60] fixed bad test assertions in openstack-nova --- .../nova/v2_0/features/ImageApiLiveTest.java | 8 +++---- .../nova/v2_0/features/ServerApiLiveTest.java | 21 ++++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java index 7e59eea5cf..6c3f325676 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java @@ -69,10 +69,10 @@ public class ImageApiLiveTest extends BaseNovaApiLiveTest { assertTrue(image.getMinRam() > 0); assertTrue(image.getProgress() >= 0 && image.getProgress() <= 100); assertNotNull(image.getStatus()); - assertNotNull(image.getServer()); - assertNotNull(image.getTenantId()); - assertNotNull(image.getUpdated()); - assertNotNull(image.getUserId()); + // image.getServer() can be null + // image.getTenantId() can be null + // image.getUpdated() can be null + // image.getUserId() can be null } } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java index 6d47cd88e1..e02dc437c1 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiLiveTest.java @@ -19,9 +19,9 @@ package org.jclouds.openstack.nova.v2_0.features; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.*; - -import java.util.Set; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; @@ -44,12 +44,7 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest { public void testListServers() throws Exception { for (String zoneId : zones) { ServerApi api = novaContext.getApi().getServerApiForZone(zoneId); - Set response = api.list().concat().toImmutableSet(); - assertNotNull(response); - assertFalse(response.isEmpty()); - assert null != response; - assertTrue(response.size() >= 0); - for (Resource server : response) { + for (Resource server : api.list().concat()) { checkResource(server); } } @@ -59,10 +54,7 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest { public void testListServersInDetail() throws Exception { for (String zoneId : zones) { ServerApi api = novaContext.getApi().getServerApiForZone(zoneId); - Set response = api.listInDetail().concat().toImmutableSet(); - assertNotNull(response); - assertFalse(response.isEmpty()); - for (Server server : response) { + for (Server server : api.listInDetail().concat()) { checkServer(server); } } @@ -72,8 +64,7 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest { public void testGetServerById() throws Exception { for (String zoneId : zones) { ServerApi api = novaContext.getApi().getServerApiForZone(zoneId); - Set response = api.list().concat().toImmutableSet(); - for (Resource server : response) { + for (Resource server : api.list().concat()) { Server details = api.get(server.getId()); assertEquals(details.getId(), server.getId()); assertEquals(details.getName(), server.getName()); From 09065a32ca79fb2447fc976ab8aa8636be7a1a6d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 12:30:24 -0700 Subject: [PATCH 37/60] value and statistics values are not compatible in cloudwatch --- .../cloudwatch/binders/MetricDataBinder.java | 6 +- .../cloudwatch/domain/MetricDatum.java | 113 ++++++++++-------- .../binders/MetricDataBinderTest.java | 4 +- 3 files changed, 67 insertions(+), 56 deletions(-) diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java index 997f437b2f..38524189f2 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java @@ -93,8 +93,10 @@ public class MetricDataBinder implements org.jclouds.rest.Binder { formParameters.put("MetricData.member." + metricDatumIndex + ".Unit", String.valueOf(metricDatum.getUnit())); - formParameters.put("MetricData.member." + metricDatumIndex + ".Value", - String.valueOf(metricDatum.getValue())); + if (metricDatum.getValue().isPresent()) { + formParameters.put("MetricData.member." + metricDatumIndex + ".Value", + String.valueOf(metricDatum.getValue().get())); + } metricDatumIndex++; } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java index 2bd2d1385e..23745a9eb4 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java @@ -25,14 +25,16 @@ import java.util.Date; import java.util.Set; import com.google.common.base.Objects; -import com.google.common.base.Optional; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; /** - * @see - * + * @see + * * @author Jeremy Whitlock */ public class MetricDatum { @@ -42,17 +44,17 @@ public class MetricDatum { private final Optional statisticValues; private final Optional timestamp; private final Unit unit; - private final double value; + private final Optional value; /** * Private constructor to enforce using {@link Builder}. */ - protected MetricDatum(Set dimensions, String metricName, StatisticValues statisticValues, Date timestamp, - Unit unit, double value) { - this.dimensions = ImmutableSet.copyOf(checkNotNull(dimensions, "dimensions")); + protected MetricDatum(Iterable dimensions, String metricName, Optional statisticValues, + Optional timestamp, Unit unit, Optional value) { + this.dimensions = ImmutableSet. copyOf(checkNotNull(dimensions, "dimensions")); this.metricName = checkNotNull(metricName, "metricName"); - this.statisticValues = Optional.fromNullable(statisticValues); - this.timestamp = Optional.fromNullable(timestamp); + this.statisticValues = checkNotNull(statisticValues, "statisticValues"); + this.timestamp = checkNotNull(timestamp, "timestamp"); this.unit = checkNotNull(unit, "unit"); this.value = checkNotNull(value, "value"); } @@ -95,13 +97,13 @@ public class MetricDatum { /** * return the actual value of the metric */ - public double getValue() { + public Optional getValue() { return value; } /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. + * Returns a new builder. The generated builder is equivalent to the builder created by the + * {@link Builder} constructor. */ public static Builder builder() { return new Builder(); @@ -110,36 +112,39 @@ public class MetricDatum { public static class Builder { // this builder is set to be additive on dimension calls, so make this mutable - private Set dimensions = Sets.newLinkedHashSet(); + private ImmutableList.Builder dimensions = ImmutableList. builder(); private String metricName; - private StatisticValues statisticValues; - private Date timestamp; + private Optional statisticValues = Optional.absent(); + private Optional timestamp = Optional.absent(); private Unit unit = Unit.NONE; - private double value; + private Optional value = Optional.absent(); /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link org.jclouds.cloudwatch.domain.MetricDatum#builder}. + * Creates a new builder. The returned builder is equivalent to the builder generated by + * {@link org.jclouds.cloudwatch.domain.MetricDatum#builder}. */ - public Builder() {} + public Builder() { + } /** * A list of dimensions describing qualities of the metric. - * - * @param dimensions the dimensions describing the qualities of the metric - * + * + * @param dimensions + * the dimensions describing the qualities of the metric + * * @return this {@code Builder} object */ - public Builder dimensions(Set dimensions) { + public Builder dimensions(Iterable dimensions) { this.dimensions.addAll(checkNotNull(dimensions, "dimensions")); return this; } /** * A dimension describing qualities of the metric. - * - * @param dimension the dimension describing the qualities of the metric - * + * + * @param dimension + * the dimension describing the qualities of the metric + * * @return this {@code Builder} object */ public Builder dimension(Dimension dimension) { @@ -149,9 +154,10 @@ public class MetricDatum { /** * The name of the metric. - * - * @param metricName the metric name - * + * + * @param metricName + * the metric name + * * @return this {@code Builder} object */ public Builder metricName(String metricName) { @@ -161,34 +167,37 @@ public class MetricDatum { /** * The object describing the set of statistical values describing the metric. - * - * @param statisticValues the object describing the set of statistical values for the metric - * + * + * @param statisticValues + * the object describing the set of statistical values for the metric + * * @return this {@code Builder} object */ public Builder statisticValues(StatisticValues statisticValues) { - this.statisticValues = statisticValues; + this.statisticValues = Optional.fromNullable(statisticValues); return this; } /** - * The time stamp used for the metric. If not specified, the default value is set to the time the metric data was - * received. - * - * @param timestamp the time stamp used for the metric - * + * The time stamp used for the metric. If not specified, the default value is set to the time + * the metric data was received. + * + * @param timestamp + * the time stamp used for the metric + * * @return this {@code Builder} object */ public Builder timestamp(Date timestamp) { - this.timestamp = timestamp; + this.timestamp = Optional.fromNullable(timestamp); return this; } /** * The unit for the metric. - * - * @param unit the unit for the metric - * + * + * @param unit + * the unit for the metric + * * @return this {@code Builder} object */ public Builder unit(Unit unit) { @@ -198,13 +207,14 @@ public class MetricDatum { /** * The value for the metric. - * - * @param value the value for the metric - * + * + * @param value + * the value for the metric + * * @return this {@code Builder} object */ - public Builder value(double value) { - this.value = value; + public Builder value(Double value) { + this.value = Optional.fromNullable(value); return this; } @@ -212,7 +222,7 @@ public class MetricDatum { * Returns a newly-created {@code MetricDatum} based on the contents of the {@code Builder}. */ public MetricDatum build() { - return new MetricDatum(dimensions, metricName, statisticValues, timestamp, unit, value); + return new MetricDatum(dimensions.build(), metricName, statisticValues, timestamp, unit, value); } } @@ -240,7 +250,8 @@ public class MetricDatum { } protected ToStringHelper string() { - return Objects.toStringHelper("").add("dimensions", dimensions).add("metricName", metricName).add( - "statisticValues", statisticValues).add("timestamp", timestamp).add("unit", unit).add("value", value); + return Objects.toStringHelper("").omitNullValues().add("dimensions", dimensions).add("metricName", metricName) + .add("statisticValues", statisticValues.orNull()).add("timestamp", timestamp.orNull()).add("unit", unit) + .add("value", value.orNull()); } } diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java index 94dcac48f6..003fb90274 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java @@ -60,7 +60,6 @@ public class MetricDataBinderTest { .statisticValues(ss) .dimension(new Dimension("TestDimension", "FAKE")) .unit(Unit.COUNT) - .value(2) .build(); HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of(metricDatum)); @@ -73,8 +72,7 @@ public class MetricDataBinderTest { "&MetricData.member.1.StatisticValues.Minimum=1.0" + "&MetricData.member.1.StatisticValues.SampleCount=4.0" + "&MetricData.member.1.StatisticValues.Sum=10.0" + - "&MetricData.member.1.Unit=" + Unit.COUNT.toString() + - "&MetricData.member.1.Value=2.0"); + "&MetricData.member.1.Unit=" + Unit.COUNT.toString()); } public void testMetricWithMultipleDimensions() throws Exception { From fae9ec122887ba1742d5ef2c0e5cf157c9e77941 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 12:36:41 -0700 Subject: [PATCH 38/60] straightened out AdminActionsApi test --- .../jclouds/openstack/nova/v2_0/NovaApi.java | 2 +- .../openstack/nova/v2_0/NovaAsyncApi.java | 2 +- .../compute/NovaComputeServiceAdapter.java | 8 +- .../extensions/AdminActionsApiExpectTest.java | 48 ++--- .../extensions/AdminActionsApiLiveTest.java | 166 +++++++++--------- 5 files changed, 116 insertions(+), 110 deletions(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java index 6898540d44..1940faf3e0 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApi.java @@ -156,7 +156,7 @@ public interface NovaApi { * Provides synchronous access to Server Admin Actions features. */ @Delegate - Optional getAdminActionsExtensionForZone( + Optional getServerAdminExtensionForZone( @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java index 1f22a6ec01..09631d323f 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaAsyncApi.java @@ -155,7 +155,7 @@ public interface NovaAsyncApi { * Provides asynchronous access to Server Admin Actions features. */ @Delegate - Optional getAdminActionsExtensionForZone( + Optional getServerAdminExtensionForZone( @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); /** diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java index 67a94910b9..f934682efe 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java @@ -249,8 +249,8 @@ public class NovaComputeServiceAdapter implements @Override public void resumeNode(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); - if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) { - novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId()); + if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) { + novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId()); } throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension"); } @@ -258,8 +258,8 @@ public class NovaComputeServiceAdapter implements @Override public void suspendNode(String id) { ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); - if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) { - novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId()); + if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) { + novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId()); } throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension"); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java index 58285d06b2..e2906f77d7 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java @@ -52,7 +52,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.suspend("1")); } @@ -64,7 +64,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.suspend("1")); } @@ -77,7 +77,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), HttpResponse.builder().statusCode(403).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); api.suspend("1"); } @@ -89,7 +89,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.resume("1")); } @@ -101,7 +101,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.resume("1")); } @@ -114,7 +114,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), HttpResponse.builder().statusCode(403).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); api.resume("1"); } @@ -126,7 +126,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "lock").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.lock("1")); } @@ -138,7 +138,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "lock").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.lock("1")); } @@ -150,7 +150,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.unlock("1")); } @@ -162,7 +162,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.unlock("1")); } @@ -174,7 +174,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "pause").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.pause("1")); } @@ -186,7 +186,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "pause").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.pause("1")); } @@ -198,7 +198,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.unpause("1")); } @@ -210,7 +210,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.unpause("1")); } @@ -222,7 +222,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.migrate("1")); } @@ -235,7 +235,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.migrate("1")); } @@ -247,7 +247,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.resetNetwork("1")); } @@ -259,7 +259,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.resetNetwork("1")); } @@ -271,7 +271,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.injectNetworkInfo("1")); } @@ -283,7 +283,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.injectNetworkInfo("1")); } @@ -295,7 +295,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action").method("POST") .payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(202).addHeader("Location", "http://172.16.89.149:8774/v2/images/1976b3b3-409a-468d-b16c-a9172c341b46").build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); String imageId = api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other"))); assertEquals(imageId, "1976b3b3-409a-468d-b16c-a9172c341b46"); @@ -310,7 +310,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { authenticatedGET().endpoint(endpoint).method("POST") .payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other"))); } @@ -323,7 +323,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") .payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(202).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertTrue(api.liveMigrate("1", "bighost", true, false)); } @@ -336,7 +336,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest { standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") .payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(), HttpResponse.builder().statusCode(404).build() - ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); + ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get(); assertFalse(api.liveMigrate("1", "bighost", true, false)); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java index d9ea62936b..602517c9f8 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java @@ -32,6 +32,7 @@ import org.jclouds.openstack.nova.v2_0.features.ServerApi; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions; import org.jclouds.openstack.v2_0.features.ExtensionApi; +import org.testng.SkipException; import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeGroups; @@ -45,7 +46,7 @@ import com.google.common.collect.Iterables; * Tests behavior of HostAdministrationApi * * TODO test migration methods - * + * * @author Adam Lowe */ @Test(groups = "live", testName = "AdminActionsApiLiveTest", singleThreaded = true) @@ -59,7 +60,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { private String testServerId; private String backupImageId; - @BeforeGroups(groups = {"integration", "live"}) + @BeforeGroups(groups = { "integration", "live" }) @Override public void setupContext() { super.setupContext(); @@ -67,7 +68,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { serverApi = novaContext.getApi().getServerApiForZone(zone); extensionApi = novaContext.getApi().getExtensionApiForZone(zone); imageApi = novaContext.getApi().getImageApiForZone(zone); - apiOption = novaContext.getApi().getAdminActionsExtensionForZone(zone); + apiOption = novaContext.getApi().getServerAdminExtensionForZone(zone); if (apiOption.isPresent()) { testServerId = createServerInZone(zone).getId(); } @@ -87,105 +88,110 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { super.tearDown(); } + protected void skipOnAdminExtensionAbsent() { + if (!apiOption.isPresent()) { + throw new SkipException("Test depends on ServerAdminApi extension"); + } + } + @AfterMethod(alwaysRun = true) public void ensureServerIsActiveAgain() { - blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); - } - - public void testSuspendAndResume() { - if (apiOption.isPresent()) { - ServerAdminApi api = apiOption.get(); - - // Suspend-resume - try { - api.resume(testServerId); - fail("Resumed an active server!"); - } catch (HttpResponseException e) { - } - assertTrue(api.suspend(testServerId)); - blockUntilServerInState(testServerId, serverApi, Status.SUSPENDED); - try { - api.suspend(testServerId); - fail("Suspended an already suspended server!"); - } catch (HttpResponseException e) { - } - assertTrue(api.resume(testServerId)); + if (apiOption.isPresent()) blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); - try { - api.resume(testServerId); - fail("Resumed an already resumed server!"); - } catch (HttpResponseException e) { - } + } + + public void testSuspendAndResume() { + skipOnAdminExtensionAbsent(); + ServerAdminApi api = apiOption.get(); + + // Suspend-resume + try { + api.resume(testServerId); + fail("Resumed an active server!"); + } catch (HttpResponseException e) { } + assertTrue(api.suspend(testServerId)); + blockUntilServerInState(testServerId, serverApi, Status.SUSPENDED); + try { + api.suspend(testServerId); + fail("Suspended an already suspended server!"); + } catch (HttpResponseException e) { + } + assertTrue(api.resume(testServerId)); + blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); + try { + api.resume(testServerId); + fail("Resumed an already resumed server!"); + } catch (HttpResponseException e) { + } + } public void testLockAndUnlock() { - if (apiOption.isPresent()) { - ServerAdminApi api = apiOption.get(); + skipOnAdminExtensionAbsent(); + ServerAdminApi api = apiOption.get(); + + // TODO should we be able to double-lock (as it were) + assertTrue(api.unlock(testServerId)); + assertTrue(api.unlock(testServerId)); + assertTrue(api.lock(testServerId)); + assertTrue(api.lock(testServerId)); + assertTrue(api.unlock(testServerId)); + assertTrue(api.unlock(testServerId)); - // TODO should we be able to double-lock (as it were) - assertTrue(api.unlock(testServerId)); - assertTrue(api.unlock(testServerId)); - assertTrue(api.lock(testServerId)); - assertTrue(api.lock(testServerId)); - assertTrue(api.unlock(testServerId)); - assertTrue(api.unlock(testServerId)); - } } public void testResetNetworkAndInjectNetworkInfo() { - if (apiOption.isPresent()) { - ServerAdminApi api = apiOption.get(); - assertTrue(api.resetNetwork(testServerId)); - assertTrue(api.injectNetworkInfo(testServerId)); - } + skipOnAdminExtensionAbsent(); + ServerAdminApi api = apiOption.get(); + assertTrue(api.resetNetwork(testServerId)); + assertTrue(api.injectNetworkInfo(testServerId)); } @Test public void testPauseAndUnpause() { - if (apiOption.isPresent()) { - ServerAdminApi api = apiOption.get(); + skipOnAdminExtensionAbsent(); + ServerAdminApi api = apiOption.get(); - // Unlock and lock (double-checking error contitions too) - try { - api.unpause(testServerId); - fail("Unpaused active server!"); - } catch (HttpResponseException e) { - } - assertTrue(api.pause(testServerId)); - blockUntilServerInState(testServerId, serverApi, Status.PAUSED); - try { - api.pause(testServerId); - fail("paused a paused server!"); - } catch (HttpResponseException e) { - } - assertTrue(api.unpause(testServerId)); - blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); - try { - api.unpause(testServerId); - fail("Unpaused a server we just unpaused!"); - } catch (HttpResponseException e) { - } + // Unlock and lock (double-checking error contitions too) + try { + api.unpause(testServerId); + fail("Unpaused active server!"); + } catch (HttpResponseException e) { } + assertTrue(api.pause(testServerId)); + blockUntilServerInState(testServerId, serverApi, Status.PAUSED); + try { + api.pause(testServerId); + fail("paused a paused server!"); + } catch (HttpResponseException e) { + } + assertTrue(api.unpause(testServerId)); + blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); + try { + api.unpause(testServerId); + fail("Unpaused a server we just unpaused!"); + } catch (HttpResponseException e) { + } + } @Test public void testCreateBackupOfServer() throws InterruptedException { - if (apiOption.isPresent()) { - backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0, + skipOnAdminExtensionAbsent(); + backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("test", "metadata"))); - assertNotNull(backupImageId); - - // If we don't have extended task status, we'll have to wait here! - if (extensionApi.get("OS-EXT-STS") == null) { - Thread.sleep(30000); - } - - blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); - - Image backupImage = imageApi.get(backupImageId); - assertEquals(backupImage.getId(), backupImageId); + assertNotNull(backupImageId); + + // If we don't have extended task status, we'll have to wait here! + if (extensionApi.get("OS-EXT-STS") == null) { + Thread.sleep(30000); } - } + + blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); + + Image backupImage = imageApi.get(backupImageId); + assertEquals(backupImage.getId(), backupImageId); + } } From 6f5ebf3e90cbf43c9ea9c011520b567a04b6f09b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 12:55:48 -0700 Subject: [PATCH 39/60] Issue 1085:deprecate getRegion from EC2 domain objects --- .../main/java/org/jclouds/ec2/domain/Attachment.java | 6 +++++- .../main/java/org/jclouds/ec2/domain/BundleTask.java | 5 ++++- .../src/main/java/org/jclouds/ec2/domain/Image.java | 5 ++++- .../org/jclouds/ec2/domain/InstanceStateChange.java | 6 +++++- .../src/main/java/org/jclouds/ec2/domain/KeyPair.java | 6 +++++- .../jclouds/ec2/domain/PublicIpInstanceIdPair.java | 6 +++++- .../main/java/org/jclouds/ec2/domain/Reservation.java | 6 +++++- .../jclouds/ec2/domain/ReservedInstancesOffering.java | 9 ++++++++- .../java/org/jclouds/ec2/domain/RunningInstance.java | 6 +++++- .../java/org/jclouds/ec2/domain/SecurityGroup.java | 11 ++++++----- .../main/java/org/jclouds/ec2/domain/Snapshot.java | 8 ++++++-- .../src/main/java/org/jclouds/ec2/domain/Volume.java | 7 +++++-- .../org/jclouds/aws/ec2/domain/PlacementGroup.java | 6 +++++- .../main/java/org/jclouds/aws/ec2/domain/Spot.java | 7 +++++++ 14 files changed, 75 insertions(+), 19 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Attachment.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Attachment.java index 0f1e79bc89..73a6fee3b4 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Attachment.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Attachment.java @@ -114,8 +114,12 @@ public class Attachment implements Comparable { } /** - * Snapshots are tied to Regions and can only be used for volumes within the same Region. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/BundleTask.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/BundleTask.java index 235004493d..9ec3bbd2e5 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/BundleTask.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/BundleTask.java @@ -209,9 +209,12 @@ public class BundleTask implements Comparable { } /** + * To be removed in jclouds 1.6

Warning

* - * @return region of the bundle task + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java index 99bb4ae5e6..1c50e637e1 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Image.java @@ -219,9 +219,12 @@ public class Image implements Comparable { } /** - * AMIs are tied to the Region where its files are located within Amazon S3. + * To be removed in jclouds 1.6

Warning

* + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/InstanceStateChange.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/InstanceStateChange.java index 3f0518769a..ab38a4b5f1 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/InstanceStateChange.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/InstanceStateChange.java @@ -47,8 +47,12 @@ public class InstanceStateChange implements Comparable { } /** - * Instances are tied to Availability Zones. However, the instance ID is tied to the Region. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/KeyPair.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/KeyPair.java index ead73cb9e3..bd927a3893 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/KeyPair.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/KeyPair.java @@ -103,8 +103,12 @@ public class KeyPair implements Comparable { } /** - * Key pairs (to connect to instances) are Region-specific. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/PublicIpInstanceIdPair.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/PublicIpInstanceIdPair.java index 8f03cab684..189fe7c92f 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/PublicIpInstanceIdPair.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/PublicIpInstanceIdPair.java @@ -42,8 +42,12 @@ public class PublicIpInstanceIdPair implements ComparableWarning + * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Reservation.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Reservation.java index 7ce47eb0b9..5a621b290d 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Reservation.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Reservation.java @@ -156,8 +156,12 @@ public class Reservation extends ForwardingSet imp } /** - * Instances are tied to Availability Zones. However, the instance ID is tied to the Region. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/ReservedInstancesOffering.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/ReservedInstancesOffering.java index f7987de2b1..a1f78e6337 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/ReservedInstancesOffering.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/ReservedInstancesOffering.java @@ -46,10 +46,17 @@ public class ReservedInstancesOffering implements ComparableWarning + * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. + */ + @Deprecated public String getRegion() { return region; } - + /** * @return The Availability Zone in which the Reserved Instance can be used. */ diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java index a1573793f0..bb4613bff2 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java @@ -290,8 +290,12 @@ public class RunningInstance implements Comparable { } /** - * Instance Ids are scoped to the region. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java index ebf1f6d5da..db36b5a634 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java @@ -49,13 +49,14 @@ public class SecurityGroup implements Comparable { this.description = description; this.ipPermissions = ipPermissions; } - + /** - * Security groups are not copied across Regions. Instances within the Region - * cannot communicate with instances outside the Region using group-based - * firewall rules. Traffic from instances in another Region is seen as WAN - * bandwidth. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Snapshot.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Snapshot.java index f01d01a40e..8acfbff519 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Snapshot.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Snapshot.java @@ -75,12 +75,16 @@ public class Snapshot implements Comparable { } /** - * Snapshots are tied to Regions and can only be used for volumes within the same Region. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } - + /** * The ID of the snapshot. */ diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java index 427560be3f..f264e1847b 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java @@ -172,9 +172,12 @@ public class Volume implements Comparable { } /** - * An Amazon EBS volume must be located within the same Availability Zone as the instance to - * which it attaches. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/PlacementGroup.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/PlacementGroup.java index db0dfee5f9..9250fc418c 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/PlacementGroup.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/PlacementGroup.java @@ -77,8 +77,12 @@ public class PlacementGroup implements Comparable { } /** - * @return placement groups are in a region, however the namescope is global. + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. */ + @Deprecated public String getRegion() { return region; } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/Spot.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/Spot.java index c5b21c9964..75e2d3cbea 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/Spot.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/Spot.java @@ -92,6 +92,13 @@ public class Spot implements Comparable { this.timestamp = checkNotNull(timestamp, "timestamp"); } + /** + * To be removed in jclouds 1.6

Warning

+ * + * Especially on EC2 clones that may not support regions, this value is fragile. Consider + * alternate means to determine context. + */ + @Deprecated public String getRegion() { return region; } From 1e50fbeb69bd3fc72ed2ce3aa5359ffbf9071164 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Sun, 16 Sep 2012 23:08:17 +0300 Subject: [PATCH 40/60] Switched from a Provider to a Supplier as requested --- .../blobstore/SwiftBlobRequestSigner.java | 9 ++-- .../config/SwiftBlobStoreContextModule.java | 21 ++++---- .../ReturnOrFetchTemporaryUrlKey.java | 49 +++++++++++++++++++ .../swift/CommonSwiftClientTest.java | 20 +++++--- 4 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/suppliers/ReturnOrFetchTemporaryUrlKey.java diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java index 4da0517a2a..b14d0f87fc 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java @@ -30,6 +30,7 @@ import java.security.InvalidKeyException; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.base.Supplier; import com.google.common.base.Throwables; import com.google.inject.Provider; import org.jclouds.blobstore.BlobRequestSigner; @@ -57,7 +58,7 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { private final Crypto crypto; private final Provider unixEpochTimestampProvider; - private final Provider temporaryUrlKeyProvider; + private final Supplier temporaryUrlKeySupplier; private final BlobToObject blobToObject; private final BlobToHttpGetOptions blob2HttpGetOptions; @@ -69,12 +70,12 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { @Inject public SwiftBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, @TimeStamp Provider unixEpochTimestampProvider, - @TemporaryUrlKey Provider temporaryUrlKeyProvider) throws SecurityException, NoSuchMethodException { + @TemporaryUrlKey Supplier temporaryUrlKeySupplier) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.crypto = checkNotNull(crypto, "crypto"); this.unixEpochTimestampProvider = checkNotNull(unixEpochTimestampProvider, "unixEpochTimestampProvider"); - this.temporaryUrlKeyProvider = checkNotNull(temporaryUrlKeyProvider, "temporaryUrlKeyProvider"); + this.temporaryUrlKeySupplier = checkNotNull(temporaryUrlKeySupplier, "temporaryUrlKeyProvider"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); @@ -121,7 +122,7 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { HttpRequest.Builder builder = request.toBuilder(); builder.filters(filter(request.getFilters(), instanceOf(AuthenticateRequest.class))); - String key = temporaryUrlKeyProvider.get(); + String key = temporaryUrlKeySupplier.get(); if (key == null) { throw new UnsupportedOperationException(); } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java index ae9ce38aa8..fc93747625 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java @@ -18,7 +18,9 @@ */ package org.jclouds.openstack.swift.blobstore.config; +import com.google.common.base.Supplier; import com.google.inject.Provides; +import com.google.inject.TypeLiteral; import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobStore; @@ -34,6 +36,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Scopes; import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyAsyncApi; +import org.jclouds.openstack.swift.suppliers.ReturnOrFetchTemporaryUrlKey; import java.util.UUID; @@ -53,18 +56,6 @@ public class SwiftBlobStoreContextModule extends AbstractModule { return System.currentTimeMillis() / 1000; /* convert to seconds */ } - @Provides - @TemporaryUrlKey - protected String temporaryUrlKeyProvider(TemporaryUrlKeyApi client) { - String key = client.getTemporaryUrlKey(); - if (key == null) { - client.setTemporaryUrlKey(UUID.randomUUID().toString()); - return client.getTemporaryUrlKey(); - } - return key; - } - - @Override protected void configure() { install(new BlobStoreMapModule()); @@ -72,6 +63,12 @@ public class SwiftBlobStoreContextModule extends AbstractModule { bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON); bind(BlobRequestSigner.class).to(SwiftBlobRequestSigner.class); + configureTemporaryUrlExtension(); + } + + protected void configureTemporaryUrlExtension() { bindClientAndAsyncClient(binder(), TemporaryUrlKeyApi.class, TemporaryUrlKeyAsyncApi.class); + bind(new TypeLiteral>() { + }).annotatedWith(TemporaryUrlKey.class).to(ReturnOrFetchTemporaryUrlKey.class); } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/suppliers/ReturnOrFetchTemporaryUrlKey.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/suppliers/ReturnOrFetchTemporaryUrlKey.java new file mode 100644 index 0000000000..0c0aad2b4c --- /dev/null +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/suppliers/ReturnOrFetchTemporaryUrlKey.java @@ -0,0 +1,49 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.swift.suppliers; + +import com.google.common.base.Supplier; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; + +import java.util.UUID; + +import static com.google.common.base.Preconditions.checkNotNull; + +@Singleton +public class ReturnOrFetchTemporaryUrlKey implements Supplier { + + private TemporaryUrlKeyApi client; + + @Inject + public ReturnOrFetchTemporaryUrlKey(TemporaryUrlKeyApi client) { + this.client = checkNotNull(client, "client"); + } + + @Override + public String get() { + String key = client.getTemporaryUrlKey(); + if (key == null) { + client.setTemporaryUrlKey(UUID.randomUUID().toString()); + return client.getTemporaryUrlKey(); + } + return key; + } +} diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java index 6e7308eab8..667f3d0c0e 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java @@ -21,13 +21,18 @@ package org.jclouds.openstack.swift; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; +import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; import java.net.URI; import java.util.Properties; import javax.inject.Singleton; +import com.google.common.base.Suppliers; +import com.google.inject.*; +import com.google.inject.util.Modules; import org.jclouds.apis.ApiMetadata; +import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService; import org.jclouds.openstack.internal.TestOpenStackAuthenticationModule; @@ -35,15 +40,14 @@ import org.jclouds.openstack.reference.AuthHeaders; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule; import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; +import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyAsyncApi; +import org.jclouds.openstack.swift.suppliers.ReturnOrFetchTemporaryUrlKey; import org.jclouds.rest.internal.BaseAsyncClientTest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; /** * Tests behavior of {@code BindSwiftObjectMetadataToRequest} @@ -79,15 +83,17 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest>() { + }).annotatedWith(TemporaryUrlKey.class).toInstance(Suppliers.ofInstance(TEMPORARY_URL_KEY)); } } @@ -95,7 +101,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest>of(StorageEndpointModule.class, SwiftRestClientModule.class, - FixedSwiftBlobStoreContextModule.class)).build(); + StaticTimeAndTemporaryUrlKeyModule.class)).build(); } @Override From d9c71923a6d4b23af63305821d7b2211bcaa2884 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 14:56:57 -0700 Subject: [PATCH 41/60] param parsers can accept nullable params --- .../internal/RestAnnotationProcessor.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index ba42417faf..1a8376e682 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -1205,17 +1205,26 @@ public class RestAnnotationProcessor { protected Optional getParamValue(Method method, Object[] args, Set extractors, Entry> entry, String paramKey) { - Object arg = args[entry.getKey()]; - if (arg == null && containsNullable(method.getParameterAnnotations()[entry.getKey()])) - return Optional.absent(); - - checkNotNull(arg, "param{%s} for method %s.%s", paramKey, method.getDeclaringClass().getSimpleName(), - method.getName()); - if (extractors != null && extractors.size() > 0) { + Integer argIndex = entry.getKey(); + Object arg = args[argIndex]; + if (extractors != null && extractors.size() > 0 && checkPresentOrNullable(method, paramKey, argIndex, arg)) { ParamParser extractor = (ParamParser) extractors.iterator().next(); - return Optional.of(injector.getInstance(extractor.value()).apply(arg)); + // ParamParsers can deal with nullable parameters + arg = injector.getInstance(extractor.value()).apply(arg); } - return Optional.of(arg); + checkPresentOrNullable(method, paramKey, argIndex, arg); + return Optional.fromNullable(arg); + } + + private static boolean checkPresentOrNullable(Method method, String paramKey, Integer argIndex, Object arg) { + if (arg == null && !argNullable(method, argIndex)) + throw new NullPointerException(String.format("param{%s} for method %s.%s", paramKey, method + .getDeclaringClass().getSimpleName(), method.getName())); + return true; + } + + private static boolean argNullable(Method method, Integer argIndex) { + return containsNullable(method.getParameterAnnotations()[argIndex]); } private static final Predicate NULLABLE = new Predicate() { From b9bef78fc8b3e91f223c24470bba11c77e339192 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 14:57:24 -0700 Subject: [PATCH 42/60] add title to savvis test --- .../org/jclouds/savvis/vpdc/features/BrowsingAsyncApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncApiTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncApiTest.java index 0aa9a1b050..b55ab503ea 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncApiTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncApiTest.java @@ -42,7 +42,7 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "BrowsingAsyncApiTest") public class BrowsingAsyncApiTest extends BaseVPDCAsyncApiTest { public void testOrg() throws SecurityException, NoSuchMethodException, IOException { From a0c383334e3d933eb56b39c3c599149765b68c29 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 14:58:07 -0700 Subject: [PATCH 43/60] Boolean -> boolean --- .../org/jclouds/openstack/nova/v2_0/features/ServerApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java index c289e24a95..6e95bf39e1 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java @@ -96,7 +96,7 @@ public interface ServerApi { * id of the server * @return True if successful, False otherwise */ - Boolean delete(String id); + boolean delete(String id); /** * Start a server From 80d3b177200605b01be7136ac277481d92dcfe1d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 14:58:34 -0700 Subject: [PATCH 44/60] elastichosts test glitches --- apis/elasticstack/pom.xml | 18 ++--------------- .../ElasticStackClientLiveTest.java | 20 +++++++------------ 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/apis/elasticstack/pom.xml b/apis/elasticstack/pom.xml index eabb89ac43..884444949a 100644 --- a/apis/elasticstack/pom.xml +++ b/apis/elasticstack/pom.xml @@ -33,27 +33,13 @@ jclouds components to access elasticstack bundle - - - - sonatype-nexus-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - https://api-lon-p.elastichosts.com - 1.0 + 2.0 FIXME FIXME - imageId=38df0986-4d85-4b76-b502-3878ffc80161 + imageId=38df0986-4d85-4b76-b502-3878ffc80161,loginUser=toor org.jclouds.elasticstack*;version="${project.version}" org.jclouds.compute.internal;version="${project.version}", diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index badcb39087..5dcca7e56f 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -50,7 +50,7 @@ import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.util.Strings2; import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -67,10 +67,8 @@ import com.google.inject.Guice; * @author Adrian Cole */ @Test(groups = "live", singleThreaded = true, testName = "ElasticStackClientLiveTest") -public class ElasticStackClientLiveTest - extends - BaseComputeServiceContextLiveTest { - +public class ElasticStackClientLiveTest extends BaseComputeServiceContextLiveTest { + public ElasticStackClientLiveTest() { provider = "elasticstack"; } @@ -84,23 +82,19 @@ public class ElasticStackClientLiveTest protected Predicate driveNotClaimed; protected String imageId; - @BeforeGroups(groups = { "integration", "live" }) @Override + @BeforeClass(groups = { "integration", "live" }) public void setupContext() { super.setupContext(); - cloudStackContext = view.unwrap(); + imageId = view.getComputeService().templateBuilder().build().getImage().getId(); - client = cloudStackContext.getApi(); + client = view.unwrap(ElasticStackApiMetadata.CONTEXT_TOKEN).getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, TimeUnit.SECONDS); - - if (template == null || template.getImageId() == null) { - imageId = view.getComputeService().templateBuilder().build().getImage().getId(); - } } - + @Test public void testListServers() throws Exception { Set servers = client.listServers(); From e4a41e49fa5c164dab3de847b208c82e2f541395 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 15:03:20 -0700 Subject: [PATCH 45/60] fixed missing nullable --- .../java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java | 5 +++-- .../org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java index 7a8a4628c7..03ec4357cf 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCApi.java @@ -32,10 +32,12 @@ import org.jclouds.fujitsu.fgcp.domain.ServerType; import org.jclouds.fujitsu.fgcp.domain.UsageInfo; import org.jclouds.fujitsu.fgcp.domain.VSystem; import org.jclouds.fujitsu.fgcp.domain.VSystemDescriptor; +import org.jclouds.javax.annotation.Nullable; /** * API relating to the virtual data center. * + * @see VirtualDCAsyncApi * @author Dies Koper */ @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) @@ -51,8 +53,7 @@ public interface VirtualDCApi { Set listDiskImages(); - Set listDiskImages(String serverCategory, - String vsysDescriptorId); + Set listDiskImages(@Nullable String serverCategory, String vsysDescriptorId); Map listPublicIPs(); diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java index b9e85191ad..7836893678 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/services/VirtualDCAsyncApi.java @@ -41,6 +41,7 @@ import org.jclouds.fujitsu.fgcp.domain.VSystem; import org.jclouds.fujitsu.fgcp.domain.VSystemDescriptor; import org.jclouds.fujitsu.fgcp.filters.RequestAuthenticator; import org.jclouds.fujitsu.fgcp.reference.RequestParameters; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.PayloadParams; import org.jclouds.rest.annotations.QueryParams; @@ -102,7 +103,7 @@ public interface VirtualDCAsyncApi { @JAXBResponseParser @QueryParams(keys = "Action", values = "ListDiskImage") ListenableFuture> listDiskImages( - @QueryParam("serverCategory") String serverCategory, + @Nullable @QueryParam("serverCategory") String serverCategory, @QueryParam("vsysDescriptorId") String vsysDescriptorId); /** From 171c0804e06a54e9000de368666b8982196d1174 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 16:20:07 -0700 Subject: [PATCH 46/60] conventions update for glesys --- .../java/org/jclouds/glesys/GleSYSApi.java | 4 +- .../org/jclouds/glesys/GleSYSAsyncApi.java | 4 +- .../compute/GleSYSComputeServiceAdapter.java | 22 ++-- .../options/GleSYSTemplateOptions.java | 2 +- .../glesys/config/GleSYSRestClientModule.java | 6 +- .../domain/ArchiveAllowedArguments.java | 6 +- .../org/jclouds/glesys/domain/Domain.java | 6 +- .../jclouds/glesys/domain/DomainRecord.java | 6 +- .../jclouds/glesys/domain/EmailOverview.java | 6 +- .../glesys/domain/EmailOverviewDomain.java | 6 +- .../jclouds/glesys/features/ArchiveApi.java | 19 ++-- .../glesys/features/ArchiveAsyncApi.java | 35 +++--- .../jclouds/glesys/features/DomainApi.java | 20 ++-- .../glesys/features/DomainAsyncApi.java | 35 +++--- .../{EmailApi.java => EmailAccountApi.java} | 25 +++-- ...syncApi.java => EmailAccountAsyncApi.java} | 43 ++++---- .../org/jclouds/glesys/features/IpApi.java | 21 ++-- .../jclouds/glesys/features/IpAsyncApi.java | 31 +++--- .../jclouds/glesys/features/ServerApi.java | 36 +++--- .../glesys/features/ServerAsyncApi.java | 67 +++++------ .../ParseTemplatesFromHttpResponse.java | 8 +- .../glesys/options/CloneServerOptions.java | 4 +- .../glesys/options/EditAccountOptions.java | 77 ------------- .../glesys/options/UpdateAccountOptions.java | 77 +++++++++++++ ...dOptions.java => UpdateRecordOptions.java} | 37 ++++--- ...rOptions.java => UpdateServerOptions.java} | 50 ++++----- .../jclouds/glesys/GleSYSAsyncApiTest.java | 4 +- .../glesys/features/ArchiveApiExpectTest.java | 32 +++--- .../glesys/features/ArchiveApiLiveTest.java | 28 ++--- .../glesys/features/DomainApiExpectTest.java | 49 +++++---- .../glesys/features/DomainApiLiveTest.java | 28 ++--- ...st.java => EmailAccountApiExpectTest.java} | 104 +++++++++--------- ...Test.java => EmailAccountApiLiveTest.java} | 54 ++++----- .../glesys/features/IpApiExpectTest.java | 24 ++-- .../glesys/features/IpApiLiveTest.java | 37 ++++--- .../glesys/features/ServerApiExpectTest.java | 63 ++++++----- .../glesys/features/ServerApiLiveTest.java | 44 ++++---- .../internal/BaseGleSYSApiLiveTest.java | 6 +- .../BaseGleSYSApiWithAServerLiveTest.java | 12 +- 39 files changed, 575 insertions(+), 563 deletions(-) rename labs/glesys/src/main/java/org/jclouds/glesys/features/{EmailApi.java => EmailAccountApi.java} (80%) rename labs/glesys/src/main/java/org/jclouds/glesys/features/{EmailAsyncApi.java => EmailAccountAsyncApi.java} (64%) delete mode 100644 labs/glesys/src/main/java/org/jclouds/glesys/options/EditAccountOptions.java create mode 100644 labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java rename labs/glesys/src/main/java/org/jclouds/glesys/options/{EditRecordOptions.java => UpdateRecordOptions.java} (59%) rename labs/glesys/src/main/java/org/jclouds/glesys/options/{EditServerOptions.java => UpdateServerOptions.java} (56%) rename labs/glesys/src/test/java/org/jclouds/glesys/features/{EmailApiExpectTest.java => EmailAccountApiExpectTest.java} (81%) rename labs/glesys/src/test/java/org/jclouds/glesys/features/{EmailApiLiveTest.java => EmailAccountApiLiveTest.java} (74%) diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java index 7852a01d4f..cdc7f499c3 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.glesys.features.ArchiveApi; import org.jclouds.glesys.features.DomainApi; -import org.jclouds.glesys.features.EmailApi; +import org.jclouds.glesys.features.EmailAccountApi; import org.jclouds.glesys.features.IpApi; import org.jclouds.glesys.features.ServerApi; import org.jclouds.rest.annotations.Delegate; @@ -67,6 +67,6 @@ public interface GleSYSApi { * Provides synchronous access to E-Mail features. */ @Delegate - EmailApi getEmailApi(); + EmailAccountApi getEmailAccountApi(); } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java index 65cedb0306..fd341eb104 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java @@ -20,7 +20,7 @@ package org.jclouds.glesys; import org.jclouds.glesys.features.ArchiveAsyncApi; import org.jclouds.glesys.features.DomainAsyncApi; -import org.jclouds.glesys.features.EmailAsyncApi; +import org.jclouds.glesys.features.EmailAccountAsyncApi; import org.jclouds.glesys.features.IpAsyncApi; import org.jclouds.glesys.features.ServerAsyncApi; import org.jclouds.rest.annotations.Delegate; @@ -63,6 +63,6 @@ public interface GleSYSAsyncApi { * Provides asynchronous access to E-Mail features. */ @Delegate - EmailAsyncApi getEmailApi(); + EmailAccountAsyncApi getEmailAccountApi(); } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java index 05ec0d3de2..63e390807a 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java @@ -132,7 +132,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter> creating new Server spec(%s) name(%s) options(%s)", spec, name, createServerOptions); - ServerDetails result = api.getServerApi().createServerWithHostnameAndRootPassword(spec, name, password, + ServerDetails result = api.getServerApi().createWithHostnameAndRootPassword(spec, name, password, createServerOptions); logger.trace("<< server(%s)", result.getId()); @@ -163,7 +163,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter images = listImages(); for (Entry platformToArgs : api.getServerApi() - .getAllowedArgumentsForCreateServerByPlatform().entrySet()) + .getAllowedArgumentsForCreateByPlatform().entrySet()) for (String datacenter : platformToArgs.getValue().getDataCenters()) for (int diskSizeGB : platformToArgs.getValue().getDiskSizesInGB()) for (int cpuCores : platformToArgs.getValue().getCpuCoreOptions()) @@ -192,7 +192,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter listImages() { - return api.getServerApi().listTemplates(); + return api.getServerApi().listTemplates().toImmutableSet(); } // cheat until we have a getTemplate command @@ -210,10 +210,10 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter listNodes() { - return Iterables2.concreteCopy(transformParallel(api.getServerApi().listServers(), new Function>() { + return Iterables2.concreteCopy(transformParallel(api.getServerApi().list(), new Function>() { @Override public Future apply(Server from) { - return aapi.getServerApi().getServerDetails(from.getId()); + return aapi.getServerApi().get(from.getId()); } }, userThreads, null, logger, "server details")); @@ -222,7 +222,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter listLocations() { return ImmutableSet.copyOf(Iterables.concat(Iterables.transform(api.getServerApi() - .getAllowedArgumentsForCreateServerByPlatform().values(), + .getAllowedArgumentsForCreateByPlatform().values(), new Function>() { @Override @@ -235,7 +235,7 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter archiveSizes = ImmutableList.of(); /** - * @see ArchiveAllowedArguments#getArchiveSizes() + * @see ArchiveAllowedArguments#getSizes() */ public T archiveSizes(List archiveSizes) { this.archiveSizes = ImmutableList.copyOf(checkNotNull(archiveSizes, "archiveSizes")); @@ -65,7 +65,7 @@ public class ArchiveAllowedArguments { } public T fromArchiveAllowedArguments(ArchiveAllowedArguments in) { - return this.archiveSizes(in.getArchiveSizes()); + return this.archiveSizes(in.getSizes()); } } @@ -88,7 +88,7 @@ public class ArchiveAllowedArguments { /** * @return the list of allowed archive sizes, in GB */ - public List getArchiveSizes() { + public List getSizes() { return this.archiveSizes; } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java b/labs/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java index 30b34b428e..59774e902a 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java @@ -60,7 +60,7 @@ public class Domain { protected int minimum; /** - * @see Domain#getDomainName() + * @see Domain#getName() */ public T domainName(String domainName) { this.domainName = checkNotNull(domainName, "domainName"); @@ -152,7 +152,7 @@ public class Domain { } public T fromDomain(Domain in) { - return this.domainName(in.getDomainName()) + return this.domainName(in.getName()) .createTime(in.getCreateTime()) .recordCount(in.getRecordCount()) .useGlesysNameServer(in.isUseGlesysNameServer()) @@ -207,7 +207,7 @@ public class Domain { /** * @return the domain name, ex. "jclouds.org" */ - public String getDomainName() { + public String getName() { return this.domainName; } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java b/labs/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java index 7ece758cb9..2a35291c00 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java @@ -62,7 +62,7 @@ public class DomainRecord { } /** - * @see DomainRecord#getDomainname() + * @see DomainRecord#getname() */ public T domainname(String domainname) { this.domainname = checkNotNull(domainname, "domainname"); @@ -107,7 +107,7 @@ public class DomainRecord { public T fromDomainRecord(DomainRecord in) { return this.id(in.getId()) - .domainname(in.getDomainname()) + .domainname(in.getname()) .host(in.getHost()) .type(in.getType()) .data(in.getData()) @@ -152,7 +152,7 @@ public class DomainRecord { /** * @return the zone content of the record */ - public String getDomainname() { + public String getname() { return this.domainname; } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java b/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java index 88bdc4c56b..45c3c3f7d8 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java @@ -61,7 +61,7 @@ public class EmailOverview { } /** - * @see EmailOverview#getDomains() + * @see EmailOverview#gets() */ public T domains(Set domains) { this.domains = ImmutableSet.copyOf(checkNotNull(domains, "domains")); @@ -77,7 +77,7 @@ public class EmailOverview { } public T fromEmailOverview(EmailOverview in) { - return this.summary(in.getSummary()).domains(in.getDomains()); + return this.summary(in.getSummary()).domains(in.gets()); } } @@ -109,7 +109,7 @@ public class EmailOverview { /** * @return the set of detailed information about the e-mail addresses and aliases for each domain */ - public Set getDomains() { + public Set gets() { return this.domains; } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java b/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java index b201b2ab19..bbf9308d73 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java @@ -51,7 +51,7 @@ public class EmailOverviewDomain { protected int aliases; /** - * @see EmailOverviewDomain#getDomain() + * @see EmailOverviewDomain#get() */ public T domain(String domain) { this.domain = checkNotNull(domain, "domain"); @@ -79,7 +79,7 @@ public class EmailOverviewDomain { } public T fromEmailOverviewDomain(EmailOverviewDomain in) { - return this.domain(in.getDomain()).accounts(in.getAccounts()).aliases(in.getAliases()); + return this.domain(in.get()).accounts(in.getAccounts()).aliases(in.getAliases()); } } @@ -104,7 +104,7 @@ public class EmailOverviewDomain { } /** @return the domain name */ - public String getDomain() { + public String get() { return this.domain; } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java index d074a87537..d50417fbad 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java @@ -18,13 +18,14 @@ */ package org.jclouds.glesys.features; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.glesys.domain.Archive; import org.jclouds.glesys.domain.ArchiveAllowedArguments; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to Archive requests. *

@@ -39,7 +40,7 @@ public interface ArchiveApi { /** * Lists all active disks on this account. */ - Set listArchives(); + FluentIterable list(); /** * Get detailed information about an archive volume. @@ -47,7 +48,7 @@ public interface ArchiveApi { * @param username the username associated with the archive * @return the archive information or null if not found */ - Archive getArchive(String username); + Archive get(String username); /** * Create a new backup volume. @@ -57,14 +58,14 @@ public interface ArchiveApi { * @param password the new password * @param size the new size required in GB */ - Archive createArchive(String username, String password, int size); + Archive createWithCredentialsAndSize(String username, String password, int size); /** * Delete an archive volume. All files on the volume * * @param username the username associated with the archive */ - void deleteArchive(String username); + void delete(String username); /** * Resize an archive volume. It is only possible to upgrade the size of the disk. Downgrading is currently not @@ -72,9 +73,9 @@ public interface ArchiveApi { * Then delete the old volume. * * @param username the username associated with the archive - * @param size the new size required, see #getArchiveAllowedArguments for valid values + * @param size the new size required, see #getAllowedArguments for valid values */ - Archive resizeArchive(String username, int size); + Archive resize(String username, int size); /** * Change the password for an archive user. @@ -82,11 +83,11 @@ public interface ArchiveApi { * @param username the archive username * @param password the new password */ - Archive changeArchivePassword(String username, String password); + Archive changePassword(String username, String password); /** * Lists the allowed arguments for some of the functions in this module such as archive size. */ - ArchiveAllowedArguments getArchiveAllowedArguments(); + ArchiveAllowedArguments getAllowedArguments(); } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java index 550c498ae3..4210f171a2 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.glesys.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; import javax.ws.rs.GET; @@ -33,9 +31,10 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -50,67 +49,67 @@ import com.google.common.util.concurrent.ListenableFuture; public interface ArchiveAsyncApi { /** - * @see ArchiveApi#listArchives + * @see ArchiveApi#list */ @POST @Path("/archive/list/format/json") @SelectJson("archives") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listArchives(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see ArchiveApi#getArchive + * @see ArchiveApi#get */ @POST @Path("/archive/details/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getArchive(@FormParam("username") String username); + ListenableFuture get(@FormParam("username") String username); /** - * @see ArchiveApi#createArchive + * @see ArchiveApi#createWithCredentialsAndSize */ @POST @Path("/archive/create/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture createArchive(@FormParam("username") String username, @FormParam("password") String password, + ListenableFuture createWithCredentialsAndSize(@FormParam("username") String username, @FormParam("password") String password, @FormParam("size")int size); /** - * @see ArchiveApi#deleteArchive + * @see ArchiveApi#delete */ @POST @Path("/archive/delete/format/json") - ListenableFuture deleteArchive(@FormParam("username") String username); + ListenableFuture delete(@FormParam("username") String username); /** - * @see ArchiveApi#resizeArchive + * @see ArchiveApi#resize */ @POST @Path("/archive/resize/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture resizeArchive(@FormParam("username") String username, @FormParam("size") int size); + ListenableFuture resize(@FormParam("username") String username, @FormParam("size") int size); /** - * @see ArchiveApi#changeArchivePassword + * @see ArchiveApi#changePassword */ @POST @Path("/archive/changepassword/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture changeArchivePassword(@FormParam("username") String username, @FormParam("password") String password); + ListenableFuture changePassword(@FormParam("username") String username, @FormParam("password") String password); /** - * @see org.jclouds.glesys.features.ArchiveApi#getArchiveAllowedArguments + * @see org.jclouds.glesys.features.ArchiveApi#getAllowedArguments */ @GET @Path("/archive/allowedarguments/format/json") @SelectJson("argumentslist") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getArchiveAllowedArguments(); + ListenableFuture getAllowedArguments(); } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java index ca6a01d804..2b393a0e9c 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java @@ -27,7 +27,9 @@ import org.jclouds.glesys.domain.DomainRecord; import org.jclouds.glesys.options.AddDomainOptions; import org.jclouds.glesys.options.AddRecordOptions; import org.jclouds.glesys.options.DomainOptions; -import org.jclouds.glesys.options.EditRecordOptions; +import org.jclouds.glesys.options.UpdateRecordOptions; + +import com.google.common.collect.FluentIterable; /** * Provides synchronous access to Domain requests. @@ -45,14 +47,14 @@ public interface DomainApi { * * @return an account's associated domain objects. */ - Set listDomains(); + FluentIterable list(); /** * Get a specific domain. * * @return the requested domain object. */ - Domain getDomain(String domain); + Domain get(String domain); /** * Add a domain to the Glesys dns-system @@ -61,23 +63,23 @@ public interface DomainApi { * @param options optional parameters * @return information about the added domain */ - Domain addDomain(String domain, AddDomainOptions... options); + Domain create(String domain, AddDomainOptions... options); /** - * Edit a domain to the Glesys dns-system + * Update a domain to the Glesys dns-system * * @param domain the name of the domain to add. * @param options optional parameters * @return information about the modified domain */ - Domain editDomain(String domain, DomainOptions... options); + Domain update(String domain, DomainOptions options); /** * Remove a domain to the Glesys dns-system * * @param domain the name of the domain to remove */ - void deleteDomain(String domain); + void delete(String domain); /** * Retrieve the DNS records for a given domain @@ -92,7 +94,7 @@ public interface DomainApi { * @param domain the domain to add the record to * @param options optional settings for the record */ - DomainRecord addRecord(String domain, String host, String type, String data, AddRecordOptions... options); + DomainRecord createRecord(String domain, String host, String type, String data, AddRecordOptions... options); /** * Modify a specific DNS Record @@ -101,7 +103,7 @@ public interface DomainApi { * @param options the settings to change * @see #listRecords to retrieve the necessary ids */ - DomainRecord editRecord(String recordId, EditRecordOptions... options); + DomainRecord updateRecord(String recordId, UpdateRecordOptions options); /** * Delete a DNS record diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java index 8fdbd19e95..ccf3f09031 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java @@ -31,14 +31,15 @@ import org.jclouds.glesys.domain.DomainRecord; import org.jclouds.glesys.options.AddDomainOptions; import org.jclouds.glesys.options.AddRecordOptions; import org.jclouds.glesys.options.DomainOptions; -import org.jclouds.glesys.options.EditRecordOptions; +import org.jclouds.glesys.options.UpdateRecordOptions; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -53,50 +54,50 @@ import com.google.common.util.concurrent.ListenableFuture; public interface DomainAsyncApi { /** - * @see org.jclouds.glesys.features.DomainApi#listDomains + * @see org.jclouds.glesys.features.DomainApi#list */ @POST @Path("/domain/list/format/json") @SelectJson("domains") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listDomains(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see org.jclouds.glesys.features.DomainApi#getDomain + * @see org.jclouds.glesys.features.DomainApi#get */ @POST @Path("/domain/details/format/json") @SelectJson("domain") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getDomain(@FormParam("domainname") String name); + ListenableFuture get(@FormParam("domainname") String name); /** - * @see DomainApi#addDomain + * @see DomainApi#create */ @POST @Path("/domain/add/format/json") @SelectJson("domain") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture addDomain(@FormParam("domainname") String name, AddDomainOptions... options); + ListenableFuture create(@FormParam("domainname") String name, AddDomainOptions... options); /** - * @see DomainApi#editDomain + * @see DomainApi#update */ @POST @Path("/domain/edit/format/json") @SelectJson("domain") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture editDomain(@FormParam("domainname") String domain, DomainOptions... options); + ListenableFuture update(@FormParam("domainname") String domain, DomainOptions options); /** - * @see DomainApi#deleteDomain + * @see DomainApi#delete */ @POST @Path("/domain/delete/format/json") - ListenableFuture deleteDomain(@FormParam("domainname") String domain); + ListenableFuture delete(@FormParam("domainname") String domain); /** * @see DomainApi#listRecords @@ -108,24 +109,24 @@ public interface DomainAsyncApi { ListenableFuture> listRecords(@FormParam("domainname") String domain); /** - * @see DomainApi#addRecord + * @see DomainApi#createRecord */ @POST @Path("/domain/addrecord/format/json") @SelectJson("record") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture addRecord(@FormParam("domainname") String domain, @FormParam("host") String host, + ListenableFuture createRecord(@FormParam("domainname") String domain, @FormParam("host") String host, @FormParam("type") String type, @FormParam("data") String data, AddRecordOptions... options); /** - * @see DomainApi#editRecord + * @see DomainApi#updateRecord */ @POST @Path("/domain/updaterecord/format/json") @SelectJson("record") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture editRecord(@FormParam("recordid") String record_id, EditRecordOptions... options); + ListenableFuture updateRecord(@FormParam("recordid") String record_id, UpdateRecordOptions options); /** * @see DomainApi#deleteRecord diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java similarity index 80% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/EmailApi.java rename to labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java index e8680435b6..e00725c4e1 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java @@ -18,7 +18,6 @@ */ package org.jclouds.glesys.features; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -26,39 +25,41 @@ import org.jclouds.glesys.domain.EmailAccount; import org.jclouds.glesys.domain.EmailAlias; import org.jclouds.glesys.domain.EmailOverview; import org.jclouds.glesys.options.CreateAccountOptions; -import org.jclouds.glesys.options.EditAccountOptions; +import org.jclouds.glesys.options.UpdateAccountOptions; + +import com.google.common.collect.FluentIterable; /** * Provides synchronous access to E-Mail requests. *

* * @author Adam Lowe - * @see org.jclouds.glesys.features.EmailAsyncApi + * @see org.jclouds.glesys.features.EmailAccountAsyncApi * @see */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) -public interface EmailApi { +public interface EmailAccountApi { /** * Get a summary of e-mail accounts associated with this Glesys account * * @return the relevant summary data */ - EmailOverview getEmailOverview(); + EmailOverview getOverview(); /** * Get the set of detailed information about e-mail accounts * * @return the relevant set of details */ - Set listAccounts(String domain); + FluentIterable listDomain(String domain); /** * Get the set of details about e-mail aliases * * @return the relevant set of details */ - Set listAliases(String domain); + FluentIterable listAliasesInDomain(String domain); /** * Create a new e-mail account @@ -66,16 +67,16 @@ public interface EmailApi { * @param accountAddress the e-mail address to use (the domain should already exist) * @param password the password to use for the mailbox * @param options optional parameters - * @see DomainApi#addDomain + * @see DomainApi#create */ - EmailAccount createAccount(String accountAddress, String password, CreateAccountOptions... options); + EmailAccount createWithPassword(String accountAddress, String password, CreateAccountOptions... options); /** * Create an e-mail alias for an e-mail account * * @param aliasAddress the address to use for the alias (the domain should already exist) * @param toEmailAddress the existing e-mail account address the alias should forward to - * @see DomainApi#addDomain + * @see DomainApi#create */ EmailAlias createAlias(String aliasAddress, String toEmailAddress); @@ -85,7 +86,7 @@ public interface EmailApi { * @param accountAddress the existing e-mail account address * @param options optional parameters */ - EmailAccount editAccount(String accountAddress, EditAccountOptions... options); + EmailAccount update(String accountAddress, UpdateAccountOptions... options); /** * Adjust (re-target) an e-mail alias @@ -93,7 +94,7 @@ public interface EmailApi { * @param aliasAddress the existing alias e-mail address * @param toEmailAddress the existing e-mail account address the alias should forward to */ - EmailAlias editAlias(String aliasAddress, String toEmailAddress); + EmailAlias updateAlias(String aliasAddress, String toEmailAddress); /** * Delete an e-mail account or alias diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java similarity index 64% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncApi.java rename to labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java index 2470729864..e3e6793abc 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.glesys.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; import javax.ws.rs.POST; @@ -30,14 +28,15 @@ import org.jclouds.glesys.domain.EmailAccount; import org.jclouds.glesys.domain.EmailAlias; import org.jclouds.glesys.domain.EmailOverview; import org.jclouds.glesys.options.CreateAccountOptions; -import org.jclouds.glesys.options.EditAccountOptions; +import org.jclouds.glesys.options.UpdateAccountOptions; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -45,53 +44,53 @@ import com.google.common.util.concurrent.ListenableFuture; *

* * @author Adam Lowe - * @see org.jclouds.glesys.features.EmailApi + * @see org.jclouds.glesys.features.EmailAccountApi * @see */ @RequestFilters(BasicAuthentication.class) -public interface EmailAsyncApi { +public interface EmailAccountAsyncApi { /** - * @see org.jclouds.glesys.features.EmailApi#getEmailOverview + * @see org.jclouds.glesys.features.EmailAccountApi#getOverview */ @POST @Path("/email/overview/format/json") @SelectJson("overview") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getEmailOverview(); + ListenableFuture getOverview(); /** - * @see org.jclouds.glesys.features.EmailApi#listAccounts + * @see org.jclouds.glesys.features.EmailAccountApi#listDomain */ @POST @Path("/email/list/format/json") @SelectJson("emailaccounts") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listAccounts(@FormParam("domainname") String domain); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listDomain(@FormParam("domainname") String domain); /** - * @see org.jclouds.glesys.features.EmailApi#listAccounts + * @see org.jclouds.glesys.features.EmailAccountApi#listAliasesInDomain */ @POST @Path("/email/list/format/json") @SelectJson("emailaliases") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listAliases(@FormParam("domainname") String domain); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listAliasesInDomain(@FormParam("domainname") String domain); /** - * @see org.jclouds.glesys.features.EmailApi#createAccount + * @see org.jclouds.glesys.features.EmailAccountApi#createWithPassword */ @POST @Consumes(MediaType.APPLICATION_JSON) @SelectJson("emailaccount") @Path("/email/createaccount/format/json") - ListenableFuture createAccount(@FormParam("emailaccount") String accountAddress, @FormParam("password") String password, CreateAccountOptions... options); + ListenableFuture createWithPassword(@FormParam("emailaccount") String accountAddress, @FormParam("password") String password, CreateAccountOptions... options); /** - * @see org.jclouds.glesys.features.EmailApi#createAlias + * @see org.jclouds.glesys.features.EmailAccountApi#createAlias */ @POST @Consumes(MediaType.APPLICATION_JSON) @@ -100,25 +99,25 @@ public interface EmailAsyncApi { ListenableFuture createAlias(@FormParam("emailalias") String aliasAddress, @FormParam("goto") String toEmailAddress); /** - * @see org.jclouds.glesys.features.EmailApi#editAccount + * @see org.jclouds.glesys.features.EmailAccountApi#update */ @POST @Consumes(MediaType.APPLICATION_JSON) @SelectJson("emailaccount") @Path("/email/editaccount/format/json") - ListenableFuture editAccount(@FormParam("emailaccount") String accountAddress, EditAccountOptions... options); + ListenableFuture update(@FormParam("emailaccount") String accountAddress, UpdateAccountOptions... options); /** - * @see org.jclouds.glesys.features.EmailApi#editAlias + * @see org.jclouds.glesys.features.EmailAccountApi#updateAlias */ @POST @Consumes(MediaType.APPLICATION_JSON) @SelectJson("alias") @Path("/email/editalias/format/json") - ListenableFuture editAlias(@FormParam("emailalias") String aliasAddress, @FormParam("goto") String toEmailAddress); + ListenableFuture updateAlias(@FormParam("emailalias") String aliasAddress, @FormParam("goto") String toEmailAddress); /** - * @see org.jclouds.glesys.features.EmailApi#delete + * @see org.jclouds.glesys.features.EmailAccountApi#delete */ @POST @Path("/email/delete/format/json") diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java index b81ee875bc..571be6b108 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java @@ -18,13 +18,14 @@ */ package org.jclouds.glesys.features; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.glesys.domain.IpDetails; import org.jclouds.glesys.options.ListIpOptions; +import com.google.common.collect.FluentIterable; + /** * Provides synchronous access to IP Addresses. *

@@ -43,7 +44,7 @@ public interface IpApi { * @param platform the platform * @return a set of free IP addresses */ - Set listFree(int ipVersion, String datacenter, String platform); + FluentIterable listFree(int ipVersion, String datacenter, String platform); /** * Take a free IP address and add it to this account. You can list free IP addresses with the function listFree(). @@ -67,7 +68,7 @@ public interface IpApi { * @param options options to filter the results (by IPV4/6, serverId, etc) * @return the set of IP addresses */ - Set listIps(ListIpOptions... options); + FluentIterable list(ListIpOptions... options); /** * Get details about the given IP address such as gateway and netmask. Different details are available @@ -76,7 +77,7 @@ public interface IpApi { * @param ipAddress the ip address * @return details about the given IP address */ - IpDetails getIp(String ipAddress); + IpDetails get(String ipAddress); /** * Add an IP address to an server. The IP has to be free, but reserved to this account. You are able to list such addresses @@ -87,27 +88,27 @@ public interface IpApi { * @param ipAddress the IP address to remove * @param serverId the server to add the IP address to */ - IpDetails addIpToServer(String ipAddress, String serverId); + IpDetails addToServer(String ipAddress, String serverId); /** * Remove an IP address from a server. This does not release it back to GleSYS pool of free ips. The address will be * kept on the account so that you can use it for other servers or the same server at a later time. To completely remove - * the IP address from this account, use removeIpFromServerAndRelease to do so + * the IP address from this account, use removeFromServerAndRelease to do so * * @param ipAddress the IP address to remove * @param serverId the server to remove the IP address from - * @see #removeIpFromServerAndRelease + * @see #removeFromServerAndRelease */ - IpDetails removeIpFromServer(String ipAddress, String serverId); + IpDetails removeFromServer(String ipAddress, String serverId); /** * Remove an IP address from a server and release it back to GleSYS pool of free ips. * * @param ipAddress the IP address to remove * @param serverId the server to remove the IP address from - * @see #removeIpFromServer + * @see #removeFromServer */ - IpDetails removeIpFromServerAndRelease(String ipAddress, String serverId); + IpDetails removeFromServerAndRelease(String ipAddress, String serverId); /** * Sets PTR data for an IP. Use ip/listown or ip/details to get current PTR data diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java index 2e2a2837bf..3695f0d92a 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java @@ -18,8 +18,6 @@ */ package org.jclouds.glesys.features; -import java.util.Set; - import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; import javax.ws.rs.GET; @@ -35,9 +33,10 @@ import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -57,8 +56,8 @@ public interface IpAsyncApi { @Path("/ip/listfree/ipversion/{ipversion}/datacenter/{datacenter}/platform/{platform}/format/json") @Consumes(MediaType.APPLICATION_JSON) @SelectJson("ipaddresses") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listFree(@PathParam("ipversion") int ipversion, + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> listFree(@PathParam("ipversion") int ipversion, @PathParam("datacenter") String datacenter, @PathParam("platform") String platform); @@ -81,54 +80,54 @@ public interface IpAsyncApi { ListenableFuture release(@FormParam("ipaddress") String ipAddress); /** - * @see IpApi#listIps + * @see IpApi#list */ @GET @Path("/ip/listown/format/json") @Consumes(MediaType.APPLICATION_JSON) @SelectJson("iplist") - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listIps(ListIpOptions... options); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(ListIpOptions... options); /** - * @see IpApi#getIp + * @see IpApi#get */ @GET @Path("/ip/details/ipaddress/{ipaddress}/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getIp(@PathParam("ipaddress") String ipAddress); + ListenableFuture get(@PathParam("ipaddress") String ipAddress); /** - * @see IpApi#addIpToServer + * @see IpApi#addToServer */ @POST @Path("/ip/add/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture addIpToServer(@FormParam("ipaddress") String ipAddress, + ListenableFuture addToServer(@FormParam("ipaddress") String ipAddress, @FormParam("serverid") String serverId); /** - * @see IpApi#removeIpFromServer + * @see IpApi#removeFromServer */ @POST @Path("/ip/remove/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture removeIpFromServer(@FormParam("ipaddress") String ipAddress, + ListenableFuture removeFromServer(@FormParam("ipaddress") String ipAddress, @FormParam("serverid") String serverId); /** - * @see IpApi#removeIpFromServer + * @see IpApi#removeFromServer */ @POST @FormParams(keys = "release", values = "true") @Path("/ip/remove/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture removeIpFromServerAndRelease(@FormParam("ipaddress") String ipAddress, + ListenableFuture removeFromServerAndRelease(@FormParam("ipaddress") String ipAddress, @FormParam("serverid") String serverId); /** diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java index 370974fc77..da32f36beb 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java @@ -19,7 +19,6 @@ package org.jclouds.glesys.features; import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -35,10 +34,11 @@ import org.jclouds.glesys.domain.ServerStatus; import org.jclouds.glesys.options.CloneServerOptions; import org.jclouds.glesys.options.CreateServerOptions; import org.jclouds.glesys.options.DestroyServerOptions; -import org.jclouds.glesys.options.EditServerOptions; +import org.jclouds.glesys.options.UpdateServerOptions; import org.jclouds.glesys.options.ServerStatusOptions; import com.google.common.annotations.Beta; +import com.google.common.collect.FluentIterable; /** * Provides synchronous access to Server. @@ -57,7 +57,7 @@ public interface ServerApi { * * @return an account's associated server objects. */ - Set listServers(); + FluentIterable list(); /** * Get detailed information about a server such as hostname, hardware @@ -67,7 +67,7 @@ public interface ServerApi { * @param id id of the server * @return server or null if not found */ - ServerDetails getServerDetails(String id); + ServerDetails get(String id); /** * Get detailed information about a server status including up-time and @@ -77,7 +77,7 @@ public interface ServerApi { * @param options optional parameters * @return the status of the server or null if not found */ - ServerStatus getServerStatus(String id, ServerStatusOptions... options); + ServerStatus getStatus(String id, ServerStatusOptions... options); /** * Get detailed information about a server's limits (for OpenVZ only). @@ -86,7 +86,7 @@ public interface ServerApi { * @param id id of the server * @return the requested information about the server or null if not found */ - Map getServerLimits(String id); + Map getLimits(String id); /** * Get information about how to connect to a server via VNC @@ -101,14 +101,14 @@ public interface ServerApi { * * @return the set of information about each template */ - Set listTemplates(); + FluentIterable listTemplates(); /** * Get information about valid arguments to #createServer for each platform * * @return a map of argument lists, keyed on platform */ - Map getAllowedArgumentsForCreateServerByPlatform(); + Map getAllowedArgumentsForCreateByPlatform(); /** * Reset the fail count for a server limit (for OpenVZ only). @@ -116,35 +116,35 @@ public interface ServerApi { * @param id id of the server * @param type the type of limit to reset */ - Map resetServerLimit(String id, String type); + Map resetLimit(String id, String type); /** * Reboot a server * * @param id id of the server */ - ServerDetails rebootServer(String id); + ServerDetails reboot(String id); /** * Start a server * * @param id id of the server */ - ServerDetails startServer(String id); + ServerDetails start(String id); /** * Stop a server * * @param id id of the server */ - ServerDetails stopServer(String id); + ServerDetails stop(String id); /** * hard stop a server * * @param id id of the server */ - ServerDetails hardStopServer(String id); + ServerDetails hardStop(String id); /** * Create a new server @@ -154,16 +154,16 @@ public interface ServerApi { * @param options optional settings ex. description */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) - ServerDetails createServerWithHostnameAndRootPassword(ServerSpec serverSpec, String hostname, String rootPassword, + ServerDetails createWithHostnameAndRootPassword(ServerSpec serverSpec, String hostname, String rootPassword, CreateServerOptions... options); /** - * Edit the configuration of a server + * Update the configuration of a server * * @param serverid the serverId of the server to edit * @param options the settings to change */ - ServerDetails editServer(String serverid, EditServerOptions... options); + ServerDetails update(String serverid, UpdateServerOptions options); /** * Clone a server @@ -173,7 +173,7 @@ public interface ServerApi { * @param options the settings to change */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) - ServerDetails cloneServer(String serverid, String hostname, CloneServerOptions... options); + ServerDetails clone(String serverid, String hostname, CloneServerOptions... options); /** * Destroy a server @@ -181,7 +181,7 @@ public interface ServerApi { * @param id the id of the server * @param keepIp if DestroyServerOptions.keepIp(true) the servers ip will be retained for use in your GleSYS account */ - ServerDetails destroyServer(String id, DestroyServerOptions keepIp); + ServerDetails destroy(String id, DestroyServerOptions keepIp); /** * Reset the root password of a server diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java b/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java index 92a8ccdae7..8024622910 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java @@ -19,7 +19,6 @@ package org.jclouds.glesys.features; import java.util.Map; -import java.util.Set; import java.util.SortedMap; import javax.ws.rs.Consumes; @@ -42,7 +41,7 @@ import org.jclouds.glesys.functions.ParseTemplatesFromHttpResponse; import org.jclouds.glesys.options.CloneServerOptions; import org.jclouds.glesys.options.CreateServerOptions; import org.jclouds.glesys.options.DestroyServerOptions; -import org.jclouds.glesys.options.EditServerOptions; +import org.jclouds.glesys.options.UpdateServerOptions; import org.jclouds.glesys.options.ServerStatusOptions; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; @@ -52,9 +51,10 @@ import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import com.google.common.collect.FluentIterable; import com.google.common.util.concurrent.ListenableFuture; /** @@ -70,17 +70,17 @@ import com.google.common.util.concurrent.ListenableFuture; public interface ServerAsyncApi { /** - * @see ServerApi#listServers + * @see ServerApi#list */ @POST @Path("/server/list/format/json") @SelectJson("servers") @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listServers(); + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) + ListenableFuture> list(); /** - * @see ServerApi#getServerDetails + * @see ServerApi#get */ @POST @Path("/server/details/format/json") @@ -88,27 +88,27 @@ public interface ServerAsyncApi { @Consumes(MediaType.APPLICATION_JSON) @FormParams(keys = "includestate", values = "true") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getServerDetails(@FormParam("serverid") String id); + ListenableFuture get(@FormParam("serverid") String id); /** - * @see ServerApi#getServerStatus + * @see ServerApi#getStatus */ @POST @Path("/server/status/format/json") @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getServerStatus(@FormParam("serverid") String id, ServerStatusOptions... options); + ListenableFuture getStatus(@FormParam("serverid") String id, ServerStatusOptions... options); /** - * @see ServerApi#getServerLimits + * @see ServerApi#getLimits */ @POST @Path("/server/limits/format/json") @SelectJson("limits") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture> getServerLimits(@FormParam("serverid") String id); + ListenableFuture> getLimits(@FormParam("serverid") String id); /** * @see ServerApi#getConsole @@ -121,13 +121,13 @@ public interface ServerAsyncApi { ListenableFuture getConsole(@FormParam("serverid") String id); /** - * @see ServerApi#getAllowedArgumentsForCreateServerByPlatform + * @see ServerApi#getAllowedArgumentsForCreateByPlatform */ @GET @Path("/server/allowedarguments/format/json") @SelectJson("argumentslist") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture> getAllowedArgumentsForCreateServerByPlatform(); + ListenableFuture> getAllowedArgumentsForCreateByPlatform(); /** * @see ServerApi#listTemplates @@ -135,92 +135,93 @@ public interface ServerAsyncApi { @GET @Path("/server/templates/format/json") @ResponseParser(ParseTemplatesFromHttpResponse.class) + @ExceptionParser(ReturnEmptyFluentIterableOnNotFoundOr404.class) @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture> listTemplates(); + ListenableFuture> listTemplates(); /** - * @see ServerApi#stopServer + * @see ServerApi#stop */ @POST @Path("/server/resetlimit/format/json") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture> resetServerLimit(@FormParam("serverid") String id, + ListenableFuture> resetLimit(@FormParam("serverid") String id, @FormParam("type") String type); /** - * @see ServerApi#rebootServer + * @see ServerApi#reboot */ @POST @SelectJson("server") @Path("/server/reboot/format/json") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture rebootServer(@FormParam("serverid") String id); + ListenableFuture reboot(@FormParam("serverid") String id); /** - * @see ServerApi#startServer + * @see ServerApi#start */ @POST @SelectJson("server") @Path("/server/start/format/json") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture startServer(@FormParam("serverid") String id); + ListenableFuture start(@FormParam("serverid") String id); /** - * @see ServerApi#stopServer + * @see ServerApi#stop */ @POST @SelectJson("server") @Path("/server/stop/format/json") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture stopServer(@FormParam("serverid") String id); + ListenableFuture stop(@FormParam("serverid") String id); /** - * @see ServerApi#hardStopServer + * @see ServerApi#hardStop */ @POST @SelectJson("server") @Path("/server/stop/format/json") @FormParams(keys = "type", values = "hard") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture hardStopServer(@FormParam("serverid") String id); + ListenableFuture hardStop(@FormParam("serverid") String id); /** - * @see ServerApi#createServerWithHostnameAndRootPassword + * @see ServerApi#createWithHostnameAndRootPassword */ @POST @SelectJson("server") @Path("/server/create/format/json") @Consumes(MediaType.APPLICATION_JSON) @MapBinder(CreateServerOptions.class) - ListenableFuture createServerWithHostnameAndRootPassword(ServerSpec serverSpec, + ListenableFuture createWithHostnameAndRootPassword(ServerSpec serverSpec, @PayloadParam("hostname") String hostname, @PayloadParam("rootpassword") String rootPassword, CreateServerOptions... options); /** - * @see ServerApi#cloneServer + * @see ServerApi#clone */ @POST @Path("/server/clone/format/json") @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture cloneServer(@FormParam("serverid") String serverid, + ListenableFuture clone(@FormParam("serverid") String serverid, @FormParam("hostname") String hostname, CloneServerOptions... options); /** - * @see ServerApi#editServer + * @see ServerApi#update */ @POST @Path("/server/edit/format/json") @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture editServer(@FormParam("serverid") String serverid, EditServerOptions... options); + ListenableFuture update(@FormParam("serverid") String serverid, UpdateServerOptions options); /** - * @see ServerApi#destroyServer + * @see ServerApi#destroy */ @POST @Path("/server/destroy/format/json") - ListenableFuture destroyServer(@FormParam("serverid") String id, DestroyServerOptions keepIp); + ListenableFuture destroy(@FormParam("serverid") String id, DestroyServerOptions keepIp); /** * @see ServerApi#resetPassword diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java b/labs/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java index c03f109e27..60738f3eb1 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java @@ -31,7 +31,7 @@ import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.json.internal.GsonWrapper; import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; import com.google.inject.Inject; import com.google.inject.TypeLiteral; @@ -40,7 +40,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Singleton -public class ParseTemplatesFromHttpResponse implements Function> { +public class ParseTemplatesFromHttpResponse implements Function> { private final ParseFirstJsonValueNamed>> parser; @Inject @@ -50,10 +50,10 @@ public class ParseTemplatesFromHttpResponse implements Function apply(HttpResponse response) { + public FluentIterable apply(HttpResponse response) { checkNotNull(response, "response"); Map> toParse = parser.apply(response); checkNotNull(toParse, "parsed result from %s", response); - return ImmutableSet.copyOf(Iterables.concat(toParse.values())); + return FluentIterable.from(Iterables.concat(toParse.values())); } } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java b/labs/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java index 07f423a538..4185c08516 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java @@ -21,7 +21,7 @@ package org.jclouds.glesys.options; /** * @author Adam Lowe */ -public class CloneServerOptions extends EditServerOptions { +public class CloneServerOptions extends UpdateServerOptions { public static class Builder { /** * @see org.jclouds.glesys.options.CloneServerOptions#diskSizeGB @@ -52,7 +52,7 @@ public class CloneServerOptions extends EditServerOptions { } /** - * @see org.jclouds.glesys.options.EditServerOptions#description + * @see org.jclouds.glesys.options.UpdateServerOptions#description */ public static CloneServerOptions description(String description) { return CloneServerOptions.class.cast(new CloneServerOptions().description(description)); diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/EditAccountOptions.java b/labs/glesys/src/main/java/org/jclouds/glesys/options/EditAccountOptions.java deleted file mode 100644 index 4d2d164435..0000000000 --- a/labs/glesys/src/main/java/org/jclouds/glesys/options/EditAccountOptions.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.glesys.options; - - -/** - * @author Adam Lowe - * @see - */ -public class EditAccountOptions extends CreateAccountOptions { - - public static class Builder { - /** - * @see org.jclouds.glesys.options.EditAccountOptions#antispamLevel - */ - public static EditAccountOptions antispamLevel(int antispamLevel) { - return EditAccountOptions.class.cast(new EditAccountOptions().antispamLevel(antispamLevel)); - } - - /** - * @see org.jclouds.glesys.options.EditAccountOptions#antiVirus - */ - public static EditAccountOptions antiVirus(boolean antiVirus) { - return EditAccountOptions.class.cast(new EditAccountOptions().antiVirus(antiVirus)); - } - - /** - * @see org.jclouds.glesys.options.EditAccountOptions#autorespond - */ - public static EditAccountOptions autorespond(boolean autorespond) { - return EditAccountOptions.class.cast(new EditAccountOptions().autorespond(autorespond)); - } - - /** - * @see org.jclouds.glesys.options.EditAccountOptions#autorespondSaveEmail - */ - public static EditAccountOptions autorespondSaveEmail(boolean autorespondSaveEmail) { - return EditAccountOptions.class.cast(new EditAccountOptions().autorespondSaveEmail(autorespondSaveEmail)); - } - - /** - * @see org.jclouds.glesys.options.EditAccountOptions#autorespondMessage - */ - public static EditAccountOptions autorespondMessage(String autorespondMessage) { - return EditAccountOptions.class.cast(new EditAccountOptions().autorespondMessage(autorespondMessage)); - } - - /** - * @see org.jclouds.glesys.options.EditAccountOptions#password - */ - public static EditAccountOptions password(String password) { - return new EditAccountOptions().password(password); - } - } - - /** Reset the password for this account */ - public EditAccountOptions password(String password) { - formParameters.put("password", password); - return this; - } -} diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java b/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java new file mode 100644 index 0000000000..9c3c5a37ad --- /dev/null +++ b/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.glesys.options; + + +/** + * @author Adam Lowe + * @see + */ +public class UpdateAccountOptions extends CreateAccountOptions { + + public static class Builder { + /** + * @see org.jclouds.glesys.options.UpdateAccountOptions#antispamLevel + */ + public static UpdateAccountOptions antispamLevel(int antispamLevel) { + return UpdateAccountOptions.class.cast(new UpdateAccountOptions().antispamLevel(antispamLevel)); + } + + /** + * @see org.jclouds.glesys.options.UpdateAccountOptions#antiVirus + */ + public static UpdateAccountOptions antiVirus(boolean antiVirus) { + return UpdateAccountOptions.class.cast(new UpdateAccountOptions().antiVirus(antiVirus)); + } + + /** + * @see org.jclouds.glesys.options.UpdateAccountOptions#autorespond + */ + public static UpdateAccountOptions autorespond(boolean autorespond) { + return UpdateAccountOptions.class.cast(new UpdateAccountOptions().autorespond(autorespond)); + } + + /** + * @see org.jclouds.glesys.options.UpdateAccountOptions#autorespondSaveEmail + */ + public static UpdateAccountOptions autorespondSaveEmail(boolean autorespondSaveEmail) { + return UpdateAccountOptions.class.cast(new UpdateAccountOptions().autorespondSaveEmail(autorespondSaveEmail)); + } + + /** + * @see org.jclouds.glesys.options.UpdateAccountOptions#autorespondMessage + */ + public static UpdateAccountOptions autorespondMessage(String autorespondMessage) { + return UpdateAccountOptions.class.cast(new UpdateAccountOptions().autorespondMessage(autorespondMessage)); + } + + /** + * @see org.jclouds.glesys.options.UpdateAccountOptions#password + */ + public static UpdateAccountOptions password(String password) { + return new UpdateAccountOptions().password(password); + } + } + + /** Reset the password for this account */ + public UpdateAccountOptions password(String password) { + formParameters.put("password", password); + return this; + } +} diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/EditRecordOptions.java b/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java similarity index 59% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/EditRecordOptions.java rename to labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java index be5b4de395..8fa7571d88 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/options/EditRecordOptions.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java @@ -21,54 +21,59 @@ package org.jclouds.glesys.options; /** * @author Adam Lowe */ -public class EditRecordOptions extends AddRecordOptions { +public class UpdateRecordOptions extends AddRecordOptions { public static class Builder { /** - * @see EditRecordOptions#host + * @see UpdateRecordOptions#host */ - public static EditRecordOptions host(String host) { - return new EditRecordOptions().host(host); + public static UpdateRecordOptions host(String host) { + return new UpdateRecordOptions().host(host); } /** - * @see EditRecordOptions#type + * @see UpdateRecordOptions#type */ - public static EditRecordOptions type(String type) { - return new EditRecordOptions().type(type); + public static UpdateRecordOptions type(String type) { + return new UpdateRecordOptions().type(type); } /** - * @see EditRecordOptions#data + * @see UpdateRecordOptions#data */ - public static EditRecordOptions data(String data) { - return new EditRecordOptions().data(data); + public static UpdateRecordOptions data(String data) { + return new UpdateRecordOptions().data(data); } /** - * @see EditRecordOptions#ttl + * @see UpdateRecordOptions#ttl */ - public static EditRecordOptions ttl(int ttl) { - return EditRecordOptions.class.cast(new EditRecordOptions().ttl(ttl)); + public static UpdateRecordOptions ttl(int ttl) { + return UpdateRecordOptions.class.cast(new UpdateRecordOptions().ttl(ttl)); } } /** Configure the hostname attached to this record */ - public EditRecordOptions host(String host) { + public UpdateRecordOptions host(String host) { formParameters.put("host", host); return this; } /** Configure the type of record, ex. "A", "CNAME" or "MX" */ - public EditRecordOptions type(String type) { + public UpdateRecordOptions type(String type) { formParameters.put("type", type); return this; } /** Set the content of this record (depending on type, for an "A" record this would be an ip address) */ - public EditRecordOptions data(String data) { + public UpdateRecordOptions data(String data) { formParameters.put("data", data); return this; } + + @Override + public UpdateRecordOptions ttl(int ttl) { + return UpdateRecordOptions.class.cast(super.ttl(ttl)); + } } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/EditServerOptions.java b/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java similarity index 56% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/EditServerOptions.java rename to labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java index 3b9d4d1892..c17516a934 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/options/EditServerOptions.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java @@ -24,87 +24,87 @@ import org.jclouds.http.options.BaseHttpRequestOptions; * * @author Adam Lowe */ -public class EditServerOptions extends BaseHttpRequestOptions { +public class UpdateServerOptions extends BaseHttpRequestOptions { public static class Builder { /** - * @see org.jclouds.glesys.options.EditServerOptions#diskSizeGB + * @see org.jclouds.glesys.options.UpdateServerOptions#diskSizeGB */ - public static EditServerOptions disksizeGB(int disksizeGB) { - return new EditServerOptions().diskSizeGB(disksizeGB); + public static UpdateServerOptions disksizeGB(int disksizeGB) { + return new UpdateServerOptions().diskSizeGB(disksizeGB); } /** - * @see org.jclouds.glesys.options.EditServerOptions#memorySizeMB + * @see org.jclouds.glesys.options.UpdateServerOptions#memorySizeMB */ - public static EditServerOptions memorysizeMB(int memorysizeMB) { - return new EditServerOptions().memorySizeMB(memorysizeMB); + public static UpdateServerOptions memorysizeMB(int memorysizeMB) { + return new UpdateServerOptions().memorySizeMB(memorysizeMB); } /** - * @see org.jclouds.glesys.options.EditServerOptions#cpuCores + * @see org.jclouds.glesys.options.UpdateServerOptions#cpuCores */ - public static EditServerOptions cpucores(int cpucores) { - EditServerOptions options = new EditServerOptions(); + public static UpdateServerOptions cpucores(int cpucores) { + UpdateServerOptions options = new UpdateServerOptions(); return options.cpuCores(cpucores); } /** - * @see org.jclouds.glesys.options.EditServerOptions#transferGB + * @see org.jclouds.glesys.options.UpdateServerOptions#transferGB */ - public static EditServerOptions transferGB(int transferGB) { - return new EditServerOptions().transferGB(transferGB); + public static UpdateServerOptions transferGB(int transferGB) { + return new UpdateServerOptions().transferGB(transferGB); } /** - * @see org.jclouds.glesys.options.EditServerOptions#hostname + * @see org.jclouds.glesys.options.UpdateServerOptions#hostname */ - public static EditServerOptions hostname(String hostname) { - EditServerOptions options = new EditServerOptions(); + public static UpdateServerOptions hostname(String hostname) { + UpdateServerOptions options = new UpdateServerOptions(); return options.hostname(hostname); } /** - * @see org.jclouds.glesys.options.EditServerOptions#description + * @see org.jclouds.glesys.options.UpdateServerOptions#description */ - public static EditServerOptions description(String description) { - EditServerOptions options = new EditServerOptions(); + public static UpdateServerOptions description(String description) { + UpdateServerOptions options = new UpdateServerOptions(); return options.description(description); } } /** Configure the size of the disk, in GB, of the server */ - public EditServerOptions diskSizeGB(int diskSizeGB) { + public UpdateServerOptions diskSizeGB(int diskSizeGB) { formParameters.put("disksize", Integer.toString(diskSizeGB)); return this; } /** Configure the amount of RAM, in MB, allocated to the server */ - public EditServerOptions memorySizeMB(int memorySizeMB) { + public UpdateServerOptions memorySizeMB(int memorySizeMB) { formParameters.put("memorysize", Integer.toString(memorySizeMB)); return this; } /** Configure the number of CPU cores allocated to the server */ - public EditServerOptions cpuCores(int cpucores) { + public UpdateServerOptions cpuCores(int cpucores) { formParameters.put("cpucores", Integer.toString(cpucores)); return this; } /** Configure the transfer setting for the server */ - public EditServerOptions transferGB(int transferGB) { + public UpdateServerOptions transferGB(int transferGB) { formParameters.put("transfer", Integer.toString(transferGB)); return this; } /** Configure the host name of the server (must be unique within the GleSYS account) */ - public EditServerOptions hostname(String hostname) { + public UpdateServerOptions hostname(String hostname) { formParameters.put("hostname", hostname); return this; } /** Configure the description of the server */ - public EditServerOptions description(String description) { + public UpdateServerOptions description(String description) { formParameters.put("description", description); return this; } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java index db34cffecd..8f51ddbaf3 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java @@ -50,15 +50,15 @@ public class GleSYSAsyncApiTest extends BaseAsyncApiTest { public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { assert syncApi.getServerApi() != null; assert syncApi.getIpApi() != null; - assert syncApi.getArchiveApi() != null; assert syncApi.getDomainApi() != null; + assert syncApi.getArchiveApi() != null; } public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { assert asyncApi.getServerApi() != null; assert asyncApi.getIpApi() != null; - assert asyncApi.getArchiveApi() != null; assert asyncApi.getDomainApi() != null; + assert asyncApi.getArchiveApi() != null; } @Override diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java index 6502cf295f..f8a300965e 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java @@ -22,7 +22,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; -import java.util.List; +import java.util.Set; import org.jclouds.glesys.domain.Archive; import org.jclouds.glesys.domain.ArchiveAllowedArguments; @@ -33,8 +33,8 @@ import org.jclouds.http.HttpResponseException; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; /** * Tests parsing of {@code ArchiveAsyncApi} @@ -52,10 +52,10 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_list.json")).build()) .getArchiveApi(); - List expected = ImmutableList.of( + Set expected = ImmutableSet.of( Archive.builder().username("xxxxx_test1").freeSize("20 GB").totalSize("30 GB").locked(false).build()); - assertEquals(api.listArchives(), expected); + assertEquals(api.list().toImmutableSet(), expected); } public void testListArchivesWhenResponseIs4xxReturnsEmpty() { @@ -65,7 +65,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getArchiveApi(); - assertTrue(api.listArchives().isEmpty()); + assertTrue(api.list().isEmpty()); } public void testArchiveDetailsWhenResponseIs2xx() throws Exception { @@ -77,7 +77,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_details.json")).build()) .getArchiveApi(); - assertEquals(api.getArchive("xxxxxx_test1"), detailsInArchiveDetails()); + assertEquals(api.get("xxxxxx_test1"), detailsInArchiveDetails()); } private Archive detailsInArchiveDetails() { @@ -92,7 +92,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("username", "xxxxxx_test1").build(), HttpResponse.builder().statusCode(404).build()) .getArchiveApi(); - assertNull(api.getArchive("xxxxxx_test1")); + assertNull(api.get("xxxxxx_test1")); } public void testCreateArchiveWhenResponseIs2xx() throws Exception { @@ -105,7 +105,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .put("size", "5") .put("password", "somepass").build()).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_details.json")).build()).getArchiveApi(); - assertEquals(api.createArchive("xxxxxx_test1", "somepass", 5), detailsInArchiveDetails()); + assertEquals(api.createWithCredentialsAndSize("xxxxxx_test1", "somepass", 5), detailsInArchiveDetails()); } public void testDeleteArchiveWhenResponseIs2xx() throws Exception { @@ -115,7 +115,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("username", "xxxxxx_test1").build(), HttpResponse.builder().statusCode(200).build()).getArchiveApi(); - api.deleteArchive("xxxxxx_test1"); + api.delete("xxxxxx_test1"); } @Test(expectedExceptions = {HttpResponseException.class}) @@ -125,7 +125,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("username", "xxxxxx_test1").build(), HttpResponse.builder().statusCode(402).build()).getArchiveApi(); - api.deleteArchive("xxxxxx_test1"); + api.delete("xxxxxx_test1"); } public void testResizeArchiveWhenResponseIs2xx() throws Exception { @@ -137,7 +137,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("size", "5").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_details.json")).build()).getArchiveApi(); - assertEquals(api.resizeArchive("username1", 5), detailsInArchiveDetails()); + assertEquals(api.resize("username1", 5), detailsInArchiveDetails()); } @Test(expectedExceptions = {ResourceNotFoundException.class}) @@ -150,7 +150,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("size", "5").build(), HttpResponse.builder().statusCode(404).build()).getArchiveApi(); - api.resizeArchive("username1", 5); + api.resize("username1", 5); } public void testChangeArchivePasswordWhenResponseIs2xx() throws Exception { @@ -163,7 +163,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("password", "newpass").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_details.json")).build()).getArchiveApi(); - assertEquals(api.changeArchivePassword("username", "newpass"), detailsInArchiveDetails()); + assertEquals(api.changePassword("username", "newpass"), detailsInArchiveDetails()); } @Test(expectedExceptions = {ResourceNotFoundException.class}) @@ -177,7 +177,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("password", "newpass").build(), HttpResponse.builder().statusCode(404).build()).getArchiveApi(); - api.changeArchivePassword("username", "newpass"); + api.changePassword("username", "newpass"); } public void testGetArchiveAllowedArgumentsWhenResponseIs2xx() throws Exception { @@ -189,7 +189,7 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_allowed_arguments.json")).build()).getArchiveApi(); ArchiveAllowedArguments expected = ArchiveAllowedArguments.builder().archiveSizes(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000).build(); - assertEquals(api.getArchiveAllowedArguments(), expected); + assertEquals(api.getAllowedArguments(), expected); } public void testGetArchiveAllowedArguments4xxWhenResponseIs2xx() throws Exception { @@ -200,6 +200,6 @@ public class ArchiveApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getArchiveApi(); - assertNull(api.getArchiveAllowedArguments()); + assertNull(api.getAllowedArguments()); } } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java index fe34a30bef..59d8ec6b83 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java @@ -51,15 +51,15 @@ public class ArchiveApiLiveTest extends BaseGleSYSApiLiveTest { archiveCounter = new RetryablePredicate( new Predicate() { public boolean apply(Integer value){ - return api.listArchives().size() == value; + return api.list().size() == value; } }, 30, 1, TimeUnit.SECONDS); } @AfterClass(groups = { "integration", "live" }) protected void tearDownContext() { - int before = api.listArchives().size(); - api.deleteArchive(archiveUser); + int before = api.list().size(); + api.delete(archiveUser); assertTrue(archiveCounter.apply(before - 1)); super.tearDownContext(); @@ -71,12 +71,12 @@ public class ArchiveApiLiveTest extends BaseGleSYSApiLiveTest { @Test public void testAllowedArguments() throws Exception { - ArchiveAllowedArguments args = api.getArchiveAllowedArguments(); + ArchiveAllowedArguments args = api.getAllowedArguments(); assertNotNull(args); - assertNotNull(args.getArchiveSizes()); - assertTrue(args.getArchiveSizes().size() > 0); + assertNotNull(args.getSizes()); + assertTrue(args.getSizes().size() > 0); - for (int size : args.getArchiveSizes()) { + for (int size : args.getSizes()) { assertTrue(size > 0); } } @@ -84,37 +84,37 @@ public class ArchiveApiLiveTest extends BaseGleSYSApiLiveTest { @Test public void testCreateArchive() throws Exception { try { - api.deleteArchive(archiveUser); + api.delete(archiveUser); } catch(Exception ex) { } - int before = api.listArchives().size(); + int before = api.list().size(); - api.createArchive(archiveUser, "password", 10); + api.createWithCredentialsAndSize(archiveUser, "password", 10); assertTrue(archiveCounter.apply(before + 1)); } @Test(dependsOnMethods = "testCreateArchive") public void testArchiveDetails() throws Exception { - Archive details = api.getArchive(archiveUser); + Archive details = api.get(archiveUser); assertEquals(details.getUsername(), archiveUser); } @Test(dependsOnMethods = "testCreateArchive") public void testChangePassword() throws Exception { - api.changeArchivePassword(archiveUser, "newpassword"); + api.changePassword(archiveUser, "newpassword"); // TODO assert something useful! } @Test(dependsOnMethods = "testCreateArchive") public void testResizeArchive() throws Exception { - api.resizeArchive(archiveUser, 20); + api.resize(archiveUser, 20); assertTrue(new RetryablePredicate( new Predicate() { public boolean apply(String value){ - return api.getArchive(archiveUser) != null && value.equals(api.getArchive(archiveUser).getTotalSize()); + return api.get(archiveUser) != null && value.equals(api.get(archiveUser).getTotalSize()); } }, 30, 1, TimeUnit.SECONDS).apply("20 GB")); } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java index 677afc82d2..93230fa95d 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java @@ -30,7 +30,8 @@ import org.jclouds.glesys.domain.Domain; import org.jclouds.glesys.domain.DomainRecord; import org.jclouds.glesys.internal.BaseGleSYSApiExpectTest; import org.jclouds.glesys.options.AddDomainOptions; -import org.jclouds.glesys.options.EditRecordOptions; +import org.jclouds.glesys.options.DomainOptions; +import org.jclouds.glesys.options.UpdateRecordOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.ResourceNotFoundException; @@ -57,8 +58,8 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { Domain expected = Domain.builder().domainName("testglesys.jclouds.org").createTime(dateService.iso8601SecondsDateParse("2012-01-31T12:19:03+01:00")).build(); - Domain actual = Iterables.getOnlyElement(api.listDomains()); - assertEquals(expected.getDomainName(), actual.getDomainName()); + Domain actual = Iterables.getOnlyElement(api.list()); + assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getCreateTime(), actual.getCreateTime()); } @@ -69,7 +70,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getDomainApi(); - assertTrue(api.listDomains().isEmpty()); + assertTrue(api.list().isEmpty()); } public void testListDomainRecordsWhenResponseIs2xx() throws Exception { @@ -112,7 +113,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getDomainApi(); - assertTrue(api.listDomains().isEmpty()); + assertTrue(api.list().isEmpty()); } public void testAddDomainRecordsWhenResponseIs2xx() throws Exception { @@ -128,7 +129,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .payload(payloadFromResourceWithContentType("/domain_record.json", MediaType.APPLICATION_JSON)).build()) .getDomainApi(); - assertEquals(api.addRecord("jclouds.org", "jclouds.org", "A", ""), recordInDomainRecord()); + assertEquals(api.createRecord("jclouds.org", "jclouds.org", "A", ""), recordInDomainRecord()); } protected DomainRecord recordInDomainRecord() { @@ -147,10 +148,10 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("data", "").build(), HttpResponse.builder().statusCode(404).build()).getDomainApi(); - api.addRecord("jclouds.org", "jclouds.org", "A", ""); + api.createRecord("jclouds.org", "jclouds.org", "A", ""); } - public void testEditDomainRecordsWhenResponseIs2xx() throws Exception { + public void testUpdateDomainRecordsWhenResponseIs2xx() throws Exception { DomainApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/domain/updaterecord/format/json") .addHeader("Accept", "application/json") @@ -162,11 +163,11 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .payload(payloadFromResourceWithContentType("/domain_record.json", MediaType.APPLICATION_JSON)).build()) .getDomainApi(); - assertEquals(api.editRecord("256151", EditRecordOptions.Builder.host("somehost"), EditRecordOptions.Builder.ttl(1800)), recordInDomainRecord()); + assertEquals(api.updateRecord("256151", UpdateRecordOptions.Builder.host("somehost").ttl(1800)), recordInDomainRecord()); } @Test(expectedExceptions = ResourceNotFoundException.class) - public void testEditDomainRecordsWhenResponseIs4xx() throws Exception { + public void testUpdateDomainRecordsWhenResponseIs4xx() throws Exception { DomainApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/domain/updaterecord/format/json") .addHeader("Accept", "application/json") @@ -176,7 +177,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("ttl", "1800").build(), HttpResponse.builder().statusCode(404).build()).getDomainApi(); - api.editRecord("256151", EditRecordOptions.Builder.host("somehost"), EditRecordOptions.Builder.ttl(1800)); + api.updateRecord("256151", UpdateRecordOptions.Builder.host("somehost").ttl(1800)); } public void testDeleteDomainRecordsWhenResponseIs2xx() throws Exception { @@ -212,7 +213,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .payload(payloadFromResourceWithContentType("/domain_details.json", MediaType.APPLICATION_JSON)).build()) .getDomainApi(); - assertEquals(api.getDomain("cl66666_x"), domainInDomainDetails()); + assertEquals(api.get("cl66666_x"), domainInDomainDetails()); } @@ -225,7 +226,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(404).build()) .getDomainApi(); - assertNull(api.getDomain("cl66666_x")); + assertNull(api.get("cl66666_x")); } protected Domain domainInDomainDetails() { @@ -242,7 +243,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .payload(payloadFromResourceWithContentType("/domain_details.json", MediaType.APPLICATION_JSON)).build()) .getDomainApi(); - assertEquals(api.addDomain("cl66666_x"), domainInDomainDetails()); + assertEquals(api.create("cl66666_x"), domainInDomainDetails()); } public void testAddDomainWithOptsWhenResponseIs2xx() throws Exception { @@ -264,32 +265,34 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { AddDomainOptions options = (AddDomainOptions) AddDomainOptions.Builder.primaryNameServer("ns1.somewhere.x") .expire(1).minimum(1).refresh(1).responsiblePerson("Tester").retry(1).ttl(1); - assertEquals(api.addDomain("cl66666_x", options), domainInDomainDetails()); + assertEquals(api.create("cl66666_x", options), domainInDomainDetails()); } - public void testEditDomainWhenResponseIs2xx() throws Exception { + public void testUpdateDomainWhenResponseIs2xx() throws Exception { DomainApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/domain/edit/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") - .addFormParam("domainname", "x").build(), + .addFormParam("domainname", "x") + .addFormParam("expire", "1").build(), HttpResponse.builder().statusCode(200) .payload(payloadFromResourceWithContentType("/domain_details.json", MediaType.APPLICATION_JSON)).build()) .getDomainApi(); - assertEquals(api.editDomain("x"), domainInDomainDetails()); + assertEquals(api.update("x", DomainOptions.Builder.expire(1)), domainInDomainDetails()); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testEditDomainWhenResponseIs4xxThrows() throws Exception { + public void testUpdateDomainWhenResponseIs4xxThrows() throws Exception { DomainApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/domain/edit/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") - .addFormParam("domainname", "x").build(), + .addFormParam("domainname", "x") + .addFormParam("expire", "1").build(), HttpResponse.builder().statusCode(404).build()).getDomainApi(); - api.editDomain("x"); + api.update("x", DomainOptions.Builder.expire(1)); } public void testDeleteDomainWhenResponseIs2xx() throws Exception { @@ -299,7 +302,7 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("domainname", "x").build(), HttpResponse.builder().statusCode(200).build()).getDomainApi(); - api.deleteDomain("x"); + api.delete("x"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) @@ -310,6 +313,6 @@ public class DomainApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("domainname", "x").build(), HttpResponse.builder().statusCode(404).build()).getDomainApi(); - api.deleteDomain("x"); + api.delete("x"); } } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java index 61cacf3e8c..2f086ab526 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java @@ -29,7 +29,7 @@ import org.jclouds.glesys.domain.Domain; import org.jclouds.glesys.domain.DomainRecord; import org.jclouds.glesys.internal.BaseGleSYSApiLiveTest; import org.jclouds.glesys.options.DomainOptions; -import org.jclouds.glesys.options.EditRecordOptions; +import org.jclouds.glesys.options.UpdateRecordOptions; import org.jclouds.predicates.RetryablePredicate; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; @@ -54,7 +54,7 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { domainCounter = new RetryablePredicate( new Predicate() { public boolean apply(Integer value) { - return api.listDomains().size() == value; + return api.list().size() == value; } }, 30, 1, TimeUnit.SECONDS); recordCounter = new RetryablePredicate( @@ -65,7 +65,7 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { }, 30, 1, TimeUnit.SECONDS); try { - api.deleteDomain(testDomain); + api.delete(testDomain); } catch (Exception ex) { } @@ -74,8 +74,8 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { @AfterGroups(groups = {"live"}) public void tearDownContext() { - int before = api.listDomains().size(); - api.deleteDomain(testDomain); + int before = api.list().size(); + api.delete(testDomain); assertTrue(domainCounter.apply(before - 1)); super.tearDownContext(); @@ -87,16 +87,16 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { @Test public void testGetDomain() throws Exception { - Domain domain = api.getDomain(testDomain); + Domain domain = api.get(testDomain); assertNotNull(domain); - assertEquals(domain.getDomainName(), testDomain); + assertEquals(domain.getName(), testDomain); assertNotNull(domain.getCreateTime()); } @Test - public void testEditDomain() throws Exception { - api.editDomain(testDomain, DomainOptions.Builder.responsiblePerson("another-tester.jclouds.org.")); - Domain domain = api.getDomain(testDomain); + public void testUpdateDomain() throws Exception { + api.update(testDomain, DomainOptions.Builder.responsiblePerson("another-tester.jclouds.org.")); + Domain domain = api.get(testDomain); assertEquals(domain.getResponsiblePerson(), "another-tester.jclouds.org."); } @@ -104,7 +104,7 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { public void testCreateRecord() throws Exception { int before = api.listRecords(testDomain).size(); - api.addRecord(testDomain, "test", "A", "127.0.0.1"); + api.createRecord(testDomain, "test", "A", "127.0.0.1"); assertTrue(recordCounter.apply(before + 1)); @@ -117,10 +117,10 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { } @Test - public void testEditRecord() throws Exception { + public void testUpdateRecord() throws Exception { int before = api.listRecords(testDomain).size(); - api.addRecord(testDomain, "testeditbefore", "A", "127.0.0.1"); + api.createRecord(testDomain, "testeditbefore", "A", "127.0.0.1"); assertTrue(recordCounter.apply(before + 1)); @@ -135,7 +135,7 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { assertNotNull(recordId); - api.editRecord(recordId, EditRecordOptions.Builder.host("testeditafter")); + api.updateRecord(recordId, UpdateRecordOptions.Builder.host("testeditafter")); boolean found = false; for(DomainRecord record : api.listRecords(testDomain)) { diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java similarity index 81% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/EmailApiExpectTest.java rename to labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java index 9145784cb8..af8801fe11 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java @@ -33,7 +33,7 @@ import org.jclouds.glesys.domain.EmailOverviewDomain; import org.jclouds.glesys.domain.EmailOverviewSummary; import org.jclouds.glesys.domain.EmailQuota; import org.jclouds.glesys.internal.BaseGleSYSApiExpectTest; -import org.jclouds.glesys.options.EditAccountOptions; +import org.jclouds.glesys.options.UpdateAccountOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.AuthorizationException; @@ -44,20 +44,20 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; /** - * Tests annotation parsing of {@code EmailApi} + * Tests annotation parsing of {@code EmailAccountApi} * * @author Adam Lowe */ -@Test(groups = "unit", testName = "EmailAsyncApiTest") -public class EmailApiExpectTest extends BaseGleSYSApiExpectTest { +@Test(groups = "unit", testName = "EmailAccountAsyncApiTest") +public class EmailAccountApiExpectTest extends BaseGleSYSApiExpectTest { public void testListWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/list/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("domainname", "cl13016.test.jclouds.org").build(), - HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_list.json")).build()).getEmailApi(); + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_list.json")).build()).getEmailAccountApi(); EmailAccount.Builder builder = EmailAccount.builder().quota(EmailQuota.builder().max(200).unit("MB").build()).antispamLevel(3).antiVirus(true).autoRespond(false).autoRespondSaveEmail(true); Set expected = @@ -69,108 +69,108 @@ public class EmailApiExpectTest extends BaseGleSYSApiExpectTest { .modified(dateService.iso8601SecondsDateParse("2012-06-24T11:53:48+02:00")).build() ); - Set actual = api.listAccounts("cl13016.test.jclouds.org"); + Set actual = api.listDomain("cl13016.test.jclouds.org").toImmutableSet(); assertEquals(actual, expected); assertEquals(Iterables.get(actual, 0).toString(), Iterables.get(expected, 0).toString()); } public void testListWhenResponseIs404IsEmpty() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/list/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("domainname", "test").build(), - HttpResponse.builder().statusCode(404).build()).getEmailApi(); + HttpResponse.builder().statusCode(404).build()).getEmailAccountApi(); - assertTrue(api.listAccounts("test").isEmpty()); + assertTrue(api.listDomain("test").isEmpty()); } public void testListAliasesWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/list/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("domainname", "cl13016.test.jclouds.org").build(), - HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_list.json")).build()).getEmailApi(); + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_list.json")).build()).getEmailAccountApi(); EmailAlias expected = EmailAlias.builder().alias("test2@cl13016.test.jclouds.org").forwardTo("test2@cl13016.test.jclouds.org").build(); - EmailAlias actual = Iterables.getOnlyElement(api.listAliases("cl13016.test.jclouds.org")); + EmailAlias actual = Iterables.getOnlyElement(api.listAliasesInDomain("cl13016.test.jclouds.org")); assertEquals(actual, expected); } public void testListAliasesWhenResponseIs404IsEmpty() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/list/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("domainname", "test").build(), - HttpResponse.builder().statusCode(404).build()).getEmailApi(); + HttpResponse.builder().statusCode(404).build()).getEmailAccountApi(); - assertTrue(api.listAliases("test").isEmpty()); + assertTrue(api.listAliasesInDomain("test").isEmpty()); } public void testOverviewWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/overview/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), - HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_overview.json")).build()).getEmailApi(); + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_overview.json")).build()).getEmailAccountApi(); EmailOverviewSummary summary = EmailOverviewSummary.builder().accounts(2).maxAccounts(50).aliases(1).maxAliases(1000).build(); EmailOverviewDomain domain = EmailOverviewDomain.builder().domain("cl13016.test.jclouds.org").accounts(2).aliases(0).build(); EmailOverview expected = EmailOverview.builder().summary(summary).domains(domain).build(); - assertEquals(api.getEmailOverview(), expected); + assertEquals(api.getOverview(), expected); } public void testOverviewWhenResponseIs404ReturnsNull() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/overview/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), - HttpResponse.builder().statusCode(404).build()).getEmailApi(); + HttpResponse.builder().statusCode(404).build()).getEmailAccountApi(); - assertNull(api.getEmailOverview()); + assertNull(api.getOverview()); } public void testCreateAccountWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/createaccount/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailaccount", "test@jclouds.org") .addFormParam("password", "newpass").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/email_details.json", MediaType.APPLICATION_JSON)).build()) - .getEmailApi(); + .getEmailAccountApi(); - assertEquals(api.createAccount("test@jclouds.org", "newpass").toString(), getEmailAccountInDetails().toString()); + assertEquals(api.createWithPassword("test@jclouds.org", "newpass").toString(), getEmailAccountInDetails().toString()); } - public void testEditAccountWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + public void testUpdateAccountWhenResponseIs2xx() throws Exception { + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/editaccount/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailaccount", "test@jclouds.org") .addFormParam("password", "anotherpass").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/email_details.json", MediaType.APPLICATION_JSON)).build()) - .getEmailApi(); + .getEmailAccountApi(); - assertEquals(api.editAccount("test@jclouds.org", EditAccountOptions.Builder.password("anotherpass")).toString(), getEmailAccountInDetails().toString()); + assertEquals(api.update("test@jclouds.org", UpdateAccountOptions.Builder.password("anotherpass")).toString(), getEmailAccountInDetails().toString()); } @Test(expectedExceptions = ResourceNotFoundException.class) - public void testEditAccountWhenResponseIs4xx() throws Exception { - EmailApi api = requestSendsResponse( + public void testUpdateAccountWhenResponseIs4xx() throws Exception { + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/editaccount/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailaccount", "test@jclouds.org") .addFormParam("password", "anotherpass").build(), HttpResponse.builder().statusCode(404).build()) - .getEmailApi(); + .getEmailAccountApi(); - assertEquals(api.editAccount("test@jclouds.org", EditAccountOptions.Builder.password("anotherpass")).toString(), getEmailAccountInDetails().toString()); + assertEquals(api.update("test@jclouds.org", UpdateAccountOptions.Builder.password("anotherpass")).toString(), getEmailAccountInDetails().toString()); } private EmailAccount getEmailAccountInDetails() { @@ -184,84 +184,84 @@ public class EmailApiExpectTest extends BaseGleSYSApiExpectTest { @Test(expectedExceptions = {ResourceNotFoundException.class}) public void testCreateAccountWhenResponseIs4xxThrows() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/createaccount/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailaccount", "test@jclouds.org") .addFormParam("password", "newpass").build(), - HttpResponse.builder().statusCode(404).build()).getEmailApi(); + HttpResponse.builder().statusCode(404).build()).getEmailAccountApi(); - api.createAccount("test@jclouds.org", "newpass"); + api.createWithPassword("test@jclouds.org", "newpass"); } public void testCreateAliasWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/createalias/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailalias", "test2@jclouds.org") .addFormParam("goto", "test@jclouds.org").build(), - HttpResponse.builder().statusCode(200).build()).getEmailApi(); + HttpResponse.builder().statusCode(200).build()).getEmailAccountApi(); api.createAlias("test2@jclouds.org", "test@jclouds.org"); } @Test(expectedExceptions = {AuthorizationException.class}) public void testCreateAliasWhenResponseIs4xxThrows() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/createalias/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailalias", "test2@jclouds.org") .addFormParam("goto", "test@jclouds.org").build(), - HttpResponse.builder().statusCode(401).build()).getEmailApi(); + HttpResponse.builder().statusCode(401).build()).getEmailAccountApi(); api.createAlias("test2@jclouds.org", "test@jclouds.org"); } - public void testEditAliasWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + public void testUpdateAliasWhenResponseIs2xx() throws Exception { + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/editalias/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailalias", "test2@jclouds.org") .addFormParam("goto", "test@jclouds.org").build(), - HttpResponse.builder().statusCode(200).build()).getEmailApi(); + HttpResponse.builder().statusCode(200).build()).getEmailAccountApi(); - api.editAlias("test2@jclouds.org", "test@jclouds.org"); + api.updateAlias("test2@jclouds.org", "test@jclouds.org"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testEditAliasWhenResponseIs4xxThrows() throws Exception { - EmailApi api = requestSendsResponse( + public void testUpdateAliasWhenResponseIs4xxThrows() throws Exception { + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/editalias/format/json") .addHeader("Accept", "application/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("emailalias", "test2@jclouds.org") .addFormParam("goto", "test@jclouds.org").build(), - HttpResponse.builder().statusCode(404).build()).getEmailApi(); + HttpResponse.builder().statusCode(404).build()).getEmailAccountApi(); - api.editAlias("test2@jclouds.org", "test@jclouds.org"); + api.updateAlias("test2@jclouds.org", "test@jclouds.org"); } public void testDeleteWhenResponseIs2xx() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/delete/format/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("email", "test2@jclouds.org").build(), - HttpResponse.builder().statusCode(200).build()).getEmailApi(); + HttpResponse.builder().statusCode(200).build()).getEmailAccountApi(); api.delete("test2@jclouds.org"); } @Test(expectedExceptions = {ResourceNotFoundException.class}) public void testDeleteWhenResponseIs4xxThrows() throws Exception { - EmailApi api = requestSendsResponse( + EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/delete/format/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") .addFormParam("email", "test2@jclouds.org").build(), - HttpResponse.builder().statusCode(404).build()).getEmailApi(); + HttpResponse.builder().statusCode(404).build()).getEmailAccountApi(); api.delete("test2@jclouds.org"); } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java similarity index 74% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/EmailApiLiveTest.java rename to labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java index d050cab591..472a11c3e4 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.glesys.domain.EmailAccount; @@ -32,34 +31,35 @@ import org.jclouds.glesys.domain.EmailOverview; import org.jclouds.glesys.domain.EmailOverviewDomain; import org.jclouds.glesys.internal.BaseGleSYSApiWithAServerLiveTest; import org.jclouds.glesys.options.CreateAccountOptions; -import org.jclouds.glesys.options.EditAccountOptions; +import org.jclouds.glesys.options.UpdateAccountOptions; import org.jclouds.predicates.RetryablePredicate; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; /** - * Tests behavior of {@code EmailApi} + * Tests behavior of {@code EmailAccountApi} * * @author Adam Lowe */ -@Test(groups = "live", testName = "EmailApiLiveTest", singleThreaded = true) -public class EmailApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { +@Test(groups = "live", testName = "EmailAccountApiLiveTest", singleThreaded = true) +public class EmailAccountApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @BeforeGroups(groups = {"live"}) public void setupDomains() { testDomain = identity + ".test.jclouds.org"; - api = gleContext.getApi().getEmailApi(); + api = gleContext.getApi().getEmailAccountApi(); createDomain(testDomain); emailAccountCounter = new RetryablePredicate( new Predicate() { public boolean apply(Integer value) { - return api.listAccounts(testDomain).size() == value; + return api.listDomain(testDomain).size() == value; } }, 180, 5, TimeUnit.SECONDS); @@ -76,84 +76,84 @@ public class EmailApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { api.delete("test@" + testDomain); api.delete("test1@" + testDomain); assertTrue(emailAccountCounter.apply(0)); - gleContext.getApi().getDomainApi().deleteDomain(testDomain); + gleContext.getApi().getEmailAccountApi().delete(testDomain); } - private EmailApi api; + private EmailAccountApi api; private String testDomain; private RetryablePredicate emailAccountCounter; @Test public void testCreateEmail() { - api.createAccount("test@" + testDomain, "password", + api.createWithPassword("test@" + testDomain, "password", CreateAccountOptions.Builder.antiVirus(true).autorespond(true).autorespondMessage("out of office")); assertTrue(emailAccountCounter.apply(1)); - api.createAccount("test1@" + testDomain, "password"); + api.createWithPassword("test1@" + testDomain, "password"); assertTrue(emailAccountCounter.apply(2)); } @Test(dependsOnMethods = "testCreateEmail") public void testAliases() { - assertTrue(api.listAliases(testDomain).isEmpty()); + assertTrue(api.listAliasesInDomain(testDomain).isEmpty()); EmailAlias alias = api.createAlias("test2@" + testDomain, "test@" + testDomain); assertEquals(alias.getAlias(), "test2@" + testDomain); assertEquals(alias.getForwardTo(), "test@" + testDomain); - EmailAlias aliasFromList = Iterables.getOnlyElement(api.listAliases(testDomain)); + EmailAlias aliasFromList = Iterables.getOnlyElement(api.listAliasesInDomain(testDomain)); assertEquals(aliasFromList, alias); - EmailOverview overview = api.getEmailOverview(); + EmailOverview overview = api.getOverview(); assertTrue(overview.getSummary().getAliases() == 1); - alias = api.editAlias("test2@" + testDomain, "test1@" + testDomain); - overview = api.getEmailOverview(); + alias = api.updateAlias("test2@" + testDomain, "test1@" + testDomain); + overview = api.getOverview(); assertTrue(overview.getSummary().getAliases() == 1); - aliasFromList = Iterables.getOnlyElement(api.listAliases(testDomain)); + aliasFromList = Iterables.getOnlyElement(api.listAliasesInDomain(testDomain)); assertEquals(aliasFromList, alias); api.delete("test2@" + testDomain); - overview = api.getEmailOverview(); + overview = api.getOverview(); assertTrue(overview.getSummary().getAliases() == 0); } @Test(dependsOnMethods = "testCreateEmail") public void testOverview() throws Exception { - EmailOverview overview = api.getEmailOverview(); + EmailOverview overview = api.getOverview(); assertNotNull(overview.getSummary()); assertTrue(overview.getSummary().getAccounts() > 0); assertTrue(overview.getSummary().getAliases() > -1); assertTrue(overview.getSummary().getMaxAccounts() > 0); assertTrue(overview.getSummary().getMaxAliases() > 0); - assertNotNull(overview.getDomains()); - assertFalse(overview.getDomains().isEmpty()); + assertNotNull(overview.gets()); + assertFalse(overview.gets().isEmpty()); EmailOverviewDomain domain = EmailOverviewDomain.builder().domain(testDomain).accounts(1).build(); - assertTrue(overview.getDomains().contains(domain)); + assertTrue(overview.gets().contains(domain)); } @Test(dependsOnMethods = "testCreateEmail") public void testListAccounts() throws Exception { - Set accounts = api.listAccounts(testDomain); + FluentIterable accounts = api.listDomain(testDomain); assertTrue(accounts.size() >= 1); } @Test(dependsOnMethods = "testCreateEmail") - public void testEditAccount() throws Exception { - Set accounts = api.listAccounts(testDomain); + public void testUpdateAccount() throws Exception { + FluentIterable accounts = api.listDomain(testDomain); for (EmailAccount account : accounts) { if (account.getAccount().equals("test@" + testDomain)) { assertTrue(account.isAntiVirus()); } } - api.editAccount("test@" + testDomain, EditAccountOptions.Builder.antiVirus(false)); + api.update("test@" + testDomain, UpdateAccountOptions.Builder.antiVirus(false)); - accounts = api.listAccounts(testDomain); + accounts = api.listDomain(testDomain); for (EmailAccount account : accounts) { if (account.getAccount().equals("test@" + testDomain)) { assertFalse(account.isAntiVirus()); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java index e256def199..6358d9531a 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java @@ -58,7 +58,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { .nameServers("79.99.4.100", "79.99.4.101") .cost(Cost.builder().amount(2.0).currency("EUR").timePeriod("month").build()); - assertEquals(api.listIps().toString(), ImmutableSet.of( + assertEquals(api.list().toString(), ImmutableSet.of( builder.ptr("31-192-230-68-static.serverhotell.net.").address("31.192.230.68").serverId(null).build(), builder.ptr("31-192-231-148-static.serverhotell.net.").address("31.192.231.148").serverId("vz1609110").build()).toString()); } @@ -70,7 +70,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getIpApi(); - assertTrue(api.listIps().isEmpty()); + assertTrue(api.list().isEmpty()); } public void testGetIpDetailsWhenResponseIs2xx() { @@ -81,7 +81,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/ip_get_details.json")).build()) .getIpApi(); - assertEquals(api.getIp("31.192.227.113"), getIpInIpDetails()); + assertEquals(api.get("31.192.227.113"), getIpInIpDetails()); } protected IpDetails getIpInIpDetails() { @@ -100,7 +100,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getIpApi(); - assertEquals(api.getIp("31.192.227.37"), null); + assertEquals(api.get("31.192.227.37"), null); } public void testTakeWhenResponseIs2xx() { @@ -159,7 +159,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/ip_list_free.json")).build()) .getIpApi(); - assertEquals(api.listFree(4, "Falkenberg", "OpenVZ"), ParseIpAddressFromResponseTest.EXPECTED_IPS); + assertEquals(api.listFree(4, "Falkenberg", "OpenVZ").toImmutableSet(), ParseIpAddressFromResponseTest.EXPECTED_IPS); } public void testListFreeWhenResponseIs404ReturnsEmptySet() { @@ -170,7 +170,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(404).build()) .getIpApi(); - assertEquals(api.listFree(6, "Falkenberg", "OpenVZ"), emptySet()); + assertEquals(api.listFree(6, "Falkenberg", "OpenVZ").toImmutableSet(), emptySet()); } public void testAddWhenResponseIs2xx() { @@ -183,7 +183,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getIpApi(); - api.addIpToServer("31.192.227.37", "vz1946889"); + api.addToServer("31.192.227.37", "vz1946889"); } @Test(expectedExceptions = AuthorizationException.class) @@ -196,7 +196,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("serverid", "vz1946889").build(), HttpResponse.builder().statusCode(401).build()) .getIpApi(); - api.addIpToServer("31.192.227.37", "vz1946889"); + api.addToServer("31.192.227.37", "vz1946889"); } public void testRemoveWhenResponseIs2xx() { @@ -209,7 +209,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getIpApi(); - api.removeIpFromServer("31.192.227.37", "vz1946889"); + api.removeFromServer("31.192.227.37", "vz1946889"); } @Test(expectedExceptions = HttpResponseException.class) @@ -223,7 +223,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(400).build()) .getIpApi(); - api.removeIpFromServer("31.192.227.37", "vz1946889"); + api.removeFromServer("31.192.227.37", "vz1946889"); } public void testRemoveAndReleaseWhenResponseIs2xx() { @@ -237,7 +237,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getIpApi(); - api.removeIpFromServerAndRelease("31.192.227.37", "vz1946889"); + api.removeFromServerAndRelease("31.192.227.37", "vz1946889"); } @Test(expectedExceptions = HttpResponseException.class) @@ -252,7 +252,7 @@ public class IpApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(400).build()) .getIpApi(); - api.removeIpFromServerAndRelease("31.192.227.37", "vz1946889"); + api.removeFromServerAndRelease("31.192.227.37", "vz1946889"); } public void testSetPrtWhenResponseIs2xx() { diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java index f07240e014..15cd8fb751 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java @@ -33,6 +33,7 @@ import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -61,13 +62,13 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @Test public void testListFree() throws Exception { - Set freeIps = api.listFree(4, "Falkenberg", "Xen"); + FluentIterable freeIps = api.listFree(4, "Falkenberg", "Xen"); assertFalse(freeIps.isEmpty()); } @Test public void reserveIp() throws Exception { - Set openVzIps = api.listFree(4, "Falkenberg", "OpenVZ"); + FluentIterable openVzIps = api.listFree(4, "Falkenberg", "OpenVZ"); assertFalse(openVzIps.isEmpty()); reservedIp = api.take(Iterables.get(openVzIps, 0)); assertTrue(reservedIp.isReserved()); @@ -86,21 +87,21 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @Test(dependsOnMethods = "reserveIp") public void testList() throws Exception { - Set ownIps = api.listIps(); + FluentIterable ownIps = api.list(); assertTrue(ownIps.contains(reservedIp)); - ownIps = api.listIps(ListIpOptions.Builder.datacenter(reservedIp.getDatacenter())); + ownIps = api.list(ListIpOptions.Builder.datacenter(reservedIp.getDatacenter())); assertTrue(ownIps.contains(reservedIp)); - ownIps = api.listIps(ListIpOptions.Builder.platform(reservedIp.getPlatform())); + ownIps = api.list(ListIpOptions.Builder.platform(reservedIp.getPlatform())); assertTrue(ownIps.contains(reservedIp)); - ownIps = api.listIps(ListIpOptions.Builder.ipVersion(reservedIp.getVersion())); + ownIps = api.list(ListIpOptions.Builder.ipVersion(reservedIp.getVersion())); assertTrue(ownIps.contains(reservedIp)); - ownIps = api.listIps(ListIpOptions.Builder.datacenter(reservedIp.getDatacenter()), + ownIps = api.list(ListIpOptions.Builder.datacenter(reservedIp.getDatacenter()), ListIpOptions.Builder.platform(reservedIp.getPlatform()), ListIpOptions.Builder.ipVersion(reservedIp.getVersion())); assertTrue(ownIps.contains(reservedIp)); - ownIps = api.listIps(ListIpOptions.Builder.serverId("xmthisisnotaserverid")); + ownIps = api.list(ListIpOptions.Builder.serverId("xmthisisnotaserverid")); assertTrue(ownIps.isEmpty()); } @@ -115,20 +116,20 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @Test public void testGetOpenVZDetails() throws Exception { - Set openVzIps = api.listFree(4, "Falkenberg", "OpenVZ"); + FluentIterable openVzIps = api.listFree(4, "Falkenberg", "OpenVZ"); assertFalse(openVzIps.isEmpty()); String openVzIp = openVzIps.iterator().next(); - IpDetails ipDetails = api.getIp(openVzIp); + IpDetails ipDetails = api.get(openVzIp); checkOpenVZDefailsInFalkenberg(ipDetails); assertEquals(ipDetails.getAddress(), openVzIp); } @Test public void testGetXenDetails() throws Exception { - Set xenVzIps = api.listFree(4, "Falkenberg", "Xen"); + FluentIterable xenVzIps = api.listFree(4, "Falkenberg", "Xen"); assertFalse(xenVzIps.isEmpty()); String xenIp = xenVzIps.iterator().next(); - IpDetails ipDetails = api.getIp(xenIp); + IpDetails ipDetails = api.get(xenIp); assertEquals(ipDetails.getDatacenter(), "Falkenberg"); assertEquals(ipDetails.getPlatform(), "Xen"); assertEquals(ipDetails.getVersion(), 4); @@ -145,7 +146,7 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { IpDetails original = reservedIp; IpDetails modified = api.setPtr(reservedIp.getAddress(), "wibble."); - IpDetails modified2 = api.getIp(reservedIp.getAddress()); + IpDetails modified2 = api.get(reservedIp.getAddress()); assertEquals(modified.getPtr(), "wibble."); assertEquals(modified2, modified); @@ -157,16 +158,16 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @Test(dependsOnMethods = "reserveIp") public void testAddRemove() throws Exception { - IpDetails added = api.addIpToServer(reservedIp.getAddress(), serverId); + IpDetails added = api.addToServer(reservedIp.getAddress(), serverId); assertEquals(added.getAddress(), reservedIp.getAddress()); assertEquals(added.getPtr(), reservedIp.getPtr()); assertEquals(added.getServerId(), serverId); - IpDetails again = api.getIp(reservedIp.getAddress()); + IpDetails again = api.get(reservedIp.getAddress()); assertEquals(again, added); - IpDetails removed = api.removeIpFromServer(reservedIp.getAddress(), serverId); + IpDetails removed = api.removeFromServer(reservedIp.getAddress(), serverId); assertEquals(removed, added.toBuilder().serverId(null).build()); assertEquals(removed, reservedIp); @@ -175,11 +176,11 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { openVzIps.remove(reservedIp.getAddress()); assertFalse(openVzIps.isEmpty()); - added = api.addIpToServer(reservedIp.getAddress(), serverId); + added = api.addToServer(reservedIp.getAddress(), serverId); assertEquals(added.getServerId(), serverId); - removed = api.removeIpFromServerAndRelease(reservedIp.getAddress(), serverId); + removed = api.removeFromServerAndRelease(reservedIp.getAddress(), serverId); assertNull(removed.getServerId()); assertFalse(removed.isReserved()); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java index ac6c40ff2d..78c0b65efc 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java @@ -45,7 +45,7 @@ import org.jclouds.glesys.internal.BaseGleSYSApiExpectTest; import org.jclouds.glesys.options.CloneServerOptions; import org.jclouds.glesys.options.CreateServerOptions; import org.jclouds.glesys.options.DestroyServerOptions; -import org.jclouds.glesys.options.EditServerOptions; +import org.jclouds.glesys.options.UpdateServerOptions; import org.jclouds.glesys.options.ServerStatusOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -72,7 +72,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_list.json")).build()).getServerApi(); Server expected = Server.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ").build(); - assertEquals(api.listServers(), ImmutableSet.of(expected)); + assertEquals(api.list().toImmutableSet(), ImmutableSet.of(expected)); } public void testListServersWhenReponseIs404IsEmpty() { @@ -82,7 +82,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(), HttpResponse.builder().statusCode(404).build()).getServerApi(); - assertTrue(api.listServers().isEmpty()); + assertTrue(api.list().isEmpty()); } public void testGetAllowedArgumentsWhenResponseIs2xx() throws Exception { @@ -117,7 +117,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .build(); expected.put("Xen", xen); expected.put("OpenVZ", openvz); - assertEquals(api.getAllowedArgumentsForCreateServerByPlatform(), expected); + assertEquals(api.getAllowedArgumentsForCreateByPlatform(), expected); } public void testGetTemplatesWhenResponseIs2xx() throws Exception { @@ -147,7 +147,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { expectedBuilder.add(OSTemplate.builder().name(name).minDiskSize(20).minMemSize(1024).os("windows").platform("Xen").build()); } - assertEquals(api.listTemplates(), expectedBuilder.build()); + assertEquals(api.listTemplates().toImmutableSet(), expectedBuilder.build()); } public void testGetServerDetailsWhenResponseIs2xx() throws Exception { @@ -159,7 +159,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("serverid", "xm3276891").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerApi(); - ServerDetails actual = api.getServerDetails("xm3276891"); + ServerDetails actual = api.get("xm3276891"); assertEquals(actual.toString(), expectedServerDetails().toString()); } @@ -181,7 +181,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("serverid", "xm3276891").build(), HttpResponse.builder().statusCode(404).build()).getServerApi(); - assertNull(api.getServerDetails("xm3276891")); + assertNull(api.get("xm3276891")); } @Test @@ -206,7 +206,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .templateName("Ubuntu 11.04 64-bit").description("description").cpuCores(1).memorySizeMB(128).diskSizeGB(5).transferGB(50).cost(cost).build(); assertEquals( - api.createServerWithHostnameAndRootPassword( + api.createWithHostnameAndRootPassword( ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 32-bit") .diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), "jclouds-test", "password").toString(), expected.toString()); @@ -233,13 +233,13 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { CreateServerOptions options = CreateServerOptions.Builder.description("Description-of-server").ip("10.0.0.1"); - assertEquals(api.createServerWithHostnameAndRootPassword(ServerSpec.builder().datacenter("Falkenberg") + assertEquals(api.createWithHostnameAndRootPassword(ServerSpec.builder().datacenter("Falkenberg") .platform("OpenVZ").templateName("Ubuntu 32-bit").diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50) .build(), "jclouds-test", "password", options), expectedServerDetails()); } @Test - public void testEditServerWhenResponseIs2xx() throws Exception { + public void testUpdateServerWhenResponseIs2xx() throws Exception { ServerApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/server/edit/format/json") .addHeader("Accept", "application/json") @@ -249,12 +249,11 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("hostname", "new-hostname").build(), HttpResponse.builder().statusCode(206).build()).getServerApi(); - api.editServer("xm3276891", EditServerOptions.Builder.description("this is a different description!"), - EditServerOptions.Builder.hostname("new-hostname")); + api.update("xm3276891", UpdateServerOptions.Builder.description("this is a different description!").hostname("new-hostname")); } @Test - public void testEditServerWithOptsWhenResponseIs2xx() throws Exception { + public void testUpdateServerWithOptsWhenResponseIs2xx() throws Exception { ServerApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/server/edit/format/json") .addHeader("Accept", "application/json") @@ -267,10 +266,10 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("hostname", "jclouds-test").build(), HttpResponse.builder().statusCode(200).build()).getServerApi(); - EditServerOptions options = - EditServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1).hostname("jclouds-test"); + UpdateServerOptions options = + UpdateServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1).hostname("jclouds-test"); - api.editServer("xm3276891", options); + api.update("xm3276891", options); } @Test @@ -283,7 +282,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("hostname", "hostname1").build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerApi(); - assertEquals(api.cloneServer("xm3276891", "hostname1"), expectedServerDetails()); + assertEquals(api.clone("xm3276891", "hostname1"), expectedServerDetails()); } @Test @@ -301,7 +300,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerApi(); CloneServerOptions options = (CloneServerOptions) CloneServerOptions.Builder.description("Description-of-server").diskSizeGB(1).memorySizeMB(512).cpuCores(1); - assertEquals(api.cloneServer("xm3276891", "hostname1", options), expectedServerDetails()); + assertEquals(api.clone("xm3276891", "hostname1", options), expectedServerDetails()); } @Test(expectedExceptions = {ResourceNotFoundException.class}) @@ -314,7 +313,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { .addFormParam("hostname", "hostname1").build(), HttpResponse.builder().statusCode(404).build()).getServerApi(); - api.cloneServer("xm3276891", "hostname1"); + api.clone("xm3276891", "hostname1"); } public void testGetServerStatusWhenResponseIs2xx() throws Exception { @@ -326,7 +325,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build()) .getServerApi(); - assertEquals(api.getServerStatus("xm3276891"), expectedServerStatus()); + assertEquals(api.getStatus("xm3276891"), expectedServerStatus()); } public void testGetServerStatusWithOptsWhenResponseIs2xx() throws Exception { @@ -339,7 +338,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build()) .getServerApi(); - assertEquals(api.getServerStatus("server321", ServerStatusOptions.Builder.state()), expectedServerStatus()); + assertEquals(api.getStatus("server321", ServerStatusOptions.Builder.state()), expectedServerStatus()); } public void testGetServerStatusWhenResponseIs4xx() throws Exception { @@ -352,7 +351,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(404).build()) .getServerApi(); - assertNull(api.getServerStatus("server321", ServerStatusOptions.Builder.state())); + assertNull(api.getStatus("server321", ServerStatusOptions.Builder.state())); } public void testGetServerLimitsWhenResponseIs2xx() throws Exception { @@ -364,7 +363,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_limits.json")).build()) .getServerApi(); - api.getServerLimits("server321"); + api.getLimits("server321"); } public void testGetConsoleWhenResponseIs2xx() throws Exception { @@ -402,7 +401,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getServerApi(); - api.startServer("server777"); + api.start("server777"); } @Test(expectedExceptions = {AuthorizationException.class}) @@ -415,7 +414,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(401).build()) .getServerApi(); - api.startServer("server777"); + api.start("server777"); } public void testStopServerWhenResponseIs2xx() throws Exception { @@ -427,7 +426,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getServerApi(); - api.stopServer("server777"); + api.stop("server777"); } public void testHardStopServerWhenResponseIs2xx() throws Exception { @@ -440,7 +439,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getServerApi(); - api.hardStopServer("server777"); + api.hardStop("server777"); } @Test(expectedExceptions = {AuthorizationException.class}) @@ -453,7 +452,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(401).build()) .getServerApi(); - api.stopServer("server777"); + api.stop("server777"); } public void testRebootServerWhenResponseIs2xx() throws Exception { @@ -465,7 +464,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getServerApi(); - api.rebootServer("server777"); + api.reboot("server777"); } @Test(expectedExceptions = {AuthorizationException.class}) @@ -478,7 +477,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(401).build()) .getServerApi(); - api.rebootServer("server777"); + api.reboot("server777"); } public void testDestroyServerWhenResponseIs2xx() throws Exception { @@ -490,7 +489,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(200).build()) .getServerApi(); - api.destroyServer("server777", DestroyServerOptions.Builder.keepIp()); + api.destroy("server777", DestroyServerOptions.Builder.keepIp()); } @Test(expectedExceptions = {AuthorizationException.class}) @@ -503,7 +502,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { HttpResponse.builder().statusCode(401).build()) .getServerApi(); - api.destroyServer("server777", DestroyServerOptions.Builder.discardIp()); + api.destroy("server777", DestroyServerOptions.Builder.discardIp()); } public void testResourceUsageWhenResponseIs2xx() throws Exception { diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java index f555708e89..1ab81e2b85 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.glesys.domain.AllowedArgumentsForCreateServer; @@ -38,14 +37,15 @@ import org.jclouds.glesys.domain.ServerStatus; import org.jclouds.glesys.internal.BaseGleSYSApiWithAServerLiveTest; import org.jclouds.glesys.options.CloneServerOptions; import org.jclouds.glesys.options.DestroyServerOptions; -import org.jclouds.glesys.options.EditServerOptions; import org.jclouds.glesys.options.ServerStatusOptions; +import org.jclouds.glesys.options.UpdateServerOptions; import org.jclouds.predicates.RetryablePredicate; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; /** * Tests behavior of {@code ServerApi} @@ -65,7 +65,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @AfterGroups(groups = {"live"}) public void deleteExtraServer() { if (testServerId2 != null) { - api.destroyServer(testServerId2, DestroyServerOptions.Builder.discardIp()); + api.destroy(testServerId2, DestroyServerOptions.Builder.discardIp()); } } @@ -79,7 +79,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @Test public void testAllowedArguments() throws Exception { - Map templates = api.getAllowedArgumentsForCreateServerByPlatform(); + Map templates = api.getAllowedArgumentsForCreateByPlatform(); assertTrue(templates.containsKey("OpenVZ")); assertTrue(templates.containsKey("Xen")); @@ -101,7 +101,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { } public void testListTemplates() throws Exception { - Set oSTemplates = api.listTemplates(); + FluentIterable oSTemplates = api.listTemplates(); for(OSTemplate oSTemplate : oSTemplates) { checkTemplate(oSTemplate); @@ -119,12 +119,12 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { } public void testListServers() throws Exception { - Set response = api.listServers(); + FluentIterable response = api.list(); assertNotNull(response); assertTrue(response.size() > 0); for (Server server : response) { - ServerDetails newDetails = api.getServerDetails(server.getId()); + ServerDetails newDetails = api.get(server.getId()); assertEquals(newDetails.getId(), server.getId()); assertEquals(newDetails.getHostname(), server.getHostname()); assertEquals(newDetails.getPlatform(), server.getPlatform()); @@ -134,7 +134,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { } public void testServerDetails() throws Exception { - ServerDetails details = api.getServerDetails(serverId); + ServerDetails details = api.get(serverId); checkServer(details); assertEquals("Ubuntu 10.04 LTS 32-bit", details.getTemplateName()); assertEquals("Falkenberg", details.getDatacenter()); @@ -146,22 +146,22 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { } public void testServerStatus() throws Exception { - ServerStatus newStatus = api.getServerStatus(serverId); + ServerStatus newStatus = api.getStatus(serverId); checkStatus(newStatus); } - public void testEditServer() throws Exception { - ServerDetails edited = api.editServer(serverId, EditServerOptions.Builder.description("this is a different description!")); + public void testUpdateServer() throws Exception { + ServerDetails edited = api.update(serverId, UpdateServerOptions.Builder.description("this is a different description!")); assertEquals(edited.getDescription(), "this is a different description!"); - edited = api.editServer(serverId, EditServerOptions.Builder.description("another description!"), EditServerOptions.Builder.hostname("host-name1")); + edited = api.update(serverId, UpdateServerOptions.Builder.description("another description!").hostname("host-name1")); assertEquals(edited.getDescription(), "another description!"); assertEquals(edited.getHostname(), "host-name1"); edited = api.resetPassword(serverId, "anotherpass"); assertEquals(edited.getHostname(), "host-name1"); - edited = api.editServer(serverId, EditServerOptions.Builder.hostname(hostName)); + edited = api.update(serverId, UpdateServerOptions.Builder.hostname(hostName)); assertEquals(edited.getHostname(), hostName); } @@ -169,7 +169,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { public void testRebootServer() throws Exception { assertTrue(serverStatusChecker.apply(Server.State.RUNNING)); - api.rebootServer(serverId); + api.reboot(serverId); assertTrue(serverStatusChecker.apply(Server.State.RUNNING)); } @@ -178,17 +178,17 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { public void testStopAndStartServer() throws Exception { assertTrue(serverStatusChecker.apply(Server.State.RUNNING)); - api.stopServer(serverId); + api.stop(serverId); assertTrue(serverStatusChecker.apply(Server.State.STOPPED)); - api.startServer(serverId); + api.start(serverId); assertTrue(serverStatusChecker.apply(Server.State.RUNNING)); } public void testServerLimits() throws Exception { - Map limits = api.getServerLimits(serverId); + Map limits = api.getLimits(serverId); assertNotNull(limits); for (Map.Entry entry : limits.entrySet()) { assertNotNull(entry.getKey()); @@ -204,7 +204,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { public void testResourceUsage() throws Exception { // test server has only been in existence for less than a minute - check all servers - for (Server server : api.listServers()) { + for (Server server : api.list()) { ResourceUsage usage = api.getResourceUsage(server.getId(), "diskioread", "minute"); assertEquals(usage.getInfo().getResource(), "diskioread"); assertEquals(usage.getInfo().getResolution(), "minute"); @@ -226,7 +226,7 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { // takes a few minutes and requires an extra server (used 1 already) @Test(enabled=false) public void testCloneServer() throws Exception { - ServerDetails testServer2 = api.cloneServer(serverId, testHostName2, CloneServerOptions.Builder.cpucores(1)); + ServerDetails testServer2 = api.clone(serverId, testHostName2, CloneServerOptions.Builder.cpucores(1)); assertNotNull(testServer2.getId()); assertEquals(testServer2.getHostname(), "jclouds-test2"); @@ -237,19 +237,19 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { RetryablePredicate cloneChecker = new ServerStatusChecker(api, testServerId2, 300, 10, TimeUnit.SECONDS); assertTrue(cloneChecker.apply(Server.State.STOPPED)); - api.startServer(testServer2.getId()); + api.start(testServer2.getId()); // TODO ServerStatus==STOPPED suggests the previous call to start should have worked cloneChecker = new RetryablePredicate( new Predicate() { public boolean apply(Server.State value) { - ServerStatus status = api.getServerStatus(testServerId2, ServerStatusOptions.Builder.state()); + ServerStatus status = api.getStatus(testServerId2, ServerStatusOptions.Builder.state()); if (status.getState() == value) { return true; } - api.startServer(testServerId2); + api.start(testServerId2); return false; } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java index e805c30d16..c964c56382 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java @@ -56,11 +56,11 @@ public class BaseGleSYSApiLiveTest extends BaseComputeServiceContextLiveTest { protected void createDomain(String domain) { final DomainApi api = gleContext.getApi().getDomainApi(); - int before = api.listDomains().size(); - api.addDomain(domain); + int before = api.list().size(); + api.create(domain); RetryablePredicate result = new RetryablePredicate(new Predicate() { public boolean apply(Integer value) { - return api.listDomains().size() == value; + return api.list().size() == value; } }, 30, 1, TimeUnit.SECONDS); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java index 75366af467..995d137cbb 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java @@ -69,17 +69,17 @@ public class BaseGleSYSApiWithAServerLiveTest extends BaseGleSYSApiLiveTest { @AfterGroups(groups = {"integration", "live"}) @Override public final void tearDownContext() { - gleContext.getApi().getServerApi().destroyServer(serverId, DestroyServerOptions.Builder.discardIp()); + gleContext.getApi().getServerApi().destroy(serverId, DestroyServerOptions.Builder.discardIp()); super.tearDownContext(); } protected void createDomain(String domain) { final DomainApi api = gleContext.getApi().getDomainApi(); - int before = api.listDomains().size(); - api.addDomain(domain); + int before = api.list().size(); + api.create(domain); RetryablePredicate result = new RetryablePredicate(new Predicate() { public boolean apply(Integer value) { - return api.listDomains().size() == value; + return api.list().size() == value; } }, 30, 1, TimeUnit.SECONDS); @@ -89,7 +89,7 @@ public class BaseGleSYSApiWithAServerLiveTest extends BaseGleSYSApiLiveTest { protected ServerStatusChecker createServer(String hostName) { ServerApi api = gleContext.getApi().getServerApi(); - ServerDetails testServer = api.createServerWithHostnameAndRootPassword( + ServerDetails testServer = api.createWithHostnameAndRootPassword( ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit") .diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), hostName, UUID.randomUUID() .toString().replace("-","")); @@ -117,7 +117,7 @@ public class BaseGleSYSApiWithAServerLiveTest extends BaseGleSYSApiLiveTest { super(new Predicate() { public boolean apply(Server.State value) { - ServerStatus status = api.getServerStatus(serverId, ServerStatusOptions.Builder.state()); + ServerStatus status = api.getStatus(serverId, ServerStatusOptions.Builder.state()); return status.getState() == value; } From 2ebd5f0247bd65f46c73049480cfcbdedb7b45b3 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 16:20:45 -0700 Subject: [PATCH 47/60] not all cloud providers accept mixed case metadata keys --- .../jclouds/compute/internal/BaseComputeServiceLiveTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java index 7c6624a551..376119578e 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java @@ -645,7 +645,9 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte } protected void createAndRunAServiceInGroup(String group) throws RunNodesException { - ImmutableMap userMetadata = ImmutableMap. of("Name", group); + // note that some cloud providers do not support mixed case tag names + ImmutableMap userMetadata = ImmutableMap. of("name", group); + ImmutableSet tags = ImmutableSet. of(group); Stopwatch watch = new Stopwatch().start(); NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, From 612aa2c93a38cc06a5a29c9f70a372dfceaa58ab Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 16:21:09 -0700 Subject: [PATCH 48/60] update for elastichosts to support metadata and tags --- .../compute/ElasticStackComputeServiceAdapter.java | 3 ++- .../compute/functions/ServerInfoToNodeMetadata.java | 3 ++- .../compute/ElasticStackComputeServiceLiveTest.java | 12 ++---------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java index adce2eba15..217f71a13a 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java @@ -122,7 +122,8 @@ public class ElasticStackComputeServiceAdapter implements } Server toCreate = small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()) - .cpu((int) (template.getHardware().getProcessors().get(0).getSpeed())).build(); + .cpu((int) (template.getHardware().getProcessors().get(0).getSpeed())) + .tags(template.getOptions().getTags()).userMetadata(template.getOptions().getUserMetadata()).build(); ServerInfo from = client.createServer(toCreate); client.startServer(from.getUuid()); diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java index 887d0f3486..27f648f928 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java @@ -93,7 +93,8 @@ public class ServerInfoToNodeMetadata implements Function userMetadata) { - assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( - "node userMetadata did not match %s %s", userMetadata, node); - } - @Override public void testOptionToNotBlock() { // start call is blocking anyway. @@ -56,6 +48,6 @@ public class ElasticStackComputeServiceLiveTest extends BaseComputeServiceLiveTe protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { // hostname is not predictable based on node metadata - assert execResponse.getOutput().trim().equals("ubuntu"); + assert execResponse.getOutput().trim().equals("ubuntu") : execResponse.getOutput(); } } From 2543c0abd79dfa810a28ef4680603efb0f650673 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 16:21:34 -0700 Subject: [PATCH 49/60] disabled broken tests in abiquo --- .../org/jclouds/abiquo/features/PricingAsyncApiTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java index 2fcaaf35c8..3e0f6a01f2 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/features/PricingAsyncApiTest.java @@ -42,7 +42,7 @@ import com.google.inject.TypeLiteral; * @author Ignasi Barrera * @author Susana Acedo */ -@Test(groups = "unit", testName = "PricingAsyncApiTest") +@Test(groups = "unit", singleThreaded = true, testName = "PricingAsyncApiTest") public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest { @@ -80,6 +80,7 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest checkFilters(request); } + @Test(enabled = false) //TODO: fails public void testCreateCurrency() throws SecurityException, NoSuchMethodException, IOException { Method method = PricingAsyncApi.class.getMethod("createCurrency", CurrencyDto.class); @@ -97,7 +98,8 @@ public class PricingAsyncApiTest extends BaseAbiquoAsyncApiTest checkFilters(request); } - + + @Test(enabled = false) //TODO: fails public void testUpdateCurrency() throws SecurityException, NoSuchMethodException, IOException { Method method = PricingAsyncApi.class.getMethod("updateCurrency", CurrencyDto.class); From c078cb21704c56b2dfe1b70350df657fcbd2c34e Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Sun, 16 Sep 2012 15:43:18 -0700 Subject: [PATCH 50/60] Initial contribution to metadata APIs --- .../nova/v2_0/features/ImageApi.java | 67 ++++ .../nova/v2_0/features/ImageAsyncApi.java | 75 +++++ .../nova/v2_0/features/ServerApi.java | 67 ++++ .../nova/v2_0/features/ServerAsyncApi.java | 70 ++++ .../v2_0/features/ImageApiExpectTest.java | 285 ++++++++++++++++ .../v2_0/features/ServerApiExpectTest.java | 307 ++++++++++++++++++ .../v2_0/parse/ParseMetadataItemTest.java | 60 ++++ .../v2_0/parse/ParseMetadataListTest.java | 65 ++++ .../v2_0/parse/ParseMetadataUpdateTest.java | 66 ++++ .../src/test/resources/metadata_item.json | 5 + .../src/test/resources/metadata_list.json | 6 + .../src/test/resources/metadata_updated.json | 7 + 12 files changed, 1080 insertions(+) create mode 100644 apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataItemTest.java create mode 100644 apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataListTest.java create mode 100644 apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataUpdateTest.java create mode 100644 apis/openstack-nova/src/test/resources/metadata_item.json create mode 100644 apis/openstack-nova/src/test/resources/metadata_list.json create mode 100644 apis/openstack-nova/src/test/resources/metadata_updated.json diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java index a6ccf4d17b..24dee30e05 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java @@ -18,6 +18,7 @@ */ package org.jclouds.openstack.nova.v2_0.features; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.jclouds.collect.PagedIterable; @@ -75,5 +76,71 @@ public interface ImageApi { * @return server or null if not found */ void delete(String id); + + /** + * List all metadata for an image. + * + * @param id + * id of the image + * @return the metadata as a Map + */ + Map listMetadata(String id); + + /** + * Sets the metadata for an image. + * + * @param id + * id of the image + * @param metadata + * a Map containing the metadata + * @return the metadata as a Map + */ + Map setMetadata(String id, Map metadata); + + /** + * Update the metadata for a server. + * + * @param id + * id of the image + * @param metadata + * a Map containing the metadata + * @return the metadata as a Map + */ + Map updateMetadata(String id, Map metadata); + + /** + * Update the metadata for an image. + * + * @param id + * id of the image + * @param metadata + * a Map containing the metadata + * @return the metadata as a Map + */ + Map getMetadataItem(String id, String key); + + + /** + * Set a metadata item for an image. + * + * @param id + * id of the image + * @param key + * the name of the metadata item + * @param value + * the value of the metadata item + * @return the metadata as a Map + */ + Map setMetadataItem(String id, String key, String value); + + /** + * Delete a metadata item from an image. + * + * @param id + * id of the image + * @param key + * the name of the metadata item + */ + void deleteMetadataItem(String id, String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java index c68fb74149..79dfef9f8a 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java @@ -18,11 +18,16 @@ */ package org.jclouds.openstack.nova.v2_0.features; +import java.util.Map; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.collect.PagedIterable; @@ -35,11 +40,16 @@ import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages; import org.jclouds.openstack.v2_0.domain.Resource; import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; +import org.jclouds.rest.binders.BindToJsonPayload; +import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; @@ -117,5 +127,70 @@ public interface ImageAsyncApi { @Path("/images/{id}") @ExceptionParser(ReturnVoidOnNotFoundOr404.class) ListenableFuture delete(@PathParam("id") String id); + + /** + * @see ImageApi#listMetadata + */ + @GET + @SelectJson("metadata") + @Path("/images/{id}/metadata") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + ListenableFuture> listMetadata(@PathParam("id") String id); + /** + * @see ImageApi#setMetadata + */ + @PUT + @SelectJson("metadata") + @Path("/images/{id}/metadata") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + @MapBinder(BindToJsonPayload.class) + ListenableFuture> setMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); + + /** + * @see ImageApi#updateMetadata + */ + @POST + @SelectJson("metadata") + @Path("/images/{id}/metadata") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + @MapBinder(BindToJsonPayload.class) + ListenableFuture> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); + + /** + * @see ImageApi#getMetadataItem + */ + @GET + @SelectJson("metadata") + @Path("/images/{id}/metadata/{key}") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + + /** + * @see ImageApi#setMetadataItem + */ + @PUT + @SelectJson("metadata") + @Path("/images/{id}/metadata/{key}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + @Payload("%7B\"metadata\":%7B\"{key}\":\"{value}\"%7D%7D") + ListenableFuture> setMetadataItem(@PathParam("id") String id, @PathParam("key") String key, @PathParam("value") String value); + + + /** + * @see ImageApi#deleteMetadataItem + */ + @DELETE + @Consumes + @Path("/images/{id}/metadata/{key}") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture deleteMetadataItem(@PathParam("id") String id, @PathParam("key") String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java index 6e95bf39e1..f8454004a3 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java @@ -18,6 +18,7 @@ */ package org.jclouds.openstack.nova.v2_0.features; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.jclouds.collect.PagedIterable; @@ -191,5 +192,71 @@ public interface ServerApi { * @return ID of the new / updated image */ String createImageFromServer(String name, String id); + + /** + * List all metadata for a server. + * + * @param id + * id of the server + * + * @return the metadata as a Map + */ + Map listMetadata(String id); + + /** + * Set the metadata for a server. + * + * @param id + * id of the server + * @param metadata + * a Map containing the metadata + * @return the metadata as a Map + */ + Map setMetadata(String id, Map metadata); + + /** + * Update the metadata for a server. + * + * @param id + * id of the server + * @param metadata + * a Map containing the metadata + * @return the metadata as a Map + */ + Map updateMetadata(String id, Map metadata); + + /** + * Update the metadata for a server. + * + * @param id + * id of the image + * @param metadata + * a Map containing the metadata + * @return the metadata as a Map + */ + Map getMetadataItem(String id, String key); + + /** + * Set a metadata item for a server. + * + * @param id + * id of the image + * @param key + * the name of the metadata item + * @param value + * the value of the metadata item + * @return the metadata as a Map + */ + Map setMetadataItem(String id, String key, String value); + + /** + * Delete a metadata item from a server. + * + * @param id + * id of the image + * @param key + * the name of the metadata item + */ + void deleteMetadataItem(String id, String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java index 848a57ddeb..e58e879baf 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java @@ -18,6 +18,8 @@ */ package org.jclouds.openstack.nova.v2_0.features; +import java.util.Map; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -52,10 +54,13 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.Unwrap; +import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; +import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -247,4 +252,69 @@ public interface ServerAsyncApi { @ResponseParser(ParseImageIdFromLocationHeader.class) ListenableFuture createImageFromServer(@PayloadParam("name") String name, @PathParam("id") String id); + /** + * @see ServerApi#listMetadata + */ + @GET + @SelectJson("metadata") + @Path("/servers/{id}/metadata") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + ListenableFuture> listMetadata(@PathParam("id") String id); + + /** + * @see ServerApi#setMetadata + */ + @PUT + @SelectJson("metadata") + @Path("/servers/{id}/metadata") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + @MapBinder(BindToJsonPayload.class) + ListenableFuture> setMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); + + /** + * @see ServerApi#updateMetadata + */ + @POST + @SelectJson("metadata") + @Path("/servers/{id}/metadata") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + @MapBinder(BindToJsonPayload.class) + ListenableFuture> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); + + /** + * @see ServerApi#getMetadataItem + */ + @GET + @SelectJson("metadata") + @Path("/servers/{id}/metadata/{key}") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + + /** + * @see ServerApi#setMetadataItem + */ + @PUT + @SelectJson("metadata") + @Path("/servers/{id}/metadata/{key}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) + @Payload("%7B\"metadata\":%7B\"{key}\":\"{value}\"%7D%7D") + ListenableFuture> setMetadataItem(@PathParam("id") String id, @PathParam("key") String key, @PathParam("value") String value); + + /** + * @see ServerApi#deleteMetadataItem + */ + @DELETE + @Consumes + @Path("/servers/{id}/metadata/{key}") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture deleteMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java index 705cf2a280..aea70f0496 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java @@ -21,6 +21,7 @@ package org.jclouds.openstack.nova.v2_0.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -28,8 +29,11 @@ import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; import org.jclouds.openstack.nova.v2_0.parse.ParseImageListTest; import org.jclouds.openstack.nova.v2_0.parse.ParseImageTest; +import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest; +import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; /** @@ -113,4 +117,285 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { } + public void testListMetadataWhenResponseIs2xx() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + HttpRequest listMetadata = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken).build(); + + HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_list.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, listMetadata, listMetadataResponse); + + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").listMetadata(imageId).toString(), + new ParseMetadataListTest().expected().toString()); + } + + public void testListMetadataWhenResponseIs404() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + HttpRequest listMetadata = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata") + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, listMetadata, listMetadataResponse); + + try { + apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").listMetadata(imageId); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testSetMetadataWhenResponseIs2xx() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 1") + .put("Image Version", "2.1") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("PUT") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 1\",\"Image Version\":\"2.1\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_list.json")).build(); + + NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + assertEquals(apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").setMetadata(imageId, metadata).toString(), + new ParseMetadataListTest().expected().toString()); + } + + public void testSetMetadataWhenResponseIs404() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 1") + .put("Image Version", "2.1") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("PUT") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" +imageId + "/metadata") + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 1\",\"Image Version\":\"2.1\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + try { + apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadata(imageId, metadata); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testUpdateMetadataWhenResponseIs2xx() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Server Description", "Simple Server") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("POST") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + imageId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").updateMetadata(imageId, metadata).toString(), + new ParseMetadataUpdateTest().expected().toString()); + } + + public void testUpdateMetadataWhenResponseIs404() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Server Description", "Simple Server") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("POST") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + imageId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + try { + apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadata(imageId, metadata); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testGetMetadataItemWhenResponseIs2xx() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + String key = "Image%20Version"; + + HttpRequest getMetadataItem = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse getMetadataItemResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromString("{\"metadata\":{\"Image Version\":\"2.5\"}}")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, getMetadataItem, getMetadataItemResponse); + + System.out.println(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, "Image Version").toString()); + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, "Image Version").toString(), + "{Image Version=2.5}"); + } + + public void testGetMetadataItemWhenResponseIs404() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + String key = "Image%20Version"; + + HttpRequest getMetadata = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(404) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")).build(); + + NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, getMetadata, getMetadataResponse); + + assertNull(apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, key)); + } + + public void testSetMetadataItemWhenResponseIs2xx() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + String key = "Image%20Version"; + + HttpRequest setMetadataItem = HttpRequest + .builder() + .method("PUT") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")) + .build(); + + HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse); + + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadataItem(imageId, key, "2.5").toString(), + "Image Version=2.5"); + } + + public void testSetMetadataItemWhenResponseIs404() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + String key = "Image%20Version"; + + HttpRequest setMetadataItem = HttpRequest + .builder() + .method("PUT") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse); + + assertNull(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadataItem(imageId, key, "2.5")); + + } + + public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + String key = "Image%20Version"; + + HttpRequest deleteMetadataItem = HttpRequest + .builder() + .method("DELETE") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(204).build(); + + NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse); + + apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadataItem(imageId, key); + } + + public void testDeleteMetadataItemWhenResponseIs404() throws Exception { + String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; + String key = "Image%20Version"; + + HttpRequest deleteMetadataItem = HttpRequest + .builder() + .method("DELETE") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse); + + apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadataItem(imageId, key); + + } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java index 967aeea409..0292c75e4d 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java @@ -28,9 +28,13 @@ import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest; +import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataItemTest; +import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest; +import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest; import org.jclouds.openstack.nova.v2_0.parse.ParseServerListTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; @@ -271,4 +275,307 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { } } + public void testListMetadataWhenResponseIs2xx() throws Exception { + String serverId = "123"; + + HttpRequest listMetadata = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken).build(); + + HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_list.json")).build(); + + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, listMetadata, listMetadataResponse); + + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").listMetadata(serverId).toString(), + new ParseMetadataListTest().expected().toString()); + } + + public void testListMetadataWhenResponseIs404() throws Exception { + String serverId = "123"; + HttpRequest listMetadata = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, listMetadata, listMetadataResponse); + + try { + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").listMetadata(serverId); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testSetMetadataWhenResponseIs2xx() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 1") + .put("Image Version", "2.1") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("PUT") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 1\",\"Image Version\":\"2.1\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_list.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").setMetadata(serverId, metadata).toString(), + new ParseMetadataListTest().expected().toString()); + } + + public void testSetMetadataWhenResponseIs404() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 1") + .put("Image Version", "2.1") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("PUT") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 1\",\"Image Version\":\"2.1\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + try { + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").setMetadata(serverId, metadata); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testUpdateMetadataWhenResponseIs2xx() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Server Description", "Simple Server") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("POST") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").updateMetadata(serverId, metadata).toString(), + new ParseMetadataUpdateTest().expected().toString()); + } + + public void testUpdateMetadataWhenResponseIs404() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Server Description", "Simple Server") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("POST") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + try { + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").setMetadata(serverId, metadata); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testGetMetadataItemWhenResponseIs2xx() throws Exception { + String serverId = "123"; + String key = "Server%20Label"; + + HttpRequest getMetadataItem = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key) + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse getMetadataItemResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_item.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, getMetadataItem, getMetadataItemResponse); + + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadataItem(serverId, "Server Label").toString(), + new ParseMetadataItemTest().expected().toString()); + } + + public void testGetMetadataItemWhenResponseIs404() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 1") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + try { + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").setMetadata(serverId, metadata); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testSetMetadataItemWhenResponseIs2xx() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Server Description", "Simple Server") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("POST") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").updateMetadata(serverId, metadata).toString(), + new ParseMetadataUpdateTest().expected().toString()); + } + + public void testSetMetadataItemWhenResponseIs404() throws Exception { + String serverId = "123"; + ImmutableMap metadata = new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Server Description", "Simple Server") + .build(); + + HttpRequest setMetadata = HttpRequest + .builder() + .method("POST") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken) + .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) + .build(); + + HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404) + .payload(payloadFromResource("/metadata_updated.json")).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadata, setMetadataResponse); + + try { + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").setMetadata(serverId, metadata); + fail("Expected an exception."); + } catch (Exception e) { + ; + } + } + + public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception { + String serverId = "123"; + String key = "Server%20Label"; + + HttpRequest setMetadataItem = HttpRequest + .builder() + .method("DELETE") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key) + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(204).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse); + + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadataItem(serverId, key); + + } + + public void testDeleteMetadataItemWhenResponseIs404() throws Exception { + String serverId = "123"; + String key = "Server%20Label"; + + HttpRequest deleteMetadataItem = HttpRequest + .builder() + .method("DELETE") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key) + .addHeader("Accept", "*/*") + .addHeader("X-Auth-Token", authToken) + .build(); + + HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse); + + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadataItem(serverId, key); + + } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataItemTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataItemTest.java new file mode 100644 index 0000000000..d99709a879 --- /dev/null +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataItemTest.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.parse; + +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.openstack.nova.v2_0.config.NovaParserModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "ParseMetadataItemTest") +public class ParseMetadataItemTest extends BaseItemParserTest> { + + @Override + public String resource() { + return "/metadata_item.json"; + } + + @Override + @SelectJson("metadata") + @Consumes(MediaType.APPLICATION_JSON) + public Map expected() { + ImmutableMap metadata = ImmutableMap.of("Server Label", "Web Head 1"); + return metadata; + } + + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } + +} diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataListTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataListTest.java new file mode 100644 index 0000000000..db195fcf23 --- /dev/null +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataListTest.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.parse; + +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.openstack.nova.v2_0.config.NovaParserModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "ParseMetadataListTest") +public class ParseMetadataListTest extends BaseItemParserTest> { + + @Override + public String resource() { + return "/metadata_list.json"; + } + + @Override + @SelectJson("metadata") + @Consumes(MediaType.APPLICATION_JSON) + public Map expected() { + ImmutableMap metadata = + new ImmutableMap.Builder() + .put("Server Label", "Web Head 1") + .put("Image Version", "2.1") + .build(); + + return metadata; + } + + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } + +} diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataUpdateTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataUpdateTest.java new file mode 100644 index 0000000000..dc08093ab2 --- /dev/null +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseMetadataUpdateTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.parse; + +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.openstack.nova.v2_0.config.NovaParserModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "ParseMetadataUpdateTest") +public class ParseMetadataUpdateTest extends BaseItemParserTest> { + + @Override + public String resource() { + return "/metadata_updated.json"; + } + + @Override + @SelectJson("metadata") + @Consumes(MediaType.APPLICATION_JSON) + public Map expected() { + ImmutableMap metadata = + new ImmutableMap.Builder() + .put("Server Label", "Web Head 2") + .put("Image Version", "2.1") + .put("Server Description", "Simple Server") + .build(); + + return metadata; + } + + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } + +} diff --git a/apis/openstack-nova/src/test/resources/metadata_item.json b/apis/openstack-nova/src/test/resources/metadata_item.json new file mode 100644 index 0000000000..f853109c10 --- /dev/null +++ b/apis/openstack-nova/src/test/resources/metadata_item.json @@ -0,0 +1,5 @@ +{ + "metadata": { + "Server Label": "Web Head 1" + } +} \ No newline at end of file diff --git a/apis/openstack-nova/src/test/resources/metadata_list.json b/apis/openstack-nova/src/test/resources/metadata_list.json new file mode 100644 index 0000000000..174d7d60be --- /dev/null +++ b/apis/openstack-nova/src/test/resources/metadata_list.json @@ -0,0 +1,6 @@ +{ + "metadata": { + "Server Label": "Web Head 1", + "Image Version": "2.1" + } +} \ No newline at end of file diff --git a/apis/openstack-nova/src/test/resources/metadata_updated.json b/apis/openstack-nova/src/test/resources/metadata_updated.json new file mode 100644 index 0000000000..82d9fd3ac9 --- /dev/null +++ b/apis/openstack-nova/src/test/resources/metadata_updated.json @@ -0,0 +1,7 @@ +{ + "metadata": { + "Server Label": "Web Head 2", + "Image Version": "2.1", + "Server Description": "Simple Server" + } +} \ No newline at end of file From 605d6580de92a603f42c5e3d18081aa2ad2f61ae Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 17:07:42 -0700 Subject: [PATCH 51/60] metadata for nova --- .../binders/BindMetadataToJsonPayload.java | 49 +++++++++++ .../openstack/nova/v2_0/domain/Quota.java | 6 +- .../nova/v2_0/features/ImageApi.java | 14 ++-- .../nova/v2_0/features/ImageAsyncApi.java | 27 +++--- .../nova/v2_0/features/ServerApi.java | 14 ++-- .../nova/v2_0/features/ServerAsyncApi.java | 56 +++++++------ .../internal/OnlyMetadataValueOrNull.java | 65 +++++++++++++++ .../v2_0/extensions/QuotaApiLiveTest.java | 2 +- .../v2_0/features/ImageApiExpectTest.java | 82 +++++++------------ .../v2_0/features/ServerApiExpectTest.java | 47 ++++++----- 10 files changed, 230 insertions(+), 132 deletions(-) create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/binders/BindMetadataToJsonPayload.java create mode 100644 apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/OnlyMetadataValueOrNull.java diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/binders/BindMetadataToJsonPayload.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/binders/BindMetadataToJsonPayload.java new file mode 100644 index 0000000000..7030261e04 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/binders/BindMetadataToJsonPayload.java @@ -0,0 +1,49 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.binders; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rest.binders.BindToJsonPayload; + +import com.google.common.collect.ImmutableMap; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindMetadataToJsonPayload extends BindToJsonPayload { + + @Inject + public BindMetadataToJsonPayload(Json jsonBinder) { + super(jsonBinder); + } + + @Override + public R bindToRequest(R request, Map postParams) { + return bindToRequest(request, + (Object) ImmutableMap.of("metadata", ImmutableMap.of(postParams.get("key"), postParams.get("value")))); + } +} \ No newline at end of file diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java index 6915511377..f52c13708e 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quota.java @@ -68,7 +68,7 @@ public class Quota { } /** - * @see Quota#getMetadataItems() + * @see Quota#getMetadatas() */ public T metadataItems(int metadataItems) { this.metadataItems = metadataItems; @@ -170,7 +170,7 @@ public class Quota { public T fromQuotas(Quota in) { return this .id(in.getId()) - .metadataItems(in.getMetadataItems()) + .metadataItems(in.getMetadatas()) .injectedFileContentBytes(in.getInjectedFileContentBytes()) .volumes(in.getVolumes()) .gigabytes(in.getGigabytes()) @@ -242,7 +242,7 @@ public class Quota { /** * The limit of the number of metadata items for the tenant */ - public int getMetadataItems() { + public int getMetadatas() { return this.metadataItems; } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java index 24dee30e05..5afb755fee 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageApi.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.nova.v2_0.domain.Image; import org.jclouds.openstack.v2_0.domain.Resource; @@ -84,7 +85,7 @@ public interface ImageApi { * id of the image * @return the metadata as a Map */ - Map listMetadata(String id); + Map getMetadata(String id); /** * Sets the metadata for an image. @@ -115,9 +116,10 @@ public interface ImageApi { * id of the image * @param metadata * a Map containing the metadata - * @return the metadata as a Map + * @return the value or null if not present */ - Map getMetadataItem(String id, String key); + @Nullable + String getMetadata(String id, String key); /** @@ -129,9 +131,9 @@ public interface ImageApi { * the name of the metadata item * @param value * the value of the metadata item - * @return the metadata as a Map + * @return the value you updated */ - Map setMetadataItem(String id, String key, String value); + String updateMetadata(String id, String key, String value); /** * Delete a metadata item from an image. @@ -141,6 +143,6 @@ public interface ImageApi { * @param key * the name of the metadata item */ - void deleteMetadataItem(String id, String key); + void deleteMetadata(String id, String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java index 79dfef9f8a..0d69ab3402 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ImageAsyncApi.java @@ -34,14 +34,15 @@ import org.jclouds.collect.PagedIterable; import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; +import org.jclouds.openstack.nova.v2_0.binders.BindMetadataToJsonPayload; import org.jclouds.openstack.nova.v2_0.domain.Image; +import org.jclouds.openstack.nova.v2_0.functions.internal.OnlyMetadataValueOrNull; import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImageDetails; import org.jclouds.openstack.nova.v2_0.functions.internal.ParseImages; import org.jclouds.openstack.v2_0.domain.Resource; import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; @@ -129,14 +130,14 @@ public interface ImageAsyncApi { ListenableFuture delete(@PathParam("id") String id); /** - * @see ImageApi#listMetadata + * @see ImageApi#getMetadata */ @GET @SelectJson("metadata") @Path("/images/{id}/metadata") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) - ListenableFuture> listMetadata(@PathParam("id") String id); + ListenableFuture> getMetadata(@PathParam("id") String id); /** * @see ImageApi#setMetadata @@ -163,34 +164,34 @@ public interface ImageAsyncApi { ListenableFuture> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); /** - * @see ImageApi#getMetadataItem + * @see ImageApi#getMetadata */ @GET - @SelectJson("metadata") @Path("/images/{id}/metadata/{key}") @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(OnlyMetadataValueOrNull.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture> getMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + ListenableFuture getMetadata(@PathParam("id") String id, @PathParam("key") String key); /** - * @see ImageApi#setMetadataItem + * @see ImageApi#updateMetadata */ @PUT - @SelectJson("metadata") @Path("/images/{id}/metadata/{key}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) - @Payload("%7B\"metadata\":%7B\"{key}\":\"{value}\"%7D%7D") - ListenableFuture> setMetadataItem(@PathParam("id") String id, @PathParam("key") String key, @PathParam("value") String value); + @ResponseParser(OnlyMetadataValueOrNull.class) + @MapBinder(BindMetadataToJsonPayload.class) + ListenableFuture updateMetadata(@PathParam("id") String id, + @PathParam("key") @PayloadParam("key") String key, @PathParam("value") @PayloadParam("value") String value); /** - * @see ImageApi#deleteMetadataItem + * @see ImageApi#deleteMetadata */ @DELETE @Consumes @Path("/images/{id}/metadata/{key}") @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - ListenableFuture deleteMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + ListenableFuture deleteMetadata(@PathParam("id") String id, @PathParam("key") String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java index f8454004a3..f7ea8b251d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerApi.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.collect.PagedIterable; import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.nova.v2_0.domain.RebootType; import org.jclouds.openstack.nova.v2_0.domain.Server; @@ -201,7 +202,7 @@ public interface ServerApi { * * @return the metadata as a Map */ - Map listMetadata(String id); + Map getMetadata(String id); /** * Set the metadata for a server. @@ -232,9 +233,10 @@ public interface ServerApi { * id of the image * @param metadata * a Map containing the metadata - * @return the metadata as a Map + * @return the value or null if not present */ - Map getMetadataItem(String id, String key); + @Nullable + String getMetadata(String id, String key); /** * Set a metadata item for a server. @@ -245,9 +247,9 @@ public interface ServerApi { * the name of the metadata item * @param value * the value of the metadata item - * @return the metadata as a Map + * @return the value you updated */ - Map setMetadataItem(String id, String key, String value); + String updateMetadata(String id, String key, String value); /** * Delete a metadata item from a server. @@ -257,6 +259,6 @@ public interface ServerApi { * @param key * the name of the metadata item */ - void deleteMetadataItem(String id, String key); + void deleteMetadata(String id, String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java index e58e879baf..ef3070728b 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/features/ServerAsyncApi.java @@ -34,10 +34,12 @@ import org.jclouds.collect.PagedIterable; import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404; +import org.jclouds.openstack.nova.v2_0.binders.BindMetadataToJsonPayload; import org.jclouds.openstack.nova.v2_0.domain.RebootType; import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.nova.v2_0.domain.ServerCreated; import org.jclouds.openstack.nova.v2_0.functions.ParseImageIdFromLocationHeader; +import org.jclouds.openstack.nova.v2_0.functions.internal.OnlyMetadataValueOrNull; import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServerDetails; import org.jclouds.openstack.nova.v2_0.functions.internal.ParseServers; import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; @@ -69,8 +71,7 @@ import com.google.common.util.concurrent.ListenableFuture; *

* * @see ServerApi - * @see * @author Adrian Cole */ @@ -120,7 +121,6 @@ public interface ServerAsyncApi { @ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class) ListenableFuture> listInDetail(PaginationOptions options); - /** * @see ServerApi#get */ @@ -159,7 +159,7 @@ public interface ServerAsyncApi { @Produces(MediaType.APPLICATION_JSON) @Payload("{\"os-stop\":null}") ListenableFuture stop(@PathParam("id") String id); - + /** * @see ServerApi#reboot */ @@ -209,7 +209,7 @@ public interface ServerAsyncApi { @Path("/servers") @MapBinder(CreateServerOptions.class) ListenableFuture create(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef, - @PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options); + @PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options); /** * @see ServerApi#rebuild @@ -253,15 +253,15 @@ public interface ServerAsyncApi { ListenableFuture createImageFromServer(@PayloadParam("name") String name, @PathParam("id") String id); /** - * @see ServerApi#listMetadata + * @see ServerApi#getMetadata */ @GET @SelectJson("metadata") @Path("/servers/{id}/metadata") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) - ListenableFuture> listMetadata(@PathParam("id") String id); - + ListenableFuture> getMetadata(@PathParam("id") String id); + /** * @see ServerApi#setMetadata */ @@ -272,7 +272,8 @@ public interface ServerAsyncApi { @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) @MapBinder(BindToJsonPayload.class) - ListenableFuture> setMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); + ListenableFuture> setMetadata(@PathParam("id") String id, + @PayloadParam("metadata") Map metadata); /** * @see ServerApi#updateMetadata @@ -284,37 +285,38 @@ public interface ServerAsyncApi { @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) @MapBinder(BindToJsonPayload.class) - ListenableFuture> updateMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map metadata); - - /** - * @see ServerApi#getMetadataItem - */ - @GET - @SelectJson("metadata") - @Path("/servers/{id}/metadata/{key}") - @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture> getMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + ListenableFuture> updateMetadata(@PathParam("id") String id, + @PayloadParam("metadata") Map metadata); /** - * @see ServerApi#setMetadataItem + * @see ServerApi#getMetadata + */ + @GET + @Path("/servers/{id}/metadata/{key}") + @Consumes(MediaType.APPLICATION_JSON) + @ResponseParser(OnlyMetadataValueOrNull.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getMetadata(@PathParam("id") String id, @PathParam("key") String key); + + /** + * @see ServerApi#updateMetadata */ @PUT - @SelectJson("metadata") @Path("/servers/{id}/metadata/{key}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class) - @Payload("%7B\"metadata\":%7B\"{key}\":\"{value}\"%7D%7D") - ListenableFuture> setMetadataItem(@PathParam("id") String id, @PathParam("key") String key, @PathParam("value") String value); + @ResponseParser(OnlyMetadataValueOrNull.class) + @MapBinder(BindMetadataToJsonPayload.class) + ListenableFuture updateMetadata(@PathParam("id") String id, + @PathParam("key") @PayloadParam("key") String key, @PathParam("value") @PayloadParam("value") String value); /** - * @see ServerApi#deleteMetadataItem + * @see ServerApi#deleteMetadata */ @DELETE @Consumes @Path("/servers/{id}/metadata/{key}") @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - ListenableFuture deleteMetadataItem(@PathParam("id") String id, @PathParam("key") String key); + ListenableFuture deleteMetadata(@PathParam("id") String id, @PathParam("key") String key); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/OnlyMetadataValueOrNull.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/OnlyMetadataValueOrNull.java new file mode 100644 index 0000000000..d00c2e7ea6 --- /dev/null +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/functions/internal/OnlyMetadataValueOrNull.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.v2_0.functions.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.internal.GsonWrapper; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class OnlyMetadataValueOrNull implements Function { + private final ParseJson parser; + + private static class Wrapper implements Supplier { + private Map metadata; + + @Override + public String get() { + return metadata == null ? null : Iterables.get(metadata.values(), 0, null); + } + + } + + @Inject + public OnlyMetadataValueOrNull(GsonWrapper gsonView) { + this.parser = new ParseJson(checkNotNull(gsonView, "gsonView"), new TypeLiteral() { + }); + } + + public String apply(HttpResponse response) { + checkNotNull(response, "response"); + return parser.apply(response).get(); + } +} diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java index ec771e4a52..2cb2bb2412 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java @@ -71,7 +71,7 @@ public class QuotaApiLiveTest extends BaseNovaApiLiveTest { Quota modified = before.toBuilder() .cores(before.getCores() - 1) .instances(before.getInstances() - 1) - .metadataItems(before.getMetadataItems() - 1) + .metadataItems(before.getMetadatas() - 1) .ram(before.getRam() - 1) .volumes(before.getVolumes() - 1) .build(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java index aea70f0496..81b8403713 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java @@ -119,26 +119,26 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { public void testListMetadataWhenResponseIs2xx() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - HttpRequest listMetadata = HttpRequest + HttpRequest getMetadata = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(200) + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/metadata_list.json")).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, listMetadata, listMetadataResponse); + responseWithKeystoneAccess, getMetadata, getMetadataResponse); - assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").listMetadata(imageId).toString(), + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId).toString(), new ParseMetadataListTest().expected().toString()); } public void testListMetadataWhenResponseIs404() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - HttpRequest listMetadata = HttpRequest + HttpRequest getMetadata = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata") @@ -146,13 +146,13 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, listMetadata, listMetadataResponse); + responseWithKeystoneAccess, getMetadata, getMetadataResponse); try { - apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").listMetadata(imageId); + apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId); fail("Expected an exception."); } catch (Exception e) { ; @@ -224,7 +224,7 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { HttpRequest setMetadata = HttpRequest .builder() .method("POST") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + imageId + "/metadata") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .payload(payloadFromStringWithContentType("{\"metadata\":{\"Server Label\":\"Web Head 2\",\"Server Description\":\"Simple Server\"}}","application/json")) @@ -274,7 +274,7 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; String key = "Image%20Version"; - HttpRequest getMetadataItem = HttpRequest + HttpRequest getMetadata = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) @@ -282,15 +282,14 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse getMetadataItemResponse = HttpResponse.builder().statusCode(200) + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromString("{\"metadata\":{\"Image Version\":\"2.5\"}}")).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, getMetadataItem, getMetadataItemResponse); + responseWithKeystoneAccess, getMetadata, getMetadataResponse); - System.out.println(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, "Image Version").toString()); - assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, "Image Version").toString(), - "{Image Version=2.5}"); + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId, "Image Version").toString(), + "2.5"); } public void testGetMetadataItemWhenResponseIs404() throws Exception { @@ -311,58 +310,37 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, getMetadata, getMetadataResponse); - assertNull(apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").getMetadataItem(imageId, key)); + assertNull(apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").getMetadata(imageId, key)); } public void testSetMetadataItemWhenResponseIs2xx() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - String key = "Image%20Version"; + String key = "Image Version"; - HttpRequest setMetadataItem = HttpRequest + HttpRequest updateMetadata = HttpRequest .builder() .method("PUT") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + "Image%20Version") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")) .build(); - HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(200) + HttpResponse updateMetadataResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType("{\"metadata\":{\"Image Version\":\"2.5\"}}", "application/json")).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse); + responseWithKeystoneAccess, updateMetadata, updateMetadataResponse); - assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadataItem(imageId, key, "2.5").toString(), - "Image Version=2.5"); - } - - public void testSetMetadataItemWhenResponseIs404() throws Exception { - String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - String key = "Image%20Version"; - - HttpRequest setMetadataItem = HttpRequest - .builder() - .method("PUT") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) - .addHeader("Accept", "application/json") - .addHeader("X-Auth-Token", authToken) - .build(); - - HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(404).build(); - - NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse); - - assertNull(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").setMetadataItem(imageId, key, "2.5")); - + assertEquals(apiWhenServerExists.getImageApiForZone("az-1.region-a.geo-1").updateMetadata(imageId, key, "2.5").toString(), + "2.5"); } public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; String key = "Image%20Version"; - HttpRequest deleteMetadataItem = HttpRequest + HttpRequest deleteMetadata = HttpRequest .builder() .method("DELETE") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) @@ -370,19 +348,19 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(204).build(); + HttpResponse deleteMetadataResponse = HttpResponse.builder().statusCode(204).build(); NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse); + responseWithKeystoneAccess, deleteMetadata, deleteMetadataResponse); - apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadataItem(imageId, key); + apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadata(imageId, key); } public void testDeleteMetadataItemWhenResponseIs404() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; String key = "Image%20Version"; - HttpRequest deleteMetadataItem = HttpRequest + HttpRequest deleteMetadata = HttpRequest .builder() .method("DELETE") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/images/" + imageId + "/metadata/" + key) @@ -390,12 +368,12 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse deleteMetadataResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenImageExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse); + responseWithKeystoneAccess, deleteMetadata, deleteMetadataResponse); - apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadataItem(imageId, key); + apiWhenImageExists.getImageApiForZone("az-1.region-a.geo-1").deleteMetadata(imageId, key); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java index 0292c75e4d..dde200258b 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java @@ -28,7 +28,6 @@ import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest; -import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataItemTest; import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest; import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest; import org.jclouds.openstack.nova.v2_0.parse.ParseServerListTest; @@ -278,27 +277,27 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { public void testListMetadataWhenResponseIs2xx() throws Exception { String serverId = "123"; - HttpRequest listMetadata = HttpRequest + HttpRequest getMetadata = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken).build(); - HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(200) + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/metadata_list.json")).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, listMetadata, listMetadataResponse); + responseWithKeystoneAccess, getMetadata, getMetadataResponse); - assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").listMetadata(serverId).toString(), + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadata(serverId).toString(), new ParseMetadataListTest().expected().toString()); } public void testListMetadataWhenResponseIs404() throws Exception { String serverId = "123"; - HttpRequest listMetadata = HttpRequest + HttpRequest getMetadata = HttpRequest .builder() .method("GET") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata") @@ -306,13 +305,13 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse listMetadataResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, listMetadata, listMetadataResponse); + responseWithKeystoneAccess, getMetadata, getMetadataResponse); try { - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").listMetadata(serverId); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadata(serverId); fail("Expected an exception."); } catch (Exception e) { ; @@ -432,24 +431,24 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { public void testGetMetadataItemWhenResponseIs2xx() throws Exception { String serverId = "123"; - String key = "Server%20Label"; + String key = "Server Label"; - HttpRequest getMetadataItem = HttpRequest + HttpRequest getMetadata = HttpRequest .builder() .method("GET") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + "Server%20Label") .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse getMetadataItemResponse = HttpResponse.builder().statusCode(200) + HttpResponse getMetadataResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/metadata_item.json")).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, getMetadataItem, getMetadataItemResponse); + responseWithKeystoneAccess, getMetadata, getMetadataResponse); - assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadataItem(serverId, "Server Label").toString(), - new ParseMetadataItemTest().expected().toString()); + assertEquals(apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").getMetadata(serverId, key).toString(), + "Web Head 1"); } public void testGetMetadataItemWhenResponseIs404() throws Exception { @@ -541,7 +540,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { String serverId = "123"; String key = "Server%20Label"; - HttpRequest setMetadataItem = HttpRequest + HttpRequest updateMetadata = HttpRequest .builder() .method("DELETE") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key) @@ -549,12 +548,12 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse setMetadataItemResponse = HttpResponse.builder().statusCode(204).build(); + HttpResponse updateMetadataResponse = HttpResponse.builder().statusCode(204).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, setMetadataItem, setMetadataItemResponse); + responseWithKeystoneAccess, updateMetadata, updateMetadataResponse); - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadataItem(serverId, key); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadata(serverId, key); } @@ -562,7 +561,7 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { String serverId = "123"; String key = "Server%20Label"; - HttpRequest deleteMetadataItem = HttpRequest + HttpRequest deleteMetadata = HttpRequest .builder() .method("DELETE") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/metadata/" + key) @@ -570,12 +569,12 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .build(); - HttpResponse deleteMetadataItemResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse deleteMetadataResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, deleteMetadataItem, deleteMetadataItemResponse); + responseWithKeystoneAccess, deleteMetadata, deleteMetadataResponse); - apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadataItem(serverId, key); + apiWhenServerExists.getServerApiForZone("az-1.region-a.geo-1").deleteMetadata(serverId, key); } } From 26016fde77f7e1f58de94df6d74ae8c439aecfb8 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 18:38:42 -0700 Subject: [PATCH 52/60] updated notice file --- resources/NOTICE.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/resources/NOTICE.txt b/resources/NOTICE.txt index b0a56c74b6..ab77979e5b 100644 --- a/resources/NOTICE.txt +++ b/resources/NOTICE.txt @@ -64,3 +64,9 @@ distributed in the Public Domain This product includes software developed at Hewlett-Packard Copyright (c) 2011-2012 Hewlett-Packard Development Company, L.P +This product includes software developed at Cloudsoft +Copyright (c) 2011-2012 Cloudsoft Corporation, Ltd. + +This product includes software developed at MuleSoft +Copyright (c) 2012 MuleSoft Inc. + From 8ca0dc3c1d9bdf888a6a6d59fd3fcd280d37fc2a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 21:28:51 -0700 Subject: [PATCH 53/60] better error reporting --- .../compute/internal/BaseComputeServiceLiveTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java index 376119578e..0f26611a3f 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java @@ -348,8 +348,8 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte // credentials aren't always the same // assertEquals(node1.getCredentials(), node2.getCredentials()); - assertLocationSameOrChild(node1.getLocation(), template.getLocation()); - assertLocationSameOrChild(node2.getLocation(), template.getLocation()); + assertLocationSameOrChild(checkNotNull(node1.getLocation(), "location of %s", node1), template.getLocation()); + assertLocationSameOrChild(checkNotNull(node2.getLocation(), "location of %s", node2), template.getLocation()); checkImageIdMatchesTemplate(node1); checkImageIdMatchesTemplate(node2); checkOsMatchesTemplate(node1); @@ -411,7 +411,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte if (existingLocationIsAssignable) assertEquals(node.getLocation(), existingLocation); else - this.assertLocationSameOrChild(node.getLocation(), template.getLocation()); + this.assertLocationSameOrChild(checkNotNull(node.getLocation(), "location of %s", node), template.getLocation()); checkOsMatchesTemplate(node); this.nodes.add(node); } @@ -502,7 +502,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte NodeMetadata metadata = client.getNodeMetadata(node.getId()); assertEquals(metadata.getProviderId(), node.getProviderId()); assertEquals(metadata.getGroup(), node.getGroup()); - assertLocationSameOrChild(metadata.getLocation(), template.getLocation()); + assertLocationSameOrChild(checkNotNull(metadata.getLocation(), "location of %s", metadata), template.getLocation()); checkImageIdMatchesTemplate(metadata); checkOsMatchesTemplate(metadata); assert (metadata.getStatus() == Status.RUNNING) : metadata; From 63f1d334f2b00a87dda1fe2717c0a242d045ff04 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 21:29:26 -0700 Subject: [PATCH 54/60] stable glesys --- labs/glesys/pom.xml | 4 +- .../org/jclouds/glesys/GleSYSApiMetadata.java | 1 + .../glesys/GleSYSProviderMetadata.java | 2 +- .../compute/GleSYSComputeServiceAdapter.java | 13 +++- .../ServerDetailsToNodeMetadata.java | 17 +++++- .../glesys/features/EmailAccountAsyncApi.java | 2 + .../internal/GleSYSTypeAdapters.java | 4 ++ .../glesys/handlers/GleSYSErrorHandler.java | 8 ++- .../GleSYSTemplateBuilderLiveTest.java | 10 ++-- .../ServerDetailsToNodeMetadataTest.java | 6 +- .../glesys/features/ArchiveApiLiveTest.java | 4 +- .../glesys/features/DomainApiLiveTest.java | 8 +-- .../features/EmailAccountApiExpectTest.java | 3 +- .../features/EmailAccountApiLiveTest.java | 59 ++++++++++--------- .../glesys/features/IpApiLiveTest.java | 48 ++++++++------- .../glesys/features/ServerApiExpectTest.java | 2 +- .../glesys/features/ServerApiLiveTest.java | 35 +++++++---- .../internal/BaseGleSYSApiLiveTest.java | 5 +- .../BaseGleSYSApiWithAServerLiveTest.java | 15 +++-- .../src/test/resources/server_details.json | 2 +- 20 files changed, 152 insertions(+), 96 deletions(-) diff --git a/labs/glesys/pom.xml b/labs/glesys/pom.xml index bc2b6772d7..deac5ac055 100644 --- a/labs/glesys/pom.xml +++ b/labs/glesys/pom.xml @@ -36,10 +36,10 @@ https://api.glesys.com 1 - + 3.5.0 FIXME FIXME - + osFamily=UBUNTU,osVersionMatches=1[012].[01][04],os64Bit=true,minRam=768 org.jclouds.glesys*;version="${project.version}" org.jclouds*;version="${project.version}",* diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java index 6325afcbdb..357d6bcfb5 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java @@ -78,6 +78,7 @@ public class GleSYSApiMetadata extends BaseRestApiMetadata { .credentialName("API Key") .documentation(URI.create("https://customer.glesys.com/api.php")) .version("1") + .buildVersion("3.5.0") .defaultEndpoint("https://api.glesys.com") .defaultProperties(GleSYSApiMetadata.defaultProperties()) .view(TypeToken.of(ComputeServiceContext.class)) diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java index 20eccaefe3..fc272cc46d 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java @@ -62,7 +62,7 @@ public class GleSYSProviderMetadata extends BaseProviderMetadata { properties.setProperty(PROPERTY_ZONE + ".Falkenberg." + ISO3166_CODES, "SE-N"); properties.setProperty(PROPERTY_ZONE + ".New York City." + ISO3166_CODES, "US-NY"); properties.setProperty(PROPERTY_ZONE + ".Stockholm." + ISO3166_CODES, "SE-AB"); - properties.setProperty(TEMPLATE, "minRam=512,osFamily=UBUNTU,hypervisorMatches=OpenVZ,osVersionMatches=1[012].[01][04],os64Bit=true,locationId=Falkenberg"); + properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=1[012].[01][04],os64Bit=true,minRam=768"); return properties; } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java index 63e390807a..c42a297a8c 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java @@ -20,8 +20,10 @@ package org.jclouds.glesys.compute; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue; import static org.jclouds.concurrent.FutureIterables.transformParallel; +import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -47,6 +49,7 @@ import org.jclouds.compute.domain.internal.VolumeImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; import org.jclouds.glesys.GleSYSApi; @@ -64,7 +67,9 @@ import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.util.Iterables2; +import com.google.common.base.Charsets; import com.google.common.base.Function; +import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; @@ -115,8 +120,12 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter md = metadataAndTagsAsCommaDelimitedValue(template.getOptions()); + if (md.size() > 0) { + String description = Joiner.on('\n').withKeyValueSeparator("=").join(md); + // TODO: get glesys to stop stripping out equals and commas! + createServerOptions.description(CryptoStreams.hex(description.getBytes(Charsets.UTF_8))); + } ServerSpec.Builder builder = ServerSpec.builder(); builder.datacenter(template.getLocation().getId()); diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java index 4748c6893e..bc83ba77d1 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java @@ -19,6 +19,9 @@ package org.jclouds.glesys.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Strings.isNullOrEmpty; +import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromCommaDelimitedValue; import java.util.Map; import java.util.NoSuchElementException; @@ -42,15 +45,18 @@ import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.internal.VolumeImpl; import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.domain.Location; import org.jclouds.glesys.domain.Ip; import org.jclouds.glesys.domain.ServerDetails; import org.jclouds.logging.Logger; import org.jclouds.util.InetAddresses2.IsPrivateIPAddress; +import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.base.Splitter; import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; @@ -104,8 +110,15 @@ public class ServerDetailsToNodeMetadata implements Function delete(@FormParam("email") String accountAddress); } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java b/labs/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java index b460d2e28c..8391069d8d 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java @@ -42,6 +42,10 @@ public class GleSYSTypeAdapters { @Override public Server.State read(JsonReader reader) throws IOException { + if (reader.peek() == JsonToken.NULL) { + reader.nextNull(); + return Server.State.UNRECOGNIZED; + } return Server.State.fromValue(reader.nextString()); } } diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java b/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java index 82afc0fc17..f6fd125956 100644 --- a/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java +++ b/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java @@ -56,12 +56,16 @@ public class GleSYSErrorHandler implements HttpErrorHandler { exception = new AuthorizationException(message, exception); break; case 400: - if (message.indexOf("Could not find") != -1) { + if (message.indexOf("not find") != -1) { exception = new ResourceNotFoundException(message, exception); } break; case 404: - exception = new ResourceNotFoundException(message, exception); + if (message.indexOf("Not supported") != -1) { + exception = new UnsupportedOperationException(message, exception); + } else { + exception = new ResourceNotFoundException(message, exception); + } break; case 500: if (message.indexOf("Locked") != -1) { diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java index 0744fb632a..59d9e770a5 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java @@ -70,8 +70,8 @@ public class GleSYSTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { return input.version.equals("") || input.version.equals("5") || input.version.equals("5.5") || input.version.equals("5.0") || input.version.equals("6.0"); case WINDOWS: - return input.version.equals("") || input.version.equals("2008") - || (input.version.equals("2008 R2") && input.is64Bit); + return (input.version.equals("") || input.version.equals("2008") + || input.version.equals("2008 R2")) && input.is64Bit; default: return false; } @@ -83,13 +83,13 @@ public class GleSYSTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { @Test public void testDefaultTemplateBuilder() throws IOException { Template defaultTemplate = view.getComputeService().templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getId(), "Ubuntu 12.04 LTS 64-bit"); + assertEquals(defaultTemplate.getImage().getId(), "Ubuntu 12.04 x64"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "12.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); - assertEquals(defaultTemplate.getHardware().getRam(), 512); - assertEquals(defaultTemplate.getHardware().getHypervisor(), "OpenVZ"); + assertEquals(defaultTemplate.getHardware().getRam(), 768); + assertEquals(defaultTemplate.getHardware().getHypervisor(), "Xen"); assertEquals(getSpace(defaultTemplate.getHardware()), 5.0d); assertEquals(defaultTemplate.getHardware().getVolumes().get(0).getType(), Volume.Type.LOCAL); // test that we bound the correct templateoptions in guice diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java index 5ca80eb8b5..771bcb22c8 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java @@ -79,9 +79,9 @@ public class ServerDetailsToNodeMetadataTest extends BaseGleSYSComputeServiceExp actual.toString(), new NodeMetadataBuilder() .ids("vz1840356") - .name("test-email-jclouds") - .hostname("test-email-jclouds") - .group("glesys-s") + .name("glesys-s") + .hostname("glesys-s") + .group("glesys") .imageId("Ubuntu 10.04 LTS 32-bit") .operatingSystem( OperatingSystem.builder().name("Ubuntu 10.04 LTS 32-bit").family(OsFamily.UBUNTU).version("10.04") diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java index 59d8ec6b83..d60d7852fc 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java @@ -29,7 +29,7 @@ import org.jclouds.glesys.domain.ArchiveAllowedArguments; import org.jclouds.glesys.internal.BaseGleSYSApiLiveTest; import org.jclouds.predicates.RetryablePredicate; import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -42,7 +42,7 @@ import com.google.common.base.Predicate; @Test(groups = "live", testName = "ArchiveApiLiveTest", singleThreaded = true) public class ArchiveApiLiveTest extends BaseGleSYSApiLiveTest { - @BeforeGroups(groups = {"live"}) + @BeforeClass(groups = { "integration", "live" }) public void setupContext() { super.setupContext(); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java index 2f086ab526..3a25d268c3 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java @@ -31,8 +31,8 @@ import org.jclouds.glesys.internal.BaseGleSYSApiLiveTest; import org.jclouds.glesys.options.DomainOptions; import org.jclouds.glesys.options.UpdateRecordOptions; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -46,7 +46,7 @@ import com.google.common.base.Predicate; public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { public String testDomain; - @BeforeGroups(groups = {"live"}) + @BeforeClass(groups = { "integration", "live" }) public void setupContext() { super.setupContext(); testDomain = identity.toLowerCase() + "-domain.jclouds.org"; @@ -72,7 +72,7 @@ public class DomainApiLiveTest extends BaseGleSYSApiLiveTest { createDomain(testDomain); } - @AfterGroups(groups = {"live"}) + @AfterClass(groups = { "integration", "live" }) public void tearDownContext() { int before = api.list().size(); api.delete(testDomain); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java index af8801fe11..30adf0dff8 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java @@ -255,8 +255,7 @@ public class EmailAccountApiExpectTest extends BaseGleSYSApiExpectTest { api.delete("test2@jclouds.org"); } - @Test(expectedExceptions = {ResourceNotFoundException.class}) - public void testDeleteWhenResponseIs4xxThrows() throws Exception { + public void testDeleteWhenResponseIs4xxOk() throws Exception { EmailAccountApi api = requestSendsResponse( HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/email/delete/format/json") .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java index 472a11c3e4..2fc3bbc53c 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java @@ -29,12 +29,12 @@ import org.jclouds.glesys.domain.EmailAccount; import org.jclouds.glesys.domain.EmailAlias; import org.jclouds.glesys.domain.EmailOverview; import org.jclouds.glesys.domain.EmailOverviewDomain; -import org.jclouds.glesys.internal.BaseGleSYSApiWithAServerLiveTest; +import org.jclouds.glesys.internal.BaseGleSYSApiLiveTest; import org.jclouds.glesys.options.CreateAccountOptions; import org.jclouds.glesys.options.UpdateAccountOptions; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -43,40 +43,45 @@ import com.google.common.collect.Iterables; /** * Tests behavior of {@code EmailAccountApi} - * + * * @author Adam Lowe */ @Test(groups = "live", testName = "EmailAccountApiLiveTest", singleThreaded = true) -public class EmailAccountApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { +public class EmailAccountApiLiveTest extends BaseGleSYSApiLiveTest { + public EmailAccountApiLiveTest() { + hostName = hostName + "-email"; + } - @BeforeGroups(groups = {"live"}) - public void setupDomains() { - testDomain = identity + ".test.jclouds.org"; + @BeforeClass(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + testDomain = hostName + ".test.jclouds.org"; api = gleContext.getApi().getEmailAccountApi(); + deleteAll(); createDomain(testDomain); - emailAccountCounter = new RetryablePredicate( - new Predicate() { - public boolean apply(Integer value) { - return api.listDomain(testDomain).size() == value; - } - }, 180, 5, TimeUnit.SECONDS); + emailAccountCounter = new RetryablePredicate(new Predicate() { + public boolean apply(Integer value) { + return api.listDomain(testDomain).size() == value; + } + }, 180, 5, TimeUnit.SECONDS); assertTrue(emailAccountCounter.apply(0)); - - try { - api.delete("test2@" + testDomain); - } catch(Exception e) { - } + } - @AfterGroups(groups = {"live"}) - public void tearDownDomains() { + @AfterClass(groups = { "integration", "live" }) + @Override + public void tearDownContext() { + deleteAll(); + super.tearDownContext(); + } + + private void deleteAll() { api.delete("test@" + testDomain); api.delete("test1@" + testDomain); - assertTrue(emailAccountCounter.apply(0)); - gleContext.getApi().getEmailAccountApi().delete(testDomain); } private EmailAccountApi api; @@ -85,8 +90,8 @@ public class EmailAccountApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { @Test public void testCreateEmail() { - api.createWithPassword("test@" + testDomain, "password", - CreateAccountOptions.Builder.antiVirus(true).autorespond(true).autorespondMessage("out of office")); + api.createWithPassword("test@" + testDomain, "password", CreateAccountOptions.Builder.antiVirus(true) + .autorespond(true).autorespondMessage("out of office")); assertTrue(emailAccountCounter.apply(1)); @@ -105,14 +110,14 @@ public class EmailAccountApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { EmailAlias aliasFromList = Iterables.getOnlyElement(api.listAliasesInDomain(testDomain)); assertEquals(aliasFromList, alias); - + EmailOverview overview = api.getOverview(); assertTrue(overview.getSummary().getAliases() == 1); alias = api.updateAlias("test2@" + testDomain, "test1@" + testDomain); overview = api.getOverview(); assertTrue(overview.getSummary().getAliases() == 1); - + aliasFromList = Iterables.getOnlyElement(api.listAliasesInDomain(testDomain)); assertEquals(aliasFromList, alias); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java index 15cd8fb751..aa6c5c359c 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java @@ -29,8 +29,8 @@ import java.util.Set; import org.jclouds.glesys.domain.IpDetails; import org.jclouds.glesys.internal.BaseGleSYSApiWithAServerLiveTest; import org.jclouds.glesys.options.ListIpOptions; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; @@ -39,22 +39,29 @@ import com.google.common.collect.Sets; /** * Tests behavior of {@code IpApi} - * + * * @author Adrian Cole, Mattias Holmqvist */ @Test(groups = "live", testName = "IpApiLiveTest", singleThreaded = true) public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { + public IpApiLiveTest() { + hostName = hostName + "-ip"; + } - @BeforeMethod - public void setupApi() { + @BeforeClass(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); api = gleContext.getApi().getIpApi(); } - @AfterGroups(groups = {"live"}) - public void releaseIp() { + @AfterClass(groups = { "integration", "live" }) + @Override + public void tearDownContext() { if (reservedIp != null) { api.release(reservedIp.getAddress()); } + super.tearDownContext(); } private IpApi api; @@ -80,7 +87,7 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { IpDetails details = api.release(reservedIp.getAddress()); assertEquals(details.getAddress(), reservedIp.getAddress()); assertFalse(details.isReserved()); - + // reserve an address again! reserveIp(); } @@ -97,14 +104,14 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { assertTrue(ownIps.contains(reservedIp)); ownIps = api.list(ListIpOptions.Builder.datacenter(reservedIp.getDatacenter()), - ListIpOptions.Builder.platform(reservedIp.getPlatform()), - ListIpOptions.Builder.ipVersion(reservedIp.getVersion())); + ListIpOptions.Builder.platform(reservedIp.getPlatform()), + ListIpOptions.Builder.ipVersion(reservedIp.getVersion())); assertTrue(ownIps.contains(reservedIp)); ownIps = api.list(ListIpOptions.Builder.serverId("xmthisisnotaserverid")); assertTrue(ownIps.isEmpty()); } - + private void checkOpenVZDefailsInFalkenberg(IpDetails ipDetails) { assertEquals(ipDetails.getDatacenter(), "Falkenberg"); assertEquals(ipDetails.getPlatform(), "OpenVZ"); @@ -113,7 +120,7 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { // broadcast, gateway and netmask are null for OpenVZ assertFalse(ipDetails.getNameServers().isEmpty()); } - + @Test public void testGetOpenVZDetails() throws Exception { FluentIterable openVzIps = api.listFree(4, "Falkenberg", "OpenVZ"); @@ -150,11 +157,11 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { assertEquals(modified.getPtr(), "wibble."); assertEquals(modified2, modified); - + reservedIp = api.resetPtr(reservedIp.getAddress()); - + assertEquals(reservedIp, original); - } + } @Test(dependsOnMethods = "reserveIp") public void testAddRemove() throws Exception { @@ -163,7 +170,7 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { assertEquals(added.getAddress(), reservedIp.getAddress()); assertEquals(added.getPtr(), reservedIp.getPtr()); assertEquals(added.getServerId(), serverId); - + IpDetails again = api.get(reservedIp.getAddress()); assertEquals(again, added); @@ -175,17 +182,16 @@ public class IpApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { Set openVzIps = Sets.newHashSet(api.listFree(4, "Falkenberg", "OpenVZ")); openVzIps.remove(reservedIp.getAddress()); assertFalse(openVzIps.isEmpty()); - + added = api.addToServer(reservedIp.getAddress(), serverId); - + assertEquals(added.getServerId(), serverId); removed = api.removeFromServerAndRelease(reservedIp.getAddress(), serverId); - + assertNull(removed.getServerId()); assertFalse(removed.isReserved()); - - + // reserve an address again! reserveIp(); } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java index 78c0b65efc..f0053efc57 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java @@ -166,7 +166,7 @@ public class ServerApiExpectTest extends BaseGleSYSApiExpectTest { public static ServerDetails expectedServerDetails() { Ip ip = Ip.builder().version4().ip("31.192.231.254").version4().cost(2.0).currency("EUR").build(); Cost cost = Cost.builder().amount(10.22).currency("EUR").timePeriod("month").build(); - return ServerDetails.builder().id("vz1840356").transferGB(50).hostname("test-email-jclouds").cpuCores(1).memorySizeMB(512) + return ServerDetails.builder().id("vz1840356").transferGB(50).hostname("glesys-s").cpuCores(1).memorySizeMB(512) .diskSizeGB(5).datacenter("Falkenberg").description("glesys-s-6dd").platform("OpenVZ") .templateName("Ubuntu 10.04 LTS 32-bit").state(Server.State.RUNNING).cost(cost).ips(ip).build(); } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java index 1ab81e2b85..3de28e41a6 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java @@ -40,7 +40,8 @@ import org.jclouds.glesys.options.DestroyServerOptions; import org.jclouds.glesys.options.ServerStatusOptions; import org.jclouds.glesys.options.UpdateServerOptions; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -57,16 +58,21 @@ import com.google.common.collect.FluentIterable; public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { public static final String testHostName2 = "jclouds-test2"; - @BeforeMethod - public void setupApi() { + @BeforeClass(groups = { "integration", "live" }) + @Override + public void setupContext() { + hostName = hostName + "-server"; + super.setupContext(); api = gleContext.getApi().getServerApi(); } - @AfterGroups(groups = {"live"}) - public void deleteExtraServer() { + @AfterClass(groups = { "integration", "live" }) + @Override + public void tearDownContext() { if (testServerId2 != null) { api.destroy(testServerId2, DestroyServerOptions.Builder.discardIp()); } + super.tearDownContext(); } private ServerApi api; @@ -205,13 +211,20 @@ public class ServerApiLiveTest extends BaseGleSYSApiWithAServerLiveTest { public void testResourceUsage() throws Exception { // test server has only been in existence for less than a minute - check all servers for (Server server : api.list()) { - ResourceUsage usage = api.getResourceUsage(server.getId(), "diskioread", "minute"); - assertEquals(usage.getInfo().getResource(), "diskioread"); - assertEquals(usage.getInfo().getResolution(), "minute"); + try { + ResourceUsage usage = api.getResourceUsage(server.getId(), "diskioread", "minute"); + assertEquals(usage.getInfo().getResource(), "diskioread"); + assertEquals(usage.getInfo().getResolution(), "minute"); + } catch (UnsupportedOperationException e) { - usage = api.getResourceUsage(server.getId(), "cpuusage", "minute"); - assertEquals(usage.getInfo().getResource(), "cpuusage"); - assertEquals(usage.getInfo().getResolution(), "minute"); + } + try { + ResourceUsage usage = api.getResourceUsage(server.getId(), "cpuusage", "minute"); + assertEquals(usage.getInfo().getResource(), "cpuusage"); + assertEquals(usage.getInfo().getResolution(), "minute"); + } catch (UnsupportedOperationException e) { + + } } } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java index c964c56382..83f74fa4eb 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java @@ -28,7 +28,7 @@ import org.jclouds.glesys.GleSYSAsyncApi; import org.jclouds.glesys.features.DomainApi; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -40,6 +40,7 @@ import com.google.common.base.Predicate; */ @Test(groups = "live") public class BaseGleSYSApiLiveTest extends BaseComputeServiceContextLiveTest { + protected String hostName = System.getProperty("user.name").replace('.','-').toLowerCase(); protected RestContext gleContext; @@ -47,7 +48,7 @@ public class BaseGleSYSApiLiveTest extends BaseComputeServiceContextLiveTest { provider = "glesys"; } - @BeforeGroups(groups = { "integration", "live" }) + @BeforeClass(groups = { "integration", "live" }) @Override public void setupContext() { super.setupContext(); diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java index 995d137cbb..a73942edc2 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java @@ -36,8 +36,8 @@ import org.jclouds.glesys.features.ServerApi; import org.jclouds.glesys.options.DestroyServerOptions; import org.jclouds.glesys.options.ServerStatusOptions; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -50,25 +50,24 @@ import com.google.common.base.Predicate; @Test(groups = "live", singleThreaded = true) public class BaseGleSYSApiWithAServerLiveTest extends BaseGleSYSApiLiveTest { protected String serverId; - protected String hostName = "test-server-jclouds"; protected ServerStatusChecker serverStatusChecker; public BaseGleSYSApiWithAServerLiveTest() { provider = "glesys"; } - @BeforeGroups(groups = { "integration", "live" }) + @BeforeClass(groups = { "integration", "live" }) @Override - public final void setupContext() { + public void setupContext() { assertNull(serverId, "This method should be called EXACTLY once per run"); super.setupContext(); serverStatusChecker = createServer(hostName); serverId = serverStatusChecker.getServerId(); } - @AfterGroups(groups = {"integration", "live"}) + @AfterClass(groups = { "integration", "live" }) @Override - public final void tearDownContext() { + public void tearDownContext() { gleContext.getApi().getServerApi().destroy(serverId, DestroyServerOptions.Builder.discardIp()); super.tearDownContext(); } @@ -98,7 +97,7 @@ public class BaseGleSYSApiWithAServerLiveTest extends BaseGleSYSApiLiveTest { assertEquals(testServer.getHostname(), hostName); assertFalse(testServer.getIps().isEmpty()); - ServerStatusChecker runningServerCounter = new ServerStatusChecker(api, testServer.getId(), 180, 10, + ServerStatusChecker runningServerCounter = new ServerStatusChecker(api, testServer.getId(), 300, 10, TimeUnit.SECONDS); assertTrue(runningServerCounter.apply(Server.State.RUNNING)); diff --git a/labs/glesys/src/test/resources/server_details.json b/labs/glesys/src/test/resources/server_details.json index 55a79c498d..e2e25c5497 100644 --- a/labs/glesys/src/test/resources/server_details.json +++ b/labs/glesys/src/test/resources/server_details.json @@ -1,7 +1,7 @@ {"response":{"status":{"code":200,"timestamp":"2012-06-21T14:10:57+02:00","text":"OK"}, "server":{ "serverid":"vz1840356", - "hostname":"test-email-jclouds", + "hostname":"glesys-s", "description":"glesys-s-6dd", "cpucores":1, "memorysize":512, From 696f24280a9b87af7bf5834a912b51ae21c8ec95 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 21:31:12 -0700 Subject: [PATCH 55/60] glesys now a provider --- labs/pom.xml | 1 - {labs => providers}/glesys/pom.xml | 2 +- .../glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java | 0 .../src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java | 0 .../glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java | 0 .../main/java/org/jclouds/glesys/GleSYSProviderMetadata.java | 0 .../org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java | 0 .../compute/config/GleSYSComputeServiceContextModule.java | 0 .../jclouds/glesys/compute/functions/DatacenterToLocation.java | 0 .../glesys/compute/functions/FindLocationForServerSpec.java | 0 .../org/jclouds/glesys/compute/functions/OSTemplateToImage.java | 0 .../functions/ParseOsFamilyVersion64BitFromImageName.java | 0 .../glesys/compute/functions/ServerDetailsToNodeMetadata.java | 0 .../jclouds/glesys/compute/functions/ServerSpecToHardware.java | 0 .../jclouds/glesys/compute/options/GleSYSTemplateOptions.java | 0 .../main/java/org/jclouds/glesys/config/GleSYSParserModule.java | 0 .../java/org/jclouds/glesys/config/GleSYSRestClientModule.java | 0 .../jclouds/glesys/domain/AllowedArgumentsForCreateServer.java | 0 .../glesys/src/main/java/org/jclouds/glesys/domain/Archive.java | 0 .../java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java | 0 .../glesys/src/main/java/org/jclouds/glesys/domain/Console.java | 0 .../glesys/src/main/java/org/jclouds/glesys/domain/Cost.java | 0 .../glesys/src/main/java/org/jclouds/glesys/domain/Domain.java | 0 .../src/main/java/org/jclouds/glesys/domain/DomainRecord.java | 0 .../src/main/java/org/jclouds/glesys/domain/EmailAccount.java | 0 .../src/main/java/org/jclouds/glesys/domain/EmailAlias.java | 0 .../src/main/java/org/jclouds/glesys/domain/EmailOverview.java | 0 .../java/org/jclouds/glesys/domain/EmailOverviewDomain.java | 0 .../java/org/jclouds/glesys/domain/EmailOverviewSummary.java | 0 .../src/main/java/org/jclouds/glesys/domain/EmailQuota.java | 0 .../src/main/java/org/jclouds/glesys/domain/GleSYSBoolean.java | 0 .../glesys/src/main/java/org/jclouds/glesys/domain/Ip.java | 0 .../src/main/java/org/jclouds/glesys/domain/IpDetails.java | 0 .../src/main/java/org/jclouds/glesys/domain/OSTemplate.java | 0 .../src/main/java/org/jclouds/glesys/domain/ResourceStatus.java | 0 .../src/main/java/org/jclouds/glesys/domain/ResourceUsage.java | 0 .../main/java/org/jclouds/glesys/domain/ResourceUsageInfo.java | 0 .../main/java/org/jclouds/glesys/domain/ResourceUsageValue.java | 0 .../glesys/src/main/java/org/jclouds/glesys/domain/Server.java | 0 .../src/main/java/org/jclouds/glesys/domain/ServerDetails.java | 0 .../src/main/java/org/jclouds/glesys/domain/ServerLimit.java | 0 .../src/main/java/org/jclouds/glesys/domain/ServerSpec.java | 0 .../src/main/java/org/jclouds/glesys/domain/ServerStatus.java | 0 .../src/main/java/org/jclouds/glesys/domain/ServerUptime.java | 0 .../src/main/java/org/jclouds/glesys/features/ArchiveApi.java | 0 .../main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java | 0 .../src/main/java/org/jclouds/glesys/features/DomainApi.java | 0 .../main/java/org/jclouds/glesys/features/DomainAsyncApi.java | 0 .../main/java/org/jclouds/glesys/features/EmailAccountApi.java | 0 .../java/org/jclouds/glesys/features/EmailAccountAsyncApi.java | 0 .../glesys/src/main/java/org/jclouds/glesys/features/IpApi.java | 0 .../src/main/java/org/jclouds/glesys/features/IpAsyncApi.java | 0 .../src/main/java/org/jclouds/glesys/features/ServerApi.java | 0 .../main/java/org/jclouds/glesys/features/ServerAsyncApi.java | 0 .../glesys/functions/ParseTemplatesFromHttpResponse.java | 0 .../jclouds/glesys/functions/internal/GleSYSTypeAdapters.java | 0 .../java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java | 0 .../main/java/org/jclouds/glesys/options/AddDomainOptions.java | 0 .../main/java/org/jclouds/glesys/options/AddRecordOptions.java | 0 .../java/org/jclouds/glesys/options/CloneServerOptions.java | 0 .../java/org/jclouds/glesys/options/CreateAccountOptions.java | 0 .../java/org/jclouds/glesys/options/CreateServerOptions.java | 0 .../java/org/jclouds/glesys/options/DestroyServerOptions.java | 0 .../src/main/java/org/jclouds/glesys/options/DomainOptions.java | 0 .../src/main/java/org/jclouds/glesys/options/ListIpOptions.java | 0 .../java/org/jclouds/glesys/options/ServerStatusOptions.java | 0 .../java/org/jclouds/glesys/options/UpdateAccountOptions.java | 0 .../java/org/jclouds/glesys/options/UpdateRecordOptions.java | 0 .../java/org/jclouds/glesys/options/UpdateServerOptions.java | 0 .../main/java/org/jclouds/glesys/reference/GleSYSConstants.java | 0 .../META-INF/services/org.jclouds.providers.ProviderMetadata | 0 .../src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java | 0 .../test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java | 0 .../src/test/java/org/jclouds/glesys/GleSYSProviderTest.java | 0 .../glesys/compute/GleSYSComputeServiceAdapterExpectTest.java | 0 .../jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java | 0 .../org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java | 0 .../org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java | 0 .../jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java | 0 .../functions/ParseOsFamilyVersion64BitFromImageNameTest.java | 0 .../compute/functions/ServerDetailsToNodeMetadataTest.java | 0 .../glesys/compute/functions/ServerSpecToHardwareTest.java | 0 .../compute/internal/BaseGleSYSComputeServiceExpectTest.java | 0 .../glesys/compute/options/GleSYSTemplateOptionsTest.java | 0 .../java/org/jclouds/glesys/features/ArchiveApiExpectTest.java | 0 .../java/org/jclouds/glesys/features/ArchiveApiLiveTest.java | 0 .../java/org/jclouds/glesys/features/DomainApiExpectTest.java | 0 .../java/org/jclouds/glesys/features/DomainApiLiveTest.java | 0 .../org/jclouds/glesys/features/EmailAccountApiExpectTest.java | 0 .../org/jclouds/glesys/features/EmailAccountApiLiveTest.java | 0 .../test/java/org/jclouds/glesys/features/IpApiExpectTest.java | 0 .../test/java/org/jclouds/glesys/features/IpApiLiveTest.java | 0 .../java/org/jclouds/glesys/features/ServerApiExpectTest.java | 0 .../java/org/jclouds/glesys/features/ServerApiLiveTest.java | 0 .../org/jclouds/glesys/internal/BaseGleSYSApiExpectTest.java | 0 .../java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java | 0 .../glesys/internal/BaseGleSYSApiWithAServerLiveTest.java | 0 .../java/org/jclouds/glesys/parse/ParseFullIpDetailsTest.java | 0 .../jclouds/glesys/parse/ParseIpAddressFromResponseTest.java | 0 .../glesys/src/test/resources/archive_allowed_arguments.json | 0 .../glesys/src/test/resources/archive_details.json | 0 {labs => providers}/glesys/src/test/resources/archive_list.json | 0 .../glesys/src/test/resources/domain_details.json | 0 {labs => providers}/glesys/src/test/resources/domain_list.json | 0 .../glesys/src/test/resources/domain_list_records.json | 0 .../glesys/src/test/resources/domain_record.json | 0 .../glesys/src/test/resources/email_details.json | 0 {labs => providers}/glesys/src/test/resources/email_list.json | 0 .../glesys/src/test/resources/email_overview.json | 0 .../glesys/src/test/resources/ip_get_details.json | 0 .../glesys/src/test/resources/ip_get_details_xen.json | 0 {labs => providers}/glesys/src/test/resources/ip_list_free.json | 0 {labs => providers}/glesys/src/test/resources/ip_list_own.json | 0 {labs => providers}/glesys/src/test/resources/ip_release.json | 0 {labs => providers}/glesys/src/test/resources/ip_take.json | 0 {labs => providers}/glesys/src/test/resources/log4j.xml | 0 {labs => providers}/glesys/src/test/resources/osmatches.json | 0 .../glesys/src/test/resources/server_allowed_arguments.json | 0 .../glesys/src/test/resources/server_console.json | 0 .../glesys/src/test/resources/server_details.json | 0 .../glesys/src/test/resources/server_limits.json | 0 {labs => providers}/glesys/src/test/resources/server_list.json | 0 {labs => providers}/glesys/src/test/resources/server_noip.json | 0 .../glesys/src/test/resources/server_resource_usage.json | 0 .../glesys/src/test/resources/server_status.json | 0 .../glesys/src/test/resources/server_templates.json | 0 providers/pom.xml | 1 + 127 files changed, 2 insertions(+), 2 deletions(-) rename {labs => providers}/glesys/pom.xml (99%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/functions/DatacenterToLocation.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/functions/FindLocationForServerSpec.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerSpecToHardware.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/AllowedArgumentsForCreateServer.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/Console.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/EmailAccount.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/EmailAlias.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/EmailQuota.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/GleSYSBoolean.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/Ip.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/IpDetails.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/OSTemplate.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ResourceStatus.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsage.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageInfo.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageValue.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/Server.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ServerSpec.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/AddDomainOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/AddRecordOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/CreateAccountOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/CreateServerOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/DestroyServerOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/ListIpOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java (100%) rename {labs => providers}/glesys/src/main/java/org/jclouds/glesys/reference/GleSYSConstants.java (100%) rename {labs => providers}/glesys/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapterExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageNameTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerSpecToHardwareTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptionsTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiExpectTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/parse/ParseFullIpDetailsTest.java (100%) rename {labs => providers}/glesys/src/test/java/org/jclouds/glesys/parse/ParseIpAddressFromResponseTest.java (100%) rename {labs => providers}/glesys/src/test/resources/archive_allowed_arguments.json (100%) rename {labs => providers}/glesys/src/test/resources/archive_details.json (100%) rename {labs => providers}/glesys/src/test/resources/archive_list.json (100%) rename {labs => providers}/glesys/src/test/resources/domain_details.json (100%) rename {labs => providers}/glesys/src/test/resources/domain_list.json (100%) rename {labs => providers}/glesys/src/test/resources/domain_list_records.json (100%) rename {labs => providers}/glesys/src/test/resources/domain_record.json (100%) rename {labs => providers}/glesys/src/test/resources/email_details.json (100%) rename {labs => providers}/glesys/src/test/resources/email_list.json (100%) rename {labs => providers}/glesys/src/test/resources/email_overview.json (100%) rename {labs => providers}/glesys/src/test/resources/ip_get_details.json (100%) rename {labs => providers}/glesys/src/test/resources/ip_get_details_xen.json (100%) rename {labs => providers}/glesys/src/test/resources/ip_list_free.json (100%) rename {labs => providers}/glesys/src/test/resources/ip_list_own.json (100%) rename {labs => providers}/glesys/src/test/resources/ip_release.json (100%) rename {labs => providers}/glesys/src/test/resources/ip_take.json (100%) rename {labs => providers}/glesys/src/test/resources/log4j.xml (100%) rename {labs => providers}/glesys/src/test/resources/osmatches.json (100%) rename {labs => providers}/glesys/src/test/resources/server_allowed_arguments.json (100%) rename {labs => providers}/glesys/src/test/resources/server_console.json (100%) rename {labs => providers}/glesys/src/test/resources/server_details.json (100%) rename {labs => providers}/glesys/src/test/resources/server_limits.json (100%) rename {labs => providers}/glesys/src/test/resources/server_list.json (100%) rename {labs => providers}/glesys/src/test/resources/server_noip.json (100%) rename {labs => providers}/glesys/src/test/resources/server_resource_usage.json (100%) rename {labs => providers}/glesys/src/test/resources/server_status.json (100%) rename {labs => providers}/glesys/src/test/resources/server_templates.json (100%) diff --git a/labs/pom.xml b/labs/pom.xml index cbc392b9f6..d3e782e44e 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -34,7 +34,6 @@ virtualbox vcloud-director - glesys opsource-servers elb aws-elb diff --git a/labs/glesys/pom.xml b/providers/glesys/pom.xml similarity index 99% rename from labs/glesys/pom.xml rename to providers/glesys/pom.xml index deac5ac055..c420d3e410 100644 --- a/labs/glesys/pom.xml +++ b/providers/glesys/pom.xml @@ -27,7 +27,7 @@ 1.5.0-SNAPSHOT ../../project/pom.xml - org.jclouds.labs + org.jclouds.provider glesys jclouds GleSYS core jclouds components to access GleSYS diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/GleSYSApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java b/providers/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java rename to providers/glesys/src/main/java/org/jclouds/glesys/GleSYSApiMetadata.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java b/providers/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java rename to providers/glesys/src/main/java/org/jclouds/glesys/GleSYSProviderMetadata.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapter.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/config/GleSYSComputeServiceContextModule.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/DatacenterToLocation.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/DatacenterToLocation.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/DatacenterToLocation.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/DatacenterToLocation.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/FindLocationForServerSpec.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/FindLocationForServerSpec.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/FindLocationForServerSpec.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/FindLocationForServerSpec.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/OSTemplateToImage.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageName.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadata.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerSpecToHardware.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerSpecToHardware.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerSpecToHardware.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/functions/ServerSpecToHardware.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java b/providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java rename to providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSParserModule.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java b/providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java rename to providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/AllowedArgumentsForCreateServer.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/AllowedArgumentsForCreateServer.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/AllowedArgumentsForCreateServer.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/AllowedArgumentsForCreateServer.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Console.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/Console.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/Console.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/Console.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/Cost.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/Domain.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/DomainRecord.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailAccount.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailAccount.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailAccount.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailAccount.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailAlias.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailAlias.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailAlias.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailAlias.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverview.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewDomain.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailOverviewSummary.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailQuota.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailQuota.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/EmailQuota.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/EmailQuota.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/GleSYSBoolean.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/GleSYSBoolean.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/GleSYSBoolean.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/GleSYSBoolean.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Ip.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/Ip.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/Ip.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/Ip.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/IpDetails.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/IpDetails.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/IpDetails.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/IpDetails.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/OSTemplate.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/OSTemplate.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/OSTemplate.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/OSTemplate.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceStatus.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceStatus.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceStatus.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceStatus.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsage.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsage.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsage.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsage.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageInfo.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageInfo.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageInfo.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageInfo.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageValue.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageValue.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageValue.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ResourceUsageValue.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/Server.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/Server.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/Server.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/Server.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerDetails.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerLimit.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerSpec.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerSpec.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerSpec.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerSpec.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerStatus.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java b/providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java rename to providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerUptime.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/DomainApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/DomainAsyncApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAccountAsyncApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/IpApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/IpAsyncApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/ServerApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java b/providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java rename to providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncApi.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java b/providers/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java rename to providers/glesys/src/main/java/org/jclouds/glesys/functions/ParseTemplatesFromHttpResponse.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java b/providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java rename to providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/GleSYSTypeAdapters.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java b/providers/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java rename to providers/glesys/src/main/java/org/jclouds/glesys/handlers/GleSYSErrorHandler.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/AddDomainOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/AddDomainOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/AddDomainOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/AddDomainOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/AddRecordOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/AddRecordOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/AddRecordOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/AddRecordOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/CloneServerOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/CreateAccountOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/CreateAccountOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/CreateAccountOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/CreateAccountOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/CreateServerOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/CreateServerOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/CreateServerOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/CreateServerOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/DestroyServerOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/DestroyServerOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/DestroyServerOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/DestroyServerOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/DomainOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/ListIpOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/ListIpOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/ListIpOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/ListIpOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/ServerStatusOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/UpdateAccountOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/UpdateRecordOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java b/providers/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java rename to providers/glesys/src/main/java/org/jclouds/glesys/options/UpdateServerOptions.java diff --git a/labs/glesys/src/main/java/org/jclouds/glesys/reference/GleSYSConstants.java b/providers/glesys/src/main/java/org/jclouds/glesys/reference/GleSYSConstants.java similarity index 100% rename from labs/glesys/src/main/java/org/jclouds/glesys/reference/GleSYSConstants.java rename to providers/glesys/src/main/java/org/jclouds/glesys/reference/GleSYSConstants.java diff --git a/labs/glesys/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/glesys/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata similarity index 100% rename from labs/glesys/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata rename to providers/glesys/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncApiTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/GleSYSErrorHandlerTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/GleSYSProviderTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapterExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapterExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapterExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceAdapterExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSExperimentLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSTemplateBuilderLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageNameTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageNameTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageNameTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageNameTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerDetailsToNodeMetadataTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerSpecToHardwareTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerSpecToHardwareTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerSpecToHardwareTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ServerSpecToHardwareTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/internal/BaseGleSYSComputeServiceExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptionsTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptionsTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptionsTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/compute/options/GleSYSTemplateOptionsTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveApiLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/DomainApiExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/DomainApiLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAccountApiLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/IpApiExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/IpApiLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/ServerApiExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/features/ServerApiLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiExpectTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiExpectTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiExpectTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiExpectTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/internal/BaseGleSYSApiWithAServerLiveTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/parse/ParseFullIpDetailsTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseFullIpDetailsTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/parse/ParseFullIpDetailsTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseFullIpDetailsTest.java diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/parse/ParseIpAddressFromResponseTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseIpAddressFromResponseTest.java similarity index 100% rename from labs/glesys/src/test/java/org/jclouds/glesys/parse/ParseIpAddressFromResponseTest.java rename to providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseIpAddressFromResponseTest.java diff --git a/labs/glesys/src/test/resources/archive_allowed_arguments.json b/providers/glesys/src/test/resources/archive_allowed_arguments.json similarity index 100% rename from labs/glesys/src/test/resources/archive_allowed_arguments.json rename to providers/glesys/src/test/resources/archive_allowed_arguments.json diff --git a/labs/glesys/src/test/resources/archive_details.json b/providers/glesys/src/test/resources/archive_details.json similarity index 100% rename from labs/glesys/src/test/resources/archive_details.json rename to providers/glesys/src/test/resources/archive_details.json diff --git a/labs/glesys/src/test/resources/archive_list.json b/providers/glesys/src/test/resources/archive_list.json similarity index 100% rename from labs/glesys/src/test/resources/archive_list.json rename to providers/glesys/src/test/resources/archive_list.json diff --git a/labs/glesys/src/test/resources/domain_details.json b/providers/glesys/src/test/resources/domain_details.json similarity index 100% rename from labs/glesys/src/test/resources/domain_details.json rename to providers/glesys/src/test/resources/domain_details.json diff --git a/labs/glesys/src/test/resources/domain_list.json b/providers/glesys/src/test/resources/domain_list.json similarity index 100% rename from labs/glesys/src/test/resources/domain_list.json rename to providers/glesys/src/test/resources/domain_list.json diff --git a/labs/glesys/src/test/resources/domain_list_records.json b/providers/glesys/src/test/resources/domain_list_records.json similarity index 100% rename from labs/glesys/src/test/resources/domain_list_records.json rename to providers/glesys/src/test/resources/domain_list_records.json diff --git a/labs/glesys/src/test/resources/domain_record.json b/providers/glesys/src/test/resources/domain_record.json similarity index 100% rename from labs/glesys/src/test/resources/domain_record.json rename to providers/glesys/src/test/resources/domain_record.json diff --git a/labs/glesys/src/test/resources/email_details.json b/providers/glesys/src/test/resources/email_details.json similarity index 100% rename from labs/glesys/src/test/resources/email_details.json rename to providers/glesys/src/test/resources/email_details.json diff --git a/labs/glesys/src/test/resources/email_list.json b/providers/glesys/src/test/resources/email_list.json similarity index 100% rename from labs/glesys/src/test/resources/email_list.json rename to providers/glesys/src/test/resources/email_list.json diff --git a/labs/glesys/src/test/resources/email_overview.json b/providers/glesys/src/test/resources/email_overview.json similarity index 100% rename from labs/glesys/src/test/resources/email_overview.json rename to providers/glesys/src/test/resources/email_overview.json diff --git a/labs/glesys/src/test/resources/ip_get_details.json b/providers/glesys/src/test/resources/ip_get_details.json similarity index 100% rename from labs/glesys/src/test/resources/ip_get_details.json rename to providers/glesys/src/test/resources/ip_get_details.json diff --git a/labs/glesys/src/test/resources/ip_get_details_xen.json b/providers/glesys/src/test/resources/ip_get_details_xen.json similarity index 100% rename from labs/glesys/src/test/resources/ip_get_details_xen.json rename to providers/glesys/src/test/resources/ip_get_details_xen.json diff --git a/labs/glesys/src/test/resources/ip_list_free.json b/providers/glesys/src/test/resources/ip_list_free.json similarity index 100% rename from labs/glesys/src/test/resources/ip_list_free.json rename to providers/glesys/src/test/resources/ip_list_free.json diff --git a/labs/glesys/src/test/resources/ip_list_own.json b/providers/glesys/src/test/resources/ip_list_own.json similarity index 100% rename from labs/glesys/src/test/resources/ip_list_own.json rename to providers/glesys/src/test/resources/ip_list_own.json diff --git a/labs/glesys/src/test/resources/ip_release.json b/providers/glesys/src/test/resources/ip_release.json similarity index 100% rename from labs/glesys/src/test/resources/ip_release.json rename to providers/glesys/src/test/resources/ip_release.json diff --git a/labs/glesys/src/test/resources/ip_take.json b/providers/glesys/src/test/resources/ip_take.json similarity index 100% rename from labs/glesys/src/test/resources/ip_take.json rename to providers/glesys/src/test/resources/ip_take.json diff --git a/labs/glesys/src/test/resources/log4j.xml b/providers/glesys/src/test/resources/log4j.xml similarity index 100% rename from labs/glesys/src/test/resources/log4j.xml rename to providers/glesys/src/test/resources/log4j.xml diff --git a/labs/glesys/src/test/resources/osmatches.json b/providers/glesys/src/test/resources/osmatches.json similarity index 100% rename from labs/glesys/src/test/resources/osmatches.json rename to providers/glesys/src/test/resources/osmatches.json diff --git a/labs/glesys/src/test/resources/server_allowed_arguments.json b/providers/glesys/src/test/resources/server_allowed_arguments.json similarity index 100% rename from labs/glesys/src/test/resources/server_allowed_arguments.json rename to providers/glesys/src/test/resources/server_allowed_arguments.json diff --git a/labs/glesys/src/test/resources/server_console.json b/providers/glesys/src/test/resources/server_console.json similarity index 100% rename from labs/glesys/src/test/resources/server_console.json rename to providers/glesys/src/test/resources/server_console.json diff --git a/labs/glesys/src/test/resources/server_details.json b/providers/glesys/src/test/resources/server_details.json similarity index 100% rename from labs/glesys/src/test/resources/server_details.json rename to providers/glesys/src/test/resources/server_details.json diff --git a/labs/glesys/src/test/resources/server_limits.json b/providers/glesys/src/test/resources/server_limits.json similarity index 100% rename from labs/glesys/src/test/resources/server_limits.json rename to providers/glesys/src/test/resources/server_limits.json diff --git a/labs/glesys/src/test/resources/server_list.json b/providers/glesys/src/test/resources/server_list.json similarity index 100% rename from labs/glesys/src/test/resources/server_list.json rename to providers/glesys/src/test/resources/server_list.json diff --git a/labs/glesys/src/test/resources/server_noip.json b/providers/glesys/src/test/resources/server_noip.json similarity index 100% rename from labs/glesys/src/test/resources/server_noip.json rename to providers/glesys/src/test/resources/server_noip.json diff --git a/labs/glesys/src/test/resources/server_resource_usage.json b/providers/glesys/src/test/resources/server_resource_usage.json similarity index 100% rename from labs/glesys/src/test/resources/server_resource_usage.json rename to providers/glesys/src/test/resources/server_resource_usage.json diff --git a/labs/glesys/src/test/resources/server_status.json b/providers/glesys/src/test/resources/server_status.json similarity index 100% rename from labs/glesys/src/test/resources/server_status.json rename to providers/glesys/src/test/resources/server_status.json diff --git a/labs/glesys/src/test/resources/server_templates.json b/providers/glesys/src/test/resources/server_templates.json similarity index 100% rename from labs/glesys/src/test/resources/server_templates.json rename to providers/glesys/src/test/resources/server_templates.json diff --git a/providers/pom.xml b/providers/pom.xml index 5b1537c1d0..723c6a7844 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -74,5 +74,6 @@ rackspace-cloudservers-us rackspace-cloudservers-uk aws-sqs + glesys From d766f8d4e3d4ba999183a248a8ca4300a8e6b5c5 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 22:37:13 -0700 Subject: [PATCH 56/60] stable ec2 --- .../org/jclouds/ec2/domain/SecurityGroup.java | 9 +-------- ...DescribeSecurityGroupsResponseHandler.java | 3 ++- .../services/SecurityGroupClientLiveTest.java | 20 +++++-------------- .../aws/ec2/AWSEC2ProviderMetadata.java | 2 +- .../AWSEC2TemplateBuilderLiveTest.java | 6 +++--- .../PlacementGroupClientLiveTest.java | 2 +- .../services/SpotInstanceClientLiveTest.java | 8 +++++--- .../aws/ec2/services/TagClientLiveTest.java | 8 +++++--- 8 files changed, 23 insertions(+), 35 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java index db36b5a634..ee39cc56dc 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/SecurityGroup.java @@ -31,7 +31,7 @@ import org.jclouds.javax.annotation.Nullable; * /> * @author Adrian Cole */ -public class SecurityGroup implements Comparable { +public class SecurityGroup { private final String region; private final String id; @@ -61,13 +61,6 @@ public class SecurityGroup implements Comparable { return region; } - /** - * {@inheritDoc} - */ - public int compareTo(SecurityGroup o) { - return (this == o) ? 0 : getName().compareTo(o.getName()); - } - /** * id of the security group. Not in all EC2 impls */ diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSecurityGroupsResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSecurityGroupsResponseHandler.java index 9b1b53ddf9..96cb1d1baf 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSecurityGroupsResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeSecurityGroupsResponseHandler.java @@ -130,7 +130,8 @@ public class DescribeSecurityGroupsResponseHandler extends this.ipProtocol = null; this.ipRanges = Sets.newLinkedHashSet(); } else if (inIpPermissions && !inIpRanges && inGroups) { - this.groups.put(userId, userIdGroupName); + if (userId != null && userIdGroupName != null) + this.groups.put(userId, userIdGroupName); this.userId = null; this.userIdGroupName = null; } else if (!inIpPermissions && !inIpRanges && !inGroups) { diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java index 0f0c9e67a0..3cfa7738e2 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/SecurityGroupClientLiveTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertNotNull; import java.util.Iterator; import java.util.Set; -import java.util.SortedSet; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2ApiMetadata; @@ -32,14 +31,12 @@ import org.jclouds.ec2.domain.IpPermission; import org.jclouds.ec2.domain.IpProtocol; import org.jclouds.ec2.domain.SecurityGroup; import org.jclouds.ec2.domain.UserIdGroupPair; -import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; /** @@ -67,15 +64,13 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe @Test void testDescribe() { for (String region : ec2Client.getConfiguredRegions()) { - SortedSet allResults = ImmutableSortedSet. copyOf(client - .describeSecurityGroupsInRegion(region)); + Set allResults = client.describeSecurityGroupsInRegion(region); assertNotNull(allResults); if (allResults.size() >= 1) { - SecurityGroup group = allResults.last(); - SortedSet result = ImmutableSortedSet. copyOf(client - .describeSecurityGroupsInRegion(region, group.getName())); + SecurityGroup group = Iterables.getLast(allResults); + Set result = client.describeSecurityGroupsInRegion(region, group.getName()); assertNotNull(result); - SecurityGroup compare = result.last(); + SecurityGroup compare = Iterables.getLast(result); assertEquals(compare, group); } } @@ -233,8 +228,7 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe } protected void ensureGroupsExist(String group1Name, String group2Name) { - SortedSet twoResults = ImmutableSortedSet.copyOf(client.describeSecurityGroupsInRegion(null, - group1Name, group2Name)); + Set twoResults = client.describeSecurityGroupsInRegion(null, group1Name, group2Name); assertNotNull(twoResults); assertEquals(twoResults.size(), 2); Iterator iterator = twoResults.iterator(); @@ -279,8 +273,4 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe public static final String PREFIX = System.getProperty("user.name") + "-ec2"; - @AfterTest - public void shutdown() { - view.close(); - } } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java index 4cffbd31ca..ef304cb991 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java @@ -69,7 +69,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata { properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989,801119661308,063491364108,099720109477,411009282317;state=available;image-type=machine"); // amis that work with the cluster instances - properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1 + "," + Region.EU_WEST_1); + properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1 + "," + Region.US_WEST_2 + ","+ Region.EU_WEST_1); properties .setProperty( PROPERTY_EC2_CC_AMI_QUERY, diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index 00d3ba3e56..f6ac142c0a 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -171,7 +171,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { Template defaultTemplate = view.getComputeService().templateBuilder().build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "pv-2012.03.3"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "pv-2012.09.rc-0"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); @@ -186,7 +186,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { Template defaultTemplate = view.getComputeService().templateBuilder().osFamily(OsFamily.AMZN_LINUX) .imageMatches(EC2ImagePredicates.rootDeviceType(RootDeviceType.INSTANCE_STORE)).build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "pv-2012.03.3"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "pv-2012.09.rc-0"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); @@ -201,7 +201,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { .build(); assert (fastestTemplate.getImage().getProviderId().startsWith("ami-")) : fastestTemplate; assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.HI1_4XLARGE); - assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "pv-2012.03.3"); + assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "pv-2012.09.rc-0"); assertEquals(fastestTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(fastestTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(fastestTemplate.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index 9d33a3b6ef..dc93bd90f3 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -63,7 +63,7 @@ import com.google.inject.Module; */ @Test(groups = "live", singleThreaded = true, testName = "PlacementGroupClientLiveTest") public class PlacementGroupClientLiveTest extends BaseComputeServiceContextLiveTest { - ArrayList supportedRegions = newArrayList(Region.US_EAST_1, Region.EU_WEST_1); + ArrayList supportedRegions = newArrayList(Region.US_EAST_1, Region.US_WEST_2, Region.EU_WEST_1); public PlacementGroupClientLiveTest() { provider = "aws-ec2"; diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java index 7bbc22c6ee..26188dc5f7 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java @@ -41,7 +41,7 @@ import org.jclouds.aws.ec2.predicates.SpotInstanceRequestActive; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterTest; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -160,8 +160,9 @@ public class SpotInstanceClientLiveTest extends BaseComputeServiceContextLiveTe public static final String PREFIX = System.getProperty("user.name") + "ec2"; - @AfterTest - public void shutdown() { + @Override + @AfterClass(groups = { "integration", "live" }) + protected void tearDownContext() { if (requests != null) { for (SpotInstanceRequest request : requests) client.getSpotInstanceServices().cancelSpotInstanceRequestsInRegion(request.getRegion(), request.getId()); @@ -170,5 +171,6 @@ public class SpotInstanceClientLiveTest extends BaseComputeServiceContextLiveTe if (instance != null) { client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), instance.getId()); } + super.tearDownContext(); } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java index 42286e54a5..f6d3466159 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/TagClientLiveTest.java @@ -30,7 +30,7 @@ import org.jclouds.aws.ec2.domain.Tag; import org.jclouds.aws.ec2.util.TagFilters; import org.jclouds.aws.ec2.util.TagFilters.ResourceType; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.testng.annotations.AfterGroups; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -69,9 +69,11 @@ public class TagClientLiveTest extends BaseComputeServiceContextLiveTest { } } - @AfterGroups(groups = { "live" }) - public void deleteSecurityGroup() { + @Override + @AfterClass(groups = { "integration", "live" }) + protected void tearDownContext() { view.unwrap(AWSEC2ApiMetadata.CONTEXT_TOKEN).getApi().getSecurityGroupServices().deleteSecurityGroupInRegionById(null, testGroup); + super.tearDownContext(); } public static final String PREFIX = System.getProperty("user.name") + "-ec2"; From 54ec689019576d9dd9d1a59d6c6ed17a3416c25e Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 22:38:22 -0700 Subject: [PATCH 57/60] stable openstack --- .../AllocateAndAddFloatingIpToNode.java | 2 +- ...RemoveFloatingIpFromNodeAndDeallocate.java | 4 +-- ...sWithGroupEncodedIntoNameThenAddToSet.java | 10 +++---- .../nova/v2_0/config/NovaProperties.java | 6 ++-- .../nova/v2_0/extensions/FloatingIPApi.java | 8 ++--- .../v2_0/extensions/FloatingIPAsyncApi.java | 8 ++--- ...tNamePropertyAuthenticationExpectTest.java | 2 +- .../nova/v2_0/NovaErrorHandlerTest.java | 2 +- ...ocateAndAddFloatingIpToNodeExpectTest.java | 12 ++++---- .../extensions/AdminActionsApiLiveTest.java | 12 ++++---- .../FlavorExtraSpecsApiLiveTest.java | 12 ++++---- .../extensions/FloatingIPApiExpectTest.java | 20 ++++++------- .../extensions/FloatingIPApiLiveTest.java | 8 ++--- .../FloatingIPAsyncApiExpectTest.java | 20 ++++++------- .../extensions/HostAggregateApiLiveTest.java | 12 ++++---- .../v2_0/extensions/VolumeApiLiveTest.java | 12 ++++---- .../extensions/VolumeTypeApiLiveTest.java | 9 +++--- .../nova/v2_0/features/ImageApiLiveTest.java | 4 +-- .../v2_0/internal/BaseNovaApiLiveTest.java | 29 ++++++++++--------- .../HPCloudObjectStorageProviderMetadata.java | 3 -- ...oudObjectStorageBlobRequestSignerTest.java | 2 +- ...CloudObjectStorageBlobStoreExpectTest.java | 2 +- 22 files changed, 99 insertions(+), 100 deletions(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java index dc4b274a8d..b02650dfd8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNode.java @@ -82,7 +82,7 @@ public class AllocateAndAddFloatingIpToNode implements FloatingIP ip = null; try { logger.debug(">> allocating or reassigning floating ip for node(%s)", node.getId()); - ip = floatingIpApi.allocate(); + ip = floatingIpApi.create(); } catch (InsufficientResourcesException e) { logger.trace("<< [%s] allocating a new floating ip for node(%s)", e.getMessage(), node.getId()); logger.trace(">> searching for existing, unassigned floating ip for node(%s)", node.getId()); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java index fb59e5c0eb..5a81b499d2 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/RemoveFloatingIpFromNodeAndDeallocate.java @@ -63,7 +63,7 @@ public class RemoveFloatingIpFromNodeAndDeallocate implements Function> removing floatingIp(%s) from node(%s)", ip, id); floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); - floatingIpApi.deallocate(ip.getId()); + floatingIpApi.delete(ip.getId()); } floatingIpCache.invalidate(id); return id; @@ -71,6 +71,6 @@ public class RemoveFloatingIpFromNodeAndDeallocate implements Function securityGroupCache; private final LoadingCache keyPairCache; private final NovaApi novaApi; @@ -77,15 +77,15 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT GroupNamingConvention.Factory namingConvention, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, - AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode, + AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode, LoadingCache securityGroupCache, LoadingCache keyPairCache, NovaApi novaApi) { super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache"); this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache"); - this.allocateAndAddFloatingIpToNode = checkNotNull(allocateAndAddFloatingIpToNode, - "allocateAndAddFloatingIpToNode"); + this.createAndAddFloatingIpToNode = checkNotNull(createAndAddFloatingIpToNode, + "createAndAddFloatingIpToNode"); this.novaApi = checkNotNull(novaApi, "novaApi"); } @@ -153,7 +153,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions()); if (templateOptions.shouldAutoAssignFloatingIp()) { - return Futures.compose(future, allocateAndAddFloatingIpToNode, executor); + return Futures.compose(future, createAndAddFloatingIpToNode, executor); } else { return future; } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java index e8548caebd..3275b62b01 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaProperties.java @@ -31,10 +31,10 @@ public class NovaProperties { public static final String TIMEOUT_SECURITYGROUP_PRESENT = "jclouds.openstack-nova.timeout.securitygroup-present"; /** - * Whenever a node is created, automatically allocate and assign a floating ip address, also - * deallocate when the node is destroyed. + * Whenever a node is created, automatically create and assign a floating ip address, also + * delete when the node is destroyed. */ - public static final String AUTO_ALLOCATE_FLOATING_IPS = "jclouds.openstack-nova.auto-allocate-floating-ips"; + public static final String AUTO_ALLOCATE_FLOATING_IPS = "jclouds.openstack-nova.auto-create-floating-ips"; /** * Whenever a node is created, automatically generate keypairs for groups, as needed, also diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java index e7b0b9db1b..33987cf9a7 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java @@ -57,17 +57,17 @@ public interface FloatingIPApi { /** * Allocate a Floating IP address * - * @return a newly allocated FloatingIP + * @return a newly created FloatingIP */ - FloatingIP allocate(); + FloatingIP create(); /** - * Deallocate a Floating IP address + * Decreate a Floating IP address * * @param id * the Floating IP id */ - void deallocate(String id); + void delete(String id); /** * Add a Floating IP address to a Server diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java index 0b30fcd442..391de9fdd2 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java @@ -84,7 +84,7 @@ public interface FloatingIPAsyncApi { ListenableFuture get(@PathParam("id") String id); /** - * @see FloatingIPApi#allocate + * @see FloatingIPApi#create */ @POST @Path("/os-floating-ips") @@ -93,16 +93,16 @@ public interface FloatingIPAsyncApi { @Produces(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Payload("{}") - ListenableFuture allocate(); + ListenableFuture create(); /** - * @see FloatingIPApi#deallocate + * @see FloatingIPApi#delete */ @DELETE @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Path("/os-floating-ips/{id}") - ListenableFuture deallocate(@PathParam("id") String id); + ListenableFuture delete(@PathParam("id") String id); /** * @see FloatingIPApi#addToServer diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java index c8acfec60c..c19cc001c1 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest.java @@ -37,7 +37,7 @@ import com.google.common.collect.ImmutableSet; * @see KeystoneProperties#CREDENTIAL_TYPE * @author Adrian Cole */ -@Test(groups = "unit", testName = "AccessKeyAndSecretKeyAndTenantIdAuthenticationExpectTest") +@Test(groups = "unit", testName = "AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest") public class AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest extends BaseNovaApiExpectTest { public AccessKeyAndSecretKeyAndTenantNamePropertyAuthenticationExpectTest() { identity = "identity"; diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/NovaErrorHandlerTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/NovaErrorHandlerTest.java index ec16e85c08..2691715488 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/NovaErrorHandlerTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/NovaErrorHandlerTest.java @@ -81,7 +81,7 @@ public class NovaErrorHandlerTest { URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/os-floating-ips"), 400, "HTTP/1.1 400 Bad Request", - "{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}", + "{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot create any more addresses\", \"code\": 400}}", InsufficientResourcesException.class); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java index 39062ed150..97f763de2d 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java @@ -57,7 +57,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer host).name("Server 71592").status(Status.RUNNING).privateAddresses(ImmutableSet.of("10.4.27.237")) .credentials(LoginCredentials.builder().password("foo").build()).build(); - HttpRequest allocateFloatingIP = HttpRequest.builder().method("POST").endpoint( + HttpRequest createFloatingIP = HttpRequest.builder().method("POST").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")).headers( ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", authToken).build()).payload(payloadFromStringWithContentType("{}", "application/json")).build(); @@ -65,7 +65,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer HttpResponse addFloatingIPResponse = HttpResponse.builder().statusCode(200).build(); public void testAllocateWhenAllocationReturnsIpIsAddedToServerAndUpdatesNodeMetadataButSavesCredentials() throws Exception { - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200).payload( + HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200).payload( payloadFromResource("/floatingip_details.json")).build(); HttpRequest addFloatingIPRequest = addFloatingIPForAddress("10.0.0.3"); @@ -73,7 +73,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer AllocateAndAddFloatingIpToNode fn = requestsSendResponses( ImmutableMap. builder().put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess).put(extensionsOfNovaRequest, extensionsOfNovaResponse).put( - allocateFloatingIP, allocateFloatingIPResponse) + createFloatingIP, createFloatingIPResponse) .put(addFloatingIPRequest, addFloatingIPResponse).build()).getContext().utils().injector() .getInstance(AllocateAndAddFloatingIpToNode.class); @@ -98,12 +98,12 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer } public void testAllocateWhenAllocationFailsLookupUnusedIpAddToServerAndUpdatesNodeMetadata() throws Exception { - HttpResponse allocateFloatingIPResponse = HttpResponse + HttpResponse createFloatingIPResponse = HttpResponse .builder() .statusCode(400) .payload( payloadFromStringWithContentType( - "{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}", + "{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot create any more addresses\", \"code\": 400}}", "application/json")).build(); HttpRequest list = HttpRequest.builder().method("GET").endpoint( @@ -119,7 +119,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer AllocateAndAddFloatingIpToNode fn = requestsSendResponses( ImmutableMap. builder().put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess).put(extensionsOfNovaRequest, extensionsOfNovaResponse).put( - allocateFloatingIP, allocateFloatingIPResponse) + createFloatingIP, createFloatingIPResponse) .put(addFloatingIPRequest, addFloatingIPResponse).put(list, listResponseForUnassigned).build()).getContext().utils().injector() .getInstance(AllocateAndAddFloatingIpToNode.class); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java index 602517c9f8..40312f4891 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java @@ -33,9 +33,9 @@ import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions; import org.jclouds.openstack.v2_0.features.ExtensionApi; import org.testng.SkipException; -import org.testng.annotations.AfterGroups; +import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Optional; @@ -60,7 +60,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { private String testServerId; private String backupImageId; - @BeforeGroups(groups = { "integration", "live" }) + @BeforeClass(groups = {"integration", "live"}) @Override public void setupContext() { super.setupContext(); @@ -74,9 +74,9 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { } } - @AfterGroups(groups = "live", alwaysRun = true) + @AfterClass(groups = { "integration", "live" }) @Override - protected void tearDown() { + protected void tearDownContext() { if (apiOption.isPresent()) { if (testServerId != null) { assertTrue(novaContext.getApi().getServerApiForZone(zone).delete(testServerId)); @@ -85,7 +85,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest { imageApi.delete(backupImageId); } } - super.tearDown(); + super.tearDownContext(); } protected void skipOnAdminExtensionAbsent() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java index fc2ec17238..0b24f84d39 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java @@ -27,8 +27,8 @@ import java.util.Map; import org.jclouds.openstack.nova.v2_0.features.FlavorApi; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.jclouds.openstack.v2_0.domain.Resource; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Optional; @@ -50,7 +50,7 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest { private Resource testFlavor; private Map testSpecs = ImmutableMap.of("jclouds-test", "some data", "jclouds-test2", "more data!"); - @BeforeGroups(groups = { "integration", "live" }) + @BeforeClass(groups = {"integration", "live"}) @Override public void setupContext() { super.setupContext(); @@ -59,15 +59,15 @@ public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest { apiOption = novaContext.getApi().getFlavorExtraSpecsExtensionForZone(zone); } - @AfterGroups(groups = "live") + @AfterClass(groups = { "integration", "live" }) @Override - public void tearDown() { + protected void tearDownContext() { if (apiOption.isPresent() && testFlavor != null) { for(String key : testSpecs.keySet()) { assertTrue(apiOption.get().deleteMetadataKey(testFlavor.getId(), key)); } } - super.tearDown(); + super.tearDownContext(); } public void testCreateExtraSpecs() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java index 3d85f11ce3..141408edea 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java @@ -133,7 +133,7 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest { } public void testAllocateWhenResponseIs2xx() throws Exception { - HttpRequest allocateFloatingIP = HttpRequest + HttpRequest createFloatingIP = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") @@ -141,20 +141,20 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .payload(payloadFromStringWithContentType("{}", "application/json")).build(); - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200) + HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/floatingip_details.json")).build(); NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP, - allocateFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP, + createFloatingIPResponse); - assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate().toString(), + assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create().toString(), new ParseFloatingIPTest().expected().toString()); } public void testAllocateWhenResponseIs404() throws Exception { - HttpRequest allocateFloatingIP = HttpRequest + HttpRequest createFloatingIP = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") @@ -162,13 +162,13 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest { .addHeader("X-Auth-Token", authToken) .payload(payloadFromStringWithContentType("{}", "application/json")).build(); - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP, - allocateFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP, + createFloatingIPResponse); - assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate()); + assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create()); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java index 9f4e439d8a..164be4fdbc 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java @@ -68,13 +68,13 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { } @Test - public void testAllocateAndDeallocateFloatingIPs() throws Exception { + public void testAllocateAndDecreateFloatingIPs() throws Exception { for (String zoneId : novaContext.getApi().getConfiguredZones()) { Optional apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId); if (!apiOption.isPresent()) continue; FloatingIPApi api = apiOption.get(); - FloatingIP floatingIP = api.allocate(); + FloatingIP floatingIP = api.create(); assertNotNull(floatingIP); Set response = api.list().toImmutableSet(); @@ -85,7 +85,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { } assertTrue(ipInSet); - api.deallocate(floatingIP.getId()); + api.delete(floatingIP.getId()); response = api.list().toImmutableSet(); ipInSet = false; @@ -107,7 +107,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest { FloatingIPApi api = apiOption.get(); ServerApi serverApi = novaContext.getApi().getServerApiForZone(zoneId); Server server = createServerInZone(zoneId); - FloatingIP floatingIP = api.allocate(); + FloatingIP floatingIP = api.create(); assertNotNull(floatingIP); try { api.addToServer(floatingIP.getIp(), server.getId()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java index 793ba42fe2..42b81d39c4 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java @@ -135,7 +135,7 @@ public class FloatingIPAsyncApiExpectTest extends BaseNovaAsyncApiExpectTest { } public void testAllocateWhenResponseIs2xx() throws Exception { - HttpRequest allocateFloatingIP = HttpRequest + HttpRequest createFloatingIP = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") @@ -143,20 +143,20 @@ public class FloatingIPAsyncApiExpectTest extends BaseNovaAsyncApiExpectTest { .addHeader("X-Auth-Token", authToken) .payload(payloadFromStringWithContentType("{}", "application/json")).build(); - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200) + HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/floatingip_details.json")).build(); NovaAsyncApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP, - allocateFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP, + createFloatingIPResponse); - assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate().get() + assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create().get() .toString(), new ParseFloatingIPTest().expected().toString()); } public void testAllocateWhenResponseIs404() throws Exception { - HttpRequest allocateFloatingIP = HttpRequest + HttpRequest createFloatingIP = HttpRequest .builder() .method("POST") .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips") @@ -164,13 +164,13 @@ public class FloatingIPAsyncApiExpectTest extends BaseNovaAsyncApiExpectTest { .addHeader("X-Auth-Token", authToken) .payload(payloadFromStringWithContentType("{}", "application/json")).build(); - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); NovaAsyncApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP, - allocateFloatingIPResponse); + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP, + createFloatingIPResponse); - assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate().get()); + assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create().get()); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java index 847ad551c5..339bbf9f24 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java @@ -28,8 +28,8 @@ import java.util.Set; import org.jclouds.openstack.nova.v2_0.domain.Host; import org.jclouds.openstack.nova.v2_0.domain.HostAggregate; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Optional; @@ -49,7 +49,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { private HostAggregate testAggregate; - @BeforeGroups(groups = {"integration", "live"}) + @BeforeClass(groups = {"integration", "live"}) @Override public void setupContext() { super.setupContext(); @@ -58,13 +58,13 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest { hostAdminOption = novaContext.getApi().getHostAdministrationExtensionForZone(zone); } + @AfterClass(groups = { "integration", "live" }) @Override - @AfterGroups(groups = {"integration", "live"}) - public void tearDown() { + protected void tearDownContext() { if (testAggregate != null) { assertTrue(apiOption.get().delete(testAggregate.getId())); } - super.tearDown(); + super.tearDownContext(); } public void testCreateAggregate() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java index 0d9363cfb5..4e1efbf00b 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java @@ -31,8 +31,8 @@ import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.jclouds.openstack.nova.v2_0.options.CreateVolumeOptions; import org.jclouds.openstack.nova.v2_0.options.CreateVolumeSnapshotOptions; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Objects; @@ -54,7 +54,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { private Volume testVolume; private VolumeSnapshot testSnapshot; - @BeforeGroups(groups = { "integration", "live" }) + @BeforeClass(groups = {"integration", "live"}) @Override public void setupContext() { super.setupContext(); @@ -62,9 +62,9 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { volumeOption = novaContext.getApi().getVolumeExtensionForZone(zone); } - @AfterGroups(groups = "live", alwaysRun = true) + @AfterClass(groups = { "integration", "live" }) @Override - protected void tearDown() { + protected void tearDownContext() { if (volumeOption.isPresent()) { if (testSnapshot != null) { final String snapshotId = testSnapshot.getId(); @@ -87,7 +87,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest { }, 180 * 1000L).apply(volumeOption.get())); } } - super.tearDown(); + super.tearDownContext(); } public void testCreateVolume() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java index 941613ec50..3733c4beb9 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java @@ -28,7 +28,7 @@ import org.jclouds.openstack.nova.v2_0.domain.VolumeType; import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest; import org.jclouds.openstack.nova.v2_0.options.CreateVolumeTypeOptions; import org.jclouds.predicates.RetryablePredicate; -import org.testng.annotations.AfterGroups; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -59,9 +59,10 @@ public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest { volumeTypeOption = novaContext.getApi().getVolumeTypeExtensionForZone(zone); } - @AfterGroups(groups = "live") + + @AfterClass(groups = { "integration", "live" }) @Override - protected void tearDown() { + protected void tearDownContext() { if (volumeTypeOption.isPresent()) { if (testVolumeType != null) { final String id = testVolumeType.getId(); @@ -74,7 +75,7 @@ public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest { }, 5 * 1000L).apply(volumeTypeOption.get())); } } - super.tearDown(); + super.tearDownContext(); } public void testCreateVolumeType() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java index 6c3f325676..678115aa6c 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiLiveTest.java @@ -65,8 +65,8 @@ public class ImageApiLiveTest extends BaseNovaApiLiveTest { assertNotNull(image.getName()); assertNotNull(image.getLinks()); assertNotNull(image.getCreated()); - assertTrue(image.getMinDisk() > 0); - assertTrue(image.getMinRam() > 0); + // image.getMinDisk() can be zero + // image.getMinRam() can be zero assertTrue(image.getProgress() >= 0 && image.getProgress() <= 100); assertNotNull(image.getStatus()); // image.getServer() can be null diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java index a108eef9ec..79bc69ab91 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/internal/BaseNovaApiLiveTest.java @@ -33,9 +33,9 @@ import org.jclouds.openstack.nova.v2_0.domain.ServerCreated; import org.jclouds.openstack.nova.v2_0.features.FlavorApi; import org.jclouds.openstack.nova.v2_0.features.ImageApi; import org.jclouds.openstack.nova.v2_0.features.ServerApi; +import org.jclouds.openstack.v2_0.domain.Resource; import org.jclouds.rest.RestContext; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Throwables; @@ -50,6 +50,7 @@ import com.google.common.collect.Ordering; */ @Test(groups = "live") public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { + protected String hostName = System.getProperty("user.name").replace('.','-').toLowerCase(); public BaseNovaApiLiveTest() { provider = "openstack-nova"; @@ -58,12 +59,19 @@ public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { protected Set zones; protected RestContext novaContext; - @BeforeGroups(groups = { "integration", "live" }, alwaysRun = true) + @BeforeClass(groups = { "integration", "live" }) @Override public void setupContext() { super.setupContext(); novaContext = view.unwrap(); zones = novaContext.getApi().getConfiguredZones(); + for (String zone : zones){ + ServerApi api = novaContext.getApi().getServerApiForZone(zone); + for (Resource server : api.list().concat()){ + if (server.getName().equals(hostName)) + api.delete(server.getId()); + } + } } @Override @@ -74,15 +82,9 @@ public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { return props; } - @AfterGroups(groups = "live") - protected void tearDown() { - if (novaContext != null) - novaContext.close(); - } - protected Server createServerInZone(String zoneId) { ServerApi serverApi = novaContext.getApi().getServerApiForZone(zoneId); - ServerCreated server = serverApi.create("test", imageIdForZone(zoneId), flavorRefForZone(zoneId)); + ServerCreated server = serverApi.create(hostName, imageIdForZone(zoneId), flavorRefForZone(zoneId)); blockUntilServerInState(server.getId(), serverApi, Status.ACTIVE); return serverApi.get(server.getId()); } @@ -93,10 +95,9 @@ public class BaseNovaApiLiveTest extends BaseComputeServiceContextLiveTest { */ protected void blockUntilServerInState(String serverId, ServerApi api, Status status) { Server currentDetails = null; - for (currentDetails = api.get(serverId); currentDetails.getStatus() != status || - (currentDetails.getExtendedStatus().isPresent() && currentDetails.getExtendedStatus().get().getTaskState() != null); - currentDetails = api - .get(serverId)) { + for (currentDetails = api.get(serverId); currentDetails.getStatus() != status + || ((currentDetails.getExtendedStatus().isPresent() && currentDetails.getExtendedStatus().get() + .getTaskState() != null)); currentDetails = api.get(serverId)) { System.out.printf("blocking on status %s%n%s%n", status, currentDetails); try { Thread.sleep(5 * 1000); diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java index 8a8262ce34..f8930000e8 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java @@ -18,8 +18,6 @@ */ package org.jclouds.hpcloud.objectstorage; -import static org.jclouds.openstack.keystone.v2_0.config.CredentialTypes.API_ACCESS_KEY_CREDENTIALS; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.REQUIRES_TENANT; import java.net.URI; @@ -57,7 +55,6 @@ public class HPCloudObjectStorageProviderMetadata extends BaseProviderMetadata { public static Properties defaultProperties() { Properties properties = new Properties(); - properties.setProperty(CREDENTIAL_TYPE, API_ACCESS_KEY_CREDENTIALS); properties.setProperty(REQUIRES_TENANT, "true"); return properties; } diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSignerTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSignerTest.java index da1c2699ec..ab0351bb59 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSignerTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSignerTest.java @@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableMultimap; public class HPCloudObjectStorageBlobRequestSignerTest extends BaseHPCloudObjectStorageBlobStoreExpectTest { Map requestResponseMap = ImmutableMap. builder().put( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess).build(); + keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess).build(); public void testSignGetBlob() { diff --git a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStoreExpectTest.java b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStoreExpectTest.java index 1651065fac..20e6eaf0f8 100644 --- a/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStoreExpectTest.java +++ b/providers/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStoreExpectTest.java @@ -39,7 +39,7 @@ public class HPCloudObjectStorageBlobStoreExpectTest extends BaseHPCloudObjectSt public void testListObjectsWhenResponseIs2xx() throws Exception { Map requestResponseMap = ImmutableMap. builder().put( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess).build(); + keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess).build(); BlobStore clientWhenLocationsExist = requestsSendResponses(requestResponseMap); From 0be04f79526f130a683441fc0cc429452a1c397e Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 23:38:35 -0700 Subject: [PATCH 58/60] make it possible to extend gson type adapters --- .../java/org/jclouds/json/config/GsonModule.java | 2 +- .../IgnoreNullFluentIterableTypeAdapterFactory.java | 2 +- .../IgnoreNullIterableTypeAdapterFactory.java | 4 ++-- .../internal/IgnoreNullMapTypeAdapterFactory.java | 2 +- .../IgnoreNullMultimapTypeAdapterFactory.java | 4 ++-- .../internal/IgnoreNullSetTypeAdapterFactory.java | 13 +++++++------ .../json/internal/OptionalTypeAdapterFactory.java | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/jclouds/json/config/GsonModule.java b/core/src/main/java/org/jclouds/json/config/GsonModule.java index b0d1e35661..fa2728f5b6 100644 --- a/core/src/main/java/org/jclouds/json/config/GsonModule.java +++ b/core/src/main/java/org/jclouds/json/config/GsonModule.java @@ -102,10 +102,10 @@ public class GsonModule extends AbstractModule { builder.registerTypeAdapter(byte[].class, byteArrayAdapter.nullSafe()); builder.registerTypeAdapter(JsonBall.class, jsonAdapter.nullSafe()); builder.registerTypeAdapterFactory(optional); + builder.registerTypeAdapterFactory(iterable); builder.registerTypeAdapterFactory(set); builder.registerTypeAdapterFactory(map); builder.registerTypeAdapterFactory(multimap); - builder.registerTypeAdapterFactory(iterable); builder.registerTypeAdapterFactory(fluentIterable); AnnotationConstructorNamingStrategy deserializationPolicy = diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java index ad5d9a15b1..42d31e28e1 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullFluentIterableTypeAdapterFactory.java @@ -53,7 +53,7 @@ public class IgnoreNullFluentIterableTypeAdapterFactory implements TypeAdapterFa return (TypeAdapter) newFluentIterableAdapter(elementAdapter); } - private TypeAdapter> newFluentIterableAdapter(final TypeAdapter elementAdapter) { + protected TypeAdapter> newFluentIterableAdapter(final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, FluentIterable value) throws IOException { out.beginArray(); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java index 34ca42d2d3..f4c88fbadb 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullIterableTypeAdapterFactory.java @@ -52,7 +52,7 @@ public class IgnoreNullIterableTypeAdapterFactory implements TypeAdapterFactory return (TypeAdapter) newIterableAdapter(elementAdapter); } - private TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { + protected TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Iterable value) throws IOException { out.beginArray(); @@ -63,7 +63,7 @@ public class IgnoreNullIterableTypeAdapterFactory implements TypeAdapterFactory } public Iterable read(JsonReader in) throws IOException { - in.beginArray(); + in.beginArray(); Builder builder = ImmutableList.builder(); while (in.hasNext()) { E element = elementAdapter.read(in); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java index 7fcfb2b9d3..71d032f631 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMapTypeAdapterFactory.java @@ -54,7 +54,7 @@ public class IgnoreNullMapTypeAdapterFactory implements TypeAdapterFactory { return (TypeAdapter) newMapAdapter(keyAdapter, valueAdapter); } - private TypeAdapter> newMapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { + protected TypeAdapter> newMapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Map value) throws IOException { out.beginObject(); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java index 77938bda58..6a2827c407 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullMultimapTypeAdapterFactory.java @@ -51,10 +51,10 @@ public class IgnoreNullMultimapTypeAdapterFactory implements TypeAdapterFactory Type valueType = ((ParameterizedType) type).getActualTypeArguments()[1]; TypeAdapter keyAdapter = gson.getAdapter(TypeToken.get(keyType)); TypeAdapter valueAdapter = gson.getAdapter(TypeToken.get(valueType)); - return (TypeAdapter) newMapAdapter(keyAdapter, valueAdapter); + return (TypeAdapter) newMultimapAdapter(keyAdapter, valueAdapter); } - private TypeAdapter> newMapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { + protected TypeAdapter> newMultimapAdapter(final TypeAdapter keyAdapter, final TypeAdapter valueAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Multimap map) throws IOException { out.beginObject(); diff --git a/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java index 393a710f3a..1ae22c367f 100644 --- a/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/IgnoreNullSetTypeAdapterFactory.java @@ -23,7 +23,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Set; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; @@ -32,7 +32,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; /** - * Eliminates null values when deserializing Sets + * Eliminates null values when deserializing Sets. *

* Treats [null] as the empty set; [A, null] as [A]; etc. * @@ -52,7 +52,7 @@ public class IgnoreNullSetTypeAdapterFactory implements TypeAdapterFactory { return (TypeAdapter) newSetAdapter(elementAdapter); } - private TypeAdapter> newSetAdapter(final TypeAdapter elementAdapter) { + protected TypeAdapter> newSetAdapter(final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Set value) throws IOException { out.beginArray(); @@ -63,14 +63,15 @@ public class IgnoreNullSetTypeAdapterFactory implements TypeAdapterFactory { } public Set read(JsonReader in) throws IOException { - Set result = Sets.newLinkedHashSet(); + ImmutableSet.Builder result = ImmutableSet. builder(); in.beginArray(); while (in.hasNext()) { E element = elementAdapter.read(in); - if (element != null) result.add(element); + if (element != null) + result.add(element); } in.endArray(); - return result; + return result.build(); } }.nullSafe(); } diff --git a/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java b/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java index 1855e8e7db..0e57f8eaaf 100644 --- a/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java +++ b/core/src/main/java/org/jclouds/json/internal/OptionalTypeAdapterFactory.java @@ -48,10 +48,10 @@ public class OptionalTypeAdapterFactory implements TypeAdapterFactory { Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; TypeAdapter elementAdapter = gson.getAdapter(TypeToken.get(elementType)); - return (TypeAdapter) newMultisetAdapter(elementAdapter); + return (TypeAdapter) newOptionalAdapter(elementAdapter); } - private TypeAdapter> newMultisetAdapter( + protected TypeAdapter> newOptionalAdapter( final TypeAdapter elementAdapter) { return new TypeAdapter>() { public void write(JsonWriter out, Optional value) throws IOException { From bff49f8311cce1e45fe57e7e1fb43419b3af00ba Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 23:39:26 -0700 Subject: [PATCH 59/60] compatible tags across 2.0 and 4.0 --- .../cloudstack/CloudStackApiMetadata.java | 6 +- .../config/CloudStackDateAdapter.java | 51 -------- .../config/CloudStackParserModule.java | 115 ++++++++++++++++++ .../config/CloudStackRestClientModule.java | 83 ++++++++++++- .../cloudstack/domain/DiskOffering.java | 29 +++-- .../org/jclouds/cloudstack/domain/Host.java | 45 ++++--- .../jclouds/cloudstack/domain/Network.java | 27 ++-- .../cloudstack/domain/NetworkOffering.java | 30 +++-- .../cloudstack/domain/ServiceOffering.java | 55 +++------ .../cloudstack/domain/StoragePool.java | 33 +++-- .../features/GlobalHostClientExpectTest.java | 6 +- .../parse/ListHostsResponseTest.java | 15 +-- .../parse/ListStoragePoolsResponseTest.java | 17 ++- .../parse/ListUsageRecordsResponseTest.java | 15 +-- .../resources/liststoragepoolsresponse.json | 2 +- 15 files changed, 353 insertions(+), 176 deletions(-) delete mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java index cdb671f895..d0bf37c0b0 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java @@ -23,6 +23,7 @@ import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.config.CloudStackRestClientModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.BaseRestApiMetadata; @@ -91,7 +92,10 @@ public class CloudStackApiMetadata extends BaseRestApiMetadata { .version("2.2") .view(TypeToken.of(CloudStackContext.class)) .defaultProperties(CloudStackApiMetadata.defaultProperties()) - .defaultModules(ImmutableSet.>of(CloudStackRestClientModule.class, CloudStackComputeServiceContextModule.class)); + .defaultModules(ImmutableSet.> builder() + .add(CloudStackParserModule.class) + .add(CloudStackRestClientModule.class) + .add(CloudStackComputeServiceContextModule.class).build()); } @Override diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java deleted file mode 100644 index e0bc79b1d9..0000000000 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudstack.config; - -import java.io.IOException; -import java.util.Date; - -import javax.inject.Inject; - -import org.jclouds.date.DateService; -import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; - -import com.google.gson.stream.JsonReader; - -/** - * Data adapter for the date formats used by CloudStack. - * - * Essentially this is a workaround for the CloudStack getUsage() API call returning a - * corrupted form of ISO-8601 dates, which have an unexpected pair of apostrophes, like - * 2011-12-12'T'00:00:00+00:00 - * - * @author Richard Downer - */ -public class CloudStackDateAdapter extends Iso8601DateAdapter { - - @Inject - private CloudStackDateAdapter(DateService dateService) { - super(dateService); - } - - public Date read(JsonReader reader) throws IOException { - return parseDate(reader.nextString().replaceAll("'T'", "T")); - } - -} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java new file mode 100644 index 0000000000..086529fc30 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.config; + +import java.io.IOException; +import java.util.Date; + +import javax.inject.Inject; + +import org.jclouds.date.DateService; +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.json.internal.IgnoreNullIterableTypeAdapterFactory; + +import com.google.common.base.Splitter; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.ImmutableSet; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import com.google.inject.AbstractModule; + +/** + * @author Adrian Cole + */ +public class CloudStackParserModule extends AbstractModule { + + @Override + protected void configure() { + bind(DateAdapter.class).to(CloudStackDateAdapter.class); + bind(IgnoreNullIterableTypeAdapterFactory.class).to(CommaDelimitedOKIgnoreNullIterableTypeAdapterFactory.class); + } + + /** + * Data adapter for the date formats used by CloudStack. + * + * Essentially this is a workaround for the CloudStack getUsage() API call returning a corrupted + * form of ISO-8601 dates, which have an unexpected pair of apostrophes, like + * 2011-12-12'T'00:00:00+00:00 + * + * @author Richard Downer + */ + public static class CloudStackDateAdapter extends Iso8601DateAdapter { + + @Inject + private CloudStackDateAdapter(DateService dateService) { + super(dateService); + } + + public Date read(JsonReader reader) throws IOException { + return parseDate(reader.nextString().replaceAll("'T'", "T")); + } + + } + + /** + * Handles types that were previously strings and now arrays (ex. tags) + * + * @author Adrian Cole + */ + public static class CommaDelimitedOKIgnoreNullIterableTypeAdapterFactory extends IgnoreNullIterableTypeAdapterFactory { + + @Override + protected TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { + return new TypeAdapter>() { + public void write(JsonWriter out, Iterable value) throws IOException { + out.beginArray(); + for (E element : value) { + elementAdapter.write(out, element); + } + out.endArray(); + } + + @SuppressWarnings("unchecked") + public Iterable read(JsonReader in) throws IOException { + // HACK as cloudstack changed a field from String to Set! + if (in.peek() == JsonToken.STRING) { + String val = Strings.emptyToNull(in.nextString()); + return (Iterable) (val != null ? Splitter.on(',').split(val) : ImmutableSet.of()); + } else { + Builder builder = ImmutableList. builder(); + in.beginArray(); + while (in.hasNext()) { + E element = elementAdapter.read(in); + if (element != null) + builder.add(element); + } + in.endArray(); + return builder.build(); + } + } + }.nullSafe(); + } + } + +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index 695d72864c..cbdb216c61 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -33,7 +33,86 @@ import org.jclouds.cloudstack.CloudStackDomainClient; import org.jclouds.cloudstack.CloudStackGlobalAsyncClient; import org.jclouds.cloudstack.CloudStackGlobalClient; import org.jclouds.cloudstack.domain.LoginResponse; -import org.jclouds.cloudstack.features.*; +import org.jclouds.cloudstack.features.AccountAsyncClient; +import org.jclouds.cloudstack.features.AccountClient; +import org.jclouds.cloudstack.features.AddressAsyncClient; +import org.jclouds.cloudstack.features.AddressClient; +import org.jclouds.cloudstack.features.AsyncJobAsyncClient; +import org.jclouds.cloudstack.features.AsyncJobClient; +import org.jclouds.cloudstack.features.ConfigurationAsyncClient; +import org.jclouds.cloudstack.features.ConfigurationClient; +import org.jclouds.cloudstack.features.DomainAccountAsyncClient; +import org.jclouds.cloudstack.features.DomainAccountClient; +import org.jclouds.cloudstack.features.DomainDomainAsyncClient; +import org.jclouds.cloudstack.features.DomainDomainClient; +import org.jclouds.cloudstack.features.DomainLimitAsyncClient; +import org.jclouds.cloudstack.features.DomainLimitClient; +import org.jclouds.cloudstack.features.DomainUserAsyncClient; +import org.jclouds.cloudstack.features.DomainUserClient; +import org.jclouds.cloudstack.features.EventAsyncClient; +import org.jclouds.cloudstack.features.EventClient; +import org.jclouds.cloudstack.features.FirewallAsyncClient; +import org.jclouds.cloudstack.features.FirewallClient; +import org.jclouds.cloudstack.features.GlobalAccountAsyncClient; +import org.jclouds.cloudstack.features.GlobalAccountClient; +import org.jclouds.cloudstack.features.GlobalAlertAsyncClient; +import org.jclouds.cloudstack.features.GlobalAlertClient; +import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient; +import org.jclouds.cloudstack.features.GlobalCapacityClient; +import org.jclouds.cloudstack.features.GlobalConfigurationAsyncClient; +import org.jclouds.cloudstack.features.GlobalConfigurationClient; +import org.jclouds.cloudstack.features.GlobalDomainAsyncClient; +import org.jclouds.cloudstack.features.GlobalDomainClient; +import org.jclouds.cloudstack.features.GlobalHostAsyncClient; +import org.jclouds.cloudstack.features.GlobalHostClient; +import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient; +import org.jclouds.cloudstack.features.GlobalOfferingClient; +import org.jclouds.cloudstack.features.GlobalPodAsyncClient; +import org.jclouds.cloudstack.features.GlobalPodClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolAsyncClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolClient; +import org.jclouds.cloudstack.features.GlobalUsageAsyncClient; +import org.jclouds.cloudstack.features.GlobalUsageClient; +import org.jclouds.cloudstack.features.GlobalUserAsyncClient; +import org.jclouds.cloudstack.features.GlobalUserClient; +import org.jclouds.cloudstack.features.GlobalVlanAsyncClient; +import org.jclouds.cloudstack.features.GlobalVlanClient; +import org.jclouds.cloudstack.features.GlobalZoneAsyncClient; +import org.jclouds.cloudstack.features.GlobalZoneClient; +import org.jclouds.cloudstack.features.GuestOSAsyncClient; +import org.jclouds.cloudstack.features.GuestOSClient; +import org.jclouds.cloudstack.features.HypervisorAsyncClient; +import org.jclouds.cloudstack.features.HypervisorClient; +import org.jclouds.cloudstack.features.ISOAsyncClient; +import org.jclouds.cloudstack.features.ISOClient; +import org.jclouds.cloudstack.features.LimitAsyncClient; +import org.jclouds.cloudstack.features.LimitClient; +import org.jclouds.cloudstack.features.LoadBalancerAsyncClient; +import org.jclouds.cloudstack.features.LoadBalancerClient; +import org.jclouds.cloudstack.features.NATAsyncClient; +import org.jclouds.cloudstack.features.NATClient; +import org.jclouds.cloudstack.features.NetworkAsyncClient; +import org.jclouds.cloudstack.features.NetworkClient; +import org.jclouds.cloudstack.features.OfferingAsyncClient; +import org.jclouds.cloudstack.features.OfferingClient; +import org.jclouds.cloudstack.features.SSHKeyPairAsyncClient; +import org.jclouds.cloudstack.features.SSHKeyPairClient; +import org.jclouds.cloudstack.features.SecurityGroupAsyncClient; +import org.jclouds.cloudstack.features.SecurityGroupClient; +import org.jclouds.cloudstack.features.SessionAsyncClient; +import org.jclouds.cloudstack.features.SessionClient; +import org.jclouds.cloudstack.features.SnapshotAsyncClient; +import org.jclouds.cloudstack.features.SnapshotClient; +import org.jclouds.cloudstack.features.TemplateAsyncClient; +import org.jclouds.cloudstack.features.TemplateClient; +import org.jclouds.cloudstack.features.VMGroupAsyncClient; +import org.jclouds.cloudstack.features.VMGroupClient; +import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; +import org.jclouds.cloudstack.features.VirtualMachineClient; +import org.jclouds.cloudstack.features.VolumeAsyncClient; +import org.jclouds.cloudstack.features.VolumeClient; +import org.jclouds.cloudstack.features.ZoneAsyncClient; +import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.cloudstack.filters.AddSessionKeyAndJSessionIdToRequest; import org.jclouds.cloudstack.filters.AuthenticationFilter; import org.jclouds.cloudstack.filters.QuerySigner; @@ -47,7 +126,6 @@ import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; -import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.location.Provider; import org.jclouds.location.suppliers.ImplicitLocationSupplier; import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; @@ -147,7 +225,6 @@ public class CloudStackRestClientModule extends RestClientModule>() { }).to(new TypeLiteral>() { }); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java index ba0a5874ed..97632e4e6e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java @@ -22,11 +22,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Class DiskOffering @@ -54,7 +56,7 @@ public class DiskOffering implements Comparable { protected String domainId; protected int diskSize; protected boolean customized; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); /** * @see DiskOffering#getId() @@ -123,13 +125,21 @@ public class DiskOffering implements Comparable { /** * @see DiskOffering#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } - + + /** + * @see DiskOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + public DiskOffering build() { - return new DiskOffering(id, name, displayText, created, domain, domainId, diskSize, customized, tags); + return new DiskOffering(id, name, displayText, created, domain, domainId, diskSize, customized, tags.build()); } public T fromDiskOffering(DiskOffering in) { @@ -161,14 +171,14 @@ public class DiskOffering implements Comparable { private final String domainId; private final int diskSize; private final boolean customized; - private final String tags; + private final Set tags; @ConstructorProperties({ "id", "name", "displaytext", "created", "domain", "domainid", "disksize", "iscustomized", "tags" }) protected DiskOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable String domain, @Nullable String domainId, int diskSize, boolean customized, - @Nullable String tags) { + @Nullable Iterable tags) { this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; @@ -177,7 +187,7 @@ public class DiskOffering implements Comparable { this.domainId = domainId; this.diskSize = diskSize; this.customized = customized; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); } /** @@ -244,8 +254,7 @@ public class DiskOffering implements Comparable { /** * @return the tags for the disk offering */ - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java index 7d9ea4a982..1cd4c6e15b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java @@ -24,11 +24,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Represents a host issued by Cloudstack @@ -149,7 +151,7 @@ public class Host implements Comparable { protected long diskSizeTotal; protected String events; protected boolean hasEnoughCapacity; - protected String hostTags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); protected String hypervisor; protected String ipAddress; protected boolean localStorageActive; @@ -319,13 +321,21 @@ public class Host implements Comparable { } /** - * @see Host#getHostTags() + * @see Host#getTags() */ - public T hostTags(String hostTags) { - this.hostTags = hostTags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } - + + /** + * @see Host#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + /** * @see Host#getHypervisor() */ @@ -512,7 +522,7 @@ public class Host implements Comparable { public Host build() { - return new Host(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, hostTags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); + return new Host(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, tags.build(), hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); } public T fromHost(Host in) { @@ -535,7 +545,7 @@ public class Host implements Comparable { .diskSizeTotal(in.getDiskSizeTotal()) .events(in.getEvents()) .hasEnoughCapacity(in.isHasEnoughCapacity()) - .hostTags(in.getHostTags()) + .tags(in.getTags()) .hypervisor(in.getHypervisor()) .ipAddress(in.getIpAddress()) .localStorageActive(in.isLocalStorageActive()) @@ -587,7 +597,7 @@ public class Host implements Comparable { private final long diskSizeTotal; private final String events; private final boolean hasEnoughCapacity; - private final String hostTags; + private final Set tags; private final String hypervisor; private final String ipAddress; private final boolean localStorageActive; @@ -619,7 +629,7 @@ public class Host implements Comparable { @Nullable String clusterId, @Nullable String clusterName, @Nullable Host.ClusterType clusterType, @Nullable String cpuAllocated, int cpuNumber, int cpuSpeed, @Nullable String cpuUsed, float cpuWithOverProvisioning, @Nullable Date created, @Nullable Date disconnected, long diskSizeAllocated, - long diskSizeTotal, @Nullable String events, boolean hasEnoughCapacity, @Nullable String hostTags, + long diskSizeTotal, @Nullable String events, boolean hasEnoughCapacity, @Nullable Iterable tags, @Nullable String hypervisor, @Nullable String ipAddress, boolean localStorageActive, @Nullable String jobId, @Nullable AsyncJob.Status jobStatus, @Nullable Date lastPinged, @Nullable String managementServerId, long memoryAllocated, long memoryTotal, long memoryUsed, @Nullable String name, long networkKbsRead, long networkKbsWrite, @@ -644,7 +654,7 @@ public class Host implements Comparable { this.diskSizeTotal = diskSizeTotal; this.events = events; this.hasEnoughCapacity = hasEnoughCapacity; - this.hostTags = hostTags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.hypervisor = hypervisor; this.ipAddress = ipAddress; this.localStorageActive = localStorageActive; @@ -752,11 +762,14 @@ public class Host implements Comparable { return this.hasEnoughCapacity; } - @Nullable - public String getHostTags() { - return this.hostTags; + /** + * @return the tags for the host + */ + public Set getTags() { + return this.tags; } + @Nullable public String getHypervisor() { return this.hypervisor; @@ -868,7 +881,7 @@ public class Host implements Comparable { @Override public int hashCode() { - return Objects.hashCode(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, hostTags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); + return Objects.hashCode(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, tags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); } @Override @@ -894,7 +907,7 @@ public class Host implements Comparable { && Objects.equal(this.diskSizeTotal, that.diskSizeTotal) && Objects.equal(this.events, that.events) && Objects.equal(this.hasEnoughCapacity, that.hasEnoughCapacity) - && Objects.equal(this.hostTags, that.hostTags) + && Objects.equal(this.tags, that.tags) && Objects.equal(this.hypervisor, that.hypervisor) && Objects.equal(this.ipAddress, that.ipAddress) && Objects.equal(this.localStorageActive, that.localStorageActive) @@ -928,7 +941,7 @@ public class Host implements Comparable { .add("cpuSpeed", cpuSpeed).add("cpuUsed", cpuUsed).add("cpuWithOverProvisioning", cpuWithOverProvisioning) .add("created", created).add("disconnected", disconnected).add("diskSizeAllocated", diskSizeAllocated) .add("diskSizeTotal", diskSizeTotal).add("events", events).add("hasEnoughCapacity", hasEnoughCapacity) - .add("hostTags", hostTags).add("hypervisor", hypervisor).add("ipAddress", ipAddress) + .add("tags", tags).add("hypervisor", hypervisor).add("ipAddress", ipAddress) .add("localStorageActive", localStorageActive).add("jobId", jobId).add("jobStatus", jobStatus) .add("lastPinged", lastPinged).add("managementServerId", managementServerId).add("memoryAllocated", memoryAllocated) .add("memoryTotal", memoryTotal).add("memoryUsed", memoryUsed).add("name", name).add("networkKbsRead", networkKbsRead) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java index 457edd049c..08dd4501d9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java @@ -30,6 +30,7 @@ import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; /** @@ -78,7 +79,7 @@ public class Network { protected String VLAN; protected TrafficType trafficType; protected String zoneId; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); protected boolean securityGroupEnabled; protected Set services = ImmutableSortedSet.of(); @@ -302,10 +303,19 @@ public class Network { /** * @see Network#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } + + /** + * @see Network#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + /** * @see Network#isSecurityGroupEnabled() @@ -324,7 +334,7 @@ public class Network { } public Network build() { - return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS1, DNS2, domain, domainId, endIP, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, guestIPType, VLAN, trafficType, zoneId, tags, securityGroupEnabled, services); + return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS1, DNS2, domain, domainId, endIP, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, guestIPType, VLAN, trafficType, zoneId, tags.build(), securityGroupEnabled, services); } public T fromNetwork(Network in) { @@ -397,7 +407,7 @@ public class Network { private final String VLAN; private final TrafficType trafficType; private final String zoneId; - private final String tags; + private final Set tags; private final boolean securityGroupEnabled; private final Set services; @@ -411,7 +421,7 @@ public class Network { @Nullable String networkOfferingDisplayText, @Nullable String networkOfferingId, @Nullable String networkOfferingName, @Nullable String related, @Nullable String startIP, @Nullable String name, @Nullable String state, @Nullable GuestIPType guestIPType, @Nullable String VLAN, @Nullable TrafficType trafficType, - @Nullable String zoneId, @Nullable String tags, boolean securityGroupEnabled, Set services) { + @Nullable String zoneId, @Nullable Iterable tags, boolean securityGroupEnabled, Set services) { this.id = checkNotNull(id, "id"); this.account = account; this.broadcastDomainType = broadcastDomainType; @@ -440,7 +450,7 @@ public class Network { this.VLAN = VLAN; this.trafficType = trafficType; this.zoneId = zoneId; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.securityGroupEnabled = securityGroupEnabled; this.services = ImmutableSortedSet.copyOf(services); } @@ -660,8 +670,7 @@ public class Network { /** * @return the tags for the Network */ - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java index 876b5245d6..1ec0a857a9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java @@ -22,11 +22,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Class NetworkOffering @@ -57,7 +59,7 @@ public class NetworkOffering implements Comparable { protected TrafficType trafficType; protected GuestIPType guestIPType; protected int networkRate; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); /** * @see NetworkOffering#getId() @@ -146,17 +148,26 @@ public class NetworkOffering implements Comparable { this.networkRate = networkRate; return self(); } - + /** * @see NetworkOffering#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } + + /** + * @see NetworkOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + public NetworkOffering build() { - return new NetworkOffering(id, name, displayText, created, availability, maxConnections, isDefault, supportsVLAN, trafficType, guestIPType, networkRate, tags); + return new NetworkOffering(id, name, displayText, created, availability, maxConnections, isDefault, supportsVLAN, trafficType, guestIPType, networkRate, tags.build()); } public T fromNetworkOffering(NetworkOffering in) { @@ -194,12 +205,12 @@ public class NetworkOffering implements Comparable { private final TrafficType trafficType; private final GuestIPType guestIPType; private final int networkRate; - private final String tags; + private final Set tags; @ConstructorProperties({ "id", "name", "displaytext", "created", "availability", "maxconnections", "isdefault", "specifyvlan", "traffictype", "guestiptype", "networkrate", "tags" }) - protected NetworkOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable NetworkOfferingAvailabilityType availability, @Nullable Integer maxConnections, boolean isDefault, boolean supportsVLAN, @Nullable TrafficType trafficType, @Nullable GuestIPType guestIPType, int networkRate, @Nullable String tags) { + protected NetworkOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable NetworkOfferingAvailabilityType availability, @Nullable Integer maxConnections, boolean isDefault, boolean supportsVLAN, @Nullable TrafficType trafficType, @Nullable GuestIPType guestIPType, int networkRate, @Nullable Iterable tags) { this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; @@ -211,7 +222,7 @@ public class NetworkOffering implements Comparable { this.trafficType = trafficType; this.guestIPType = guestIPType; this.networkRate = networkRate; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); } /** @@ -302,8 +313,7 @@ public class NetworkOffering implements Comparable { /** * @return the tags for the network offering */ - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java index b5bd47f365..e472da73c3 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java @@ -26,11 +26,8 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Joiner; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; /** @@ -63,12 +60,11 @@ public class ServiceOffering implements Comparable { protected boolean haSupport; protected StorageType storageType; protected boolean defaultUse; - protected String hostTags; protected boolean systemOffering; protected boolean cpuUseLimited; protected long networkRate; protected boolean systemVmType; - private Set tags = ImmutableSet.of(); + protected ImmutableSet.Builder tags = ImmutableSet.builder(); /** * @see ServiceOffering#getId() @@ -161,11 +157,19 @@ public class ServiceOffering implements Comparable { /** * @see ServiceOffering#getTags() */ - public T tags(Set tags) { - this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } - + + /** + * @see ServiceOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + /** * @see ServiceOffering#isDefaultUse() */ @@ -174,14 +178,6 @@ public class ServiceOffering implements Comparable { return self(); } - /** - * @see ServiceOffering#getHostTags() - */ - public T hostTags(String hostTags) { - this.hostTags = hostTags; - return self(); - } - /** * @see ServiceOffering#isSystemOffering() */ @@ -216,7 +212,7 @@ public class ServiceOffering implements Comparable { public ServiceOffering build() { return new ServiceOffering(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, - Joiner.on(",").join(tags), defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, systemVmType); + tags.build(), defaultUse, systemOffering, cpuUseLimited, networkRate, systemVmType); } public T fromServiceOffering(ServiceOffering in) { @@ -234,7 +230,6 @@ public class ServiceOffering implements Comparable { .storageType(in.getStorageType()) .tags(in.getTags()) .defaultUse(in.isDefaultUse()) - .hostTags(in.getHostTags()) .systemOffering(in.isSystemOffering()) .cpuUseLimited(in.isCpuUseLimited()) .networkRate(in.getNetworkRate()) @@ -262,19 +257,18 @@ public class ServiceOffering implements Comparable { private final StorageType storageType; private final Set tags; private final boolean defaultUse; - private final String hostTags; private final boolean systemOffering; private final boolean cpuUseLimited; private final long networkRate; private final boolean systemVmType; @ConstructorProperties({ - "id", "name", "displaytext", "created", "domain", "domainid", "cpunumber", "cpuspeed", "memory", "offerha", "storagetype", "tags", "defaultuse", "hosttags", "issystem", "limitcpuuse", "networkrate", "systemvmtype" + "id", "name", "displaytext", "created", "domain", "domainid", "cpunumber", "cpuspeed", "memory", "offerha", "storagetype", "tags", "defaultuse", "issystem", "limitcpuuse", "networkrate", "systemvmtype" }) protected ServiceOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable String domain, @Nullable String domainId, int cpuNumber, int cpuSpeed, int memory, - boolean haSupport, @Nullable StorageType storageType, @Nullable String tags, boolean defaultUse, - @Nullable String hostTags, boolean systemOffering, boolean cpuUseLimited, long networkRate, boolean systemVmType) { + boolean haSupport, @Nullable StorageType storageType, @Nullable Iterable tags, boolean defaultUse, + boolean systemOffering, boolean cpuUseLimited, long networkRate, boolean systemVmType) { this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; @@ -286,10 +280,8 @@ public class ServiceOffering implements Comparable { this.memory = memory; this.haSupport = haSupport; this.storageType = storageType; - this.tags = !(Strings.emptyToNull(tags) == null) ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) - : ImmutableSet. of(); + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.defaultUse = defaultUse; - this.hostTags = hostTags; this.systemOffering = systemOffering; this.cpuUseLimited = cpuUseLimited; this.networkRate = networkRate; @@ -389,14 +381,6 @@ public class ServiceOffering implements Comparable { return this.defaultUse; } - /** - * @return the host tag for the service offering - */ - @Nullable - public String getHostTags() { - return this.hostTags; - } - /** * @return whether this is a system vm offering */ @@ -427,7 +411,7 @@ public class ServiceOffering implements Comparable { @Override public int hashCode() { - return Objects.hashCode(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, tags, defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, systemVmType); + return Objects.hashCode(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, tags, defaultUse, systemOffering, cpuUseLimited, networkRate, systemVmType); } @Override @@ -448,7 +432,6 @@ public class ServiceOffering implements Comparable { && Objects.equal(this.storageType, that.storageType) && Objects.equal(this.getTags(), that.getTags()) && Objects.equal(this.defaultUse, that.defaultUse) - && Objects.equal(this.hostTags, that.hostTags) && Objects.equal(this.systemOffering, that.systemOffering) && Objects.equal(this.cpuUseLimited, that.cpuUseLimited) && Objects.equal(this.networkRate, that.networkRate) @@ -460,7 +443,7 @@ public class ServiceOffering implements Comparable { .add("id", id).add("name", name).add("displayText", displayText).add("created", created).add("domain", domain) .add("domainId", domainId).add("cpuNumber", cpuNumber).add("cpuSpeed", cpuSpeed).add("memory", memory) .add("haSupport", haSupport).add("storageType", storageType).add("tags", getTags()).add("defaultUse", defaultUse) - .add("hostTags", hostTags).add("systemOffering", systemOffering).add("cpuUseLimited", cpuUseLimited) + .add("systemOffering", systemOffering).add("cpuUseLimited", cpuUseLimited) .add("networkRate", networkRate).add("systemVmType", systemVmType); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java index 5416c07c24..5c9a32775b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java @@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.CaseFormat; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Represents a storage pool in CloudStack @@ -102,7 +104,7 @@ public class StoragePool implements Comparable { protected String id; protected String name; protected String path; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); protected StoragePool.State state; protected StoragePool.Type type; protected String zoneId; @@ -143,10 +145,18 @@ public class StoragePool implements Comparable { } /** - * @see StoragePool#getTags() + * @see DiskOffering#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); + return self(); + } + + /** + * @see DiskOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); return self(); } @@ -263,7 +273,7 @@ public class StoragePool implements Comparable { } public StoragePool build() { - return new StoragePool(id, name, path, tags, state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); + return new StoragePool(id, name, path, tags.build(), state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); } public T fromStoragePool(StoragePool in) { @@ -299,7 +309,7 @@ public class StoragePool implements Comparable { private final String id; private final String name; private final String path; - private final String tags; + private final Set tags; private final StoragePool.State state; private final StoragePool.Type type; private final String zoneId; @@ -318,11 +328,15 @@ public class StoragePool implements Comparable { @ConstructorProperties({ "id", "name", "path", "tags", "state", "type", "zoneid", "zonename", "podid", "podname", "clusterid", "clustername", "created", "disksizeallocated", "disksizetotal", "ipaddress", "jobid", "jobstatus" }) - protected StoragePool(String id, @Nullable String name, @Nullable String path, @Nullable String tags, @Nullable StoragePool.State state, @Nullable StoragePool.Type type, @Nullable String zoneId, @Nullable String zoneName, @Nullable String podId, @Nullable String podName, @Nullable String clusterId, @Nullable String clusterName, @Nullable Date created, long diskSizeAllocated, long diskSizeTotal, @Nullable String ipAddress, @Nullable String jobId, @Nullable String jobStatus) { + protected StoragePool(String id, @Nullable String name, @Nullable String path, @Nullable Iterable tags, + @Nullable StoragePool.State state, @Nullable StoragePool.Type type, @Nullable String zoneId, + @Nullable String zoneName, @Nullable String podId, @Nullable String podName, @Nullable String clusterId, + @Nullable String clusterName, @Nullable Date created, long diskSizeAllocated, long diskSizeTotal, + @Nullable String ipAddress, @Nullable String jobId, @Nullable String jobStatus) { this.id = checkNotNull(id, "id"); this.name = name; this.path = path; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.state = state; this.type = type; this.zoneId = zoneId; @@ -353,8 +367,7 @@ public class StoragePool implements Comparable { return this.path; } - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java index 26c96b0ac6..1f17abdf83 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java @@ -65,7 +65,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); - Host host1 = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); + Host host1 = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00"); lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00"); @@ -109,7 +109,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); - Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); + Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).addHost("1", "http://example.com", "XenServer", "fred", "sekrit", AddHostOptions.Builder.hostTags(Collections.emptySet()).allocationState(AllocationState.ENABLED).clusterId("1").clusterName("Xen Clust 1").podId("1")); @@ -129,7 +129,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); - Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); + Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).updateHost("1", UpdateHostOptions.Builder.allocationState(AllocationState.ENABLED).hostTags(Collections.emptySet()).osCategoryId("5")); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java index b857fd6e83..60f909659e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java @@ -22,17 +22,16 @@ import static org.testng.Assert.assertEquals; import java.util.Set; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.domain.AllocationState; import org.jclouds.cloudstack.domain.Host; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseParserTest; -import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; import com.google.inject.Guice; import com.google.inject.Injector; @@ -48,16 +47,7 @@ public class ListHostsResponseTest extends BaseParserTest, Set> @Override protected Injector injector() { - return Guice.createInjector(new GsonModule() { - - @Override - protected void configure() { - bind(DateAdapter.class).to(Iso8601DateAdapter.class); - super.configure(); - } - - }); - + return Guice.createInjector(new GsonModule(), new CloudStackParserModule()); } @Override @@ -102,7 +92,6 @@ public class ListHostsResponseTest extends BaseParserTest, Set> .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-11-26T23:28:36+0200")) .events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; " + "AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping") - .hostTags("") .hasEnoughCapacity(false) .allocationState(AllocationState.ENABLED).build(), diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java index 2c4f85dcd4..661afca398 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java @@ -23,18 +23,22 @@ import java.util.Date; import java.util.Set; import java.util.TimeZone; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.domain.StoragePool; import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** * * @author Richard Downer */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "ListStoragePoolsResponseTest") public class ListStoragePoolsResponseTest extends BaseItemParserTest> { @Override @@ -54,7 +58,16 @@ public class ListStoragePoolsResponseTest extends BaseItemParserTest .templateId("0").id("203").startDate(start).endDate(end).build()); } - + @Override protected Injector injector() { - return Guice.createInjector(new GsonModule() { - - @Override - protected void configure() { - bind(DateAdapter.class).to(CloudStackDateAdapter.class); - super.configure(); - } - - }); + return Guice.createInjector(new GsonModule(), new CloudStackParserModule()); } + } diff --git a/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json b/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json index deca7a28c7..dc3ae46444 100644 --- a/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json +++ b/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json @@ -1 +1 @@ -{ "liststoragepoolsresponse" : { "count":1 ,"storagepool" : [ {"id":201,"zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","name":"NFS Pri 1","ipaddress":"10.26.26.165","path":"/mnt/nfs/cs_pri","created":"2011-11-26T23:33:06+0200","type":"NetworkFilesystem","clusterid":1,"clustername":"Xen Clust 1","disksizetotal":898356445184,"disksizeallocated":18276679680,"tags":"","state":"Up"} ] } } \ No newline at end of file +{ "liststoragepoolsresponse" : { "count":1 ,"storagepool" : [ {"id":201,"zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","name":"NFS Pri 1","ipaddress":"10.26.26.165","path":"/mnt/nfs/cs_pri","created":"2011-11-26T23:33:06+0200","type":"NetworkFilesystem","clusterid":1,"clustername":"Xen Clust 1","disksizetotal":898356445184,"disksizeallocated":18276679680,"tags":"tag1","state":"Up"} ] } } \ No newline at end of file From 3d2504e1e444750f7df1d281d2a89dd3a47014ae Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 23:39:55 -0700 Subject: [PATCH 60/60] updated cloudsigma tests --- .../CloudSigmaComputeServiceLiveTest.java | 16 ++++++--- ...dSigmaLasVegasTemplateBuilderLiveTest.java | 33 +++++++++---------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java index bbedf65bdc..5a882ff28f 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java @@ -25,12 +25,13 @@ import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.inject.Module; /** * @author Adrian Cole */ -@Test(groups = "live") +@Test(groups = "live", testName = "CloudSigmaComputeServiceLiveTest") public class CloudSigmaComputeServiceLiveTest extends BaseComputeServiceLiveTest { public CloudSigmaComputeServiceLiveTest() { @@ -46,14 +47,21 @@ public class CloudSigmaComputeServiceLiveTest extends BaseComputeServiceLiveTest @Override protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( - "node userMetadata did not match %s %s", userMetadata, node); + "node userMetadata did not match %s %s", userMetadata, node); } - + + // cloudsigma does not support tags + @Override + protected void checkTagsInNodeEquals(final NodeMetadata node, final ImmutableSet tags) { + assert node.getTags().equals(ImmutableSet. of()) : String.format("node tags did not match %s %s", tags, + node); + } + protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { // hostname is not predictable based on node metadata assert execResponse.getOutput().trim().equals("ubuntu"); } - + @Override public void testOptionToNotBlock() { // start call has to block until we have a pool of reserved pre-cloned drives. diff --git a/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java b/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java index 4c6c3c26ec..20881a0bef 100644 --- a/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java +++ b/providers/cloudsigma-lvs/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaLasVegasTemplateBuilderLiveTest.java @@ -51,23 +51,22 @@ public class CloudSigmaLasVegasTemplateBuilderLiveTest extends BaseTemplateBuild @Override public boolean apply(OsFamilyVersion64Bit input) { switch (input.family) { - case UBUNTU: - return (input.version.equals("11.04") && input.is64Bit) - || (input.version.equals("11.10") && !input.is64Bit) || input.version.equals("") - || input.version.equals("10.04"); - case SOLARIS: - return input.version.equals("") && input.is64Bit; - case DEBIAN: - return false; - case CENTOS: - return (input.version.equals("") || input.version.equals("5.7") || input.version.equals("6.0")) - && input.is64Bit; - case WINDOWS: - return (input.version.equals("2008 R2") || (input.version.equals("2003") || input.version.equals("")) - && input.is64Bit) - || (input.version.equals("") && !input.is64Bit); - default: - return false; + case UBUNTU: + return (ImmutableSet.of("11.04", "10.10").contains(input.version) && input.is64Bit) + || (input.version.equals("11.10") && !input.is64Bit) || input.version.equals("") + || input.version.equals("10.04") || input.version.equals("12.04"); + case SOLARIS: + return (input.version.equals("") || input.version.equals("10")) && input.is64Bit; + case DEBIAN: + return input.version.equals("") || (input.version.equals("5.0") && !input.is64Bit) + || (input.version.equals("6.0") && input.is64Bit); + case CENTOS: + return (input.version.equals("") || input.version.equals("5.5") || input.version.equals("5.7") || input.version + .equals("6.0")) && input.is64Bit; + case WINDOWS: + return input.version.equals("2008") || input.version.equals("2003") || input.version.equals(""); + default: + return false; } }