From c0b37f8bc117832800060a3864540948b0d5faa7 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Sat, 29 Jun 2013 13:06:25 +0200 Subject: [PATCH] JCLOUDS-156: Cleanup Abiquo provider Removed legacy and trivial code from the Abiquo provider: * Removed all trivial predicate classes. * Removed all find* and list* methods in the domain objects that did nothing but delegating to Guava Iterables. * Removed UCS and Pricing Apis, since they are out of the scope of the provider. * Moved monitor events to the existing monitor package. --- .../main/java/org/jclouds/abiquo/AbiquoApi.java | 9 +- .../java/org/jclouds/abiquo/AbiquoContext.java | 8 - .../ucs/BindLogicServerParameters.java | 48 -- .../ucs/BindOrganizationParameters.java | 49 -- .../strategy/AbiquoComputeServiceAdapter.java | 24 +- ...leVirtualDatacentersForImageAndConversions.java | 8 +- ...atibleVirtualDatacentersForImageBaseFormat.java | 6 +- .../abiquo/domain/DomainWithTasksWrapper.java | 13 - .../abiquo/domain/cloud/VirtualAppliance.java | 30 - .../abiquo/domain/cloud/VirtualDatacenter.java | 164 +---- .../abiquo/domain/cloud/VirtualMachine.java | 25 - .../domain/cloud/VirtualMachineTemplate.java | 38 -- .../org/jclouds/abiquo/domain/config/CostCode.java | 170 ----- .../abiquo/domain/config/CostCodeCurrency.java | 47 -- .../abiquo/domain/config/CostCodePrice.java | 58 -- .../org/jclouds/abiquo/domain/config/Currency.java | 144 ----- .../abiquo/domain/config/PricingCostCode.java | 111 ---- .../abiquo/domain/config/PricingTemplate.java | 375 ----------- .../jclouds/abiquo/domain/config/PricingTier.java | 111 ---- .../abiquo/domain/enterprise/Enterprise.java | 285 --------- .../org/jclouds/abiquo/domain/enterprise/Role.java | 13 - .../org/jclouds/abiquo/domain/enterprise/User.java | 19 - .../abiquo/domain/exception/AbiquoException.java | 11 +- .../infrastructure/AbstractPhysicalMachine.java | 266 -------- .../abiquo/domain/infrastructure/Blade.java | 167 ----- .../domain/infrastructure/BladeLocatorLed.java | 68 -- .../abiquo/domain/infrastructure/Datacenter.java | 432 +------------ .../jclouds/abiquo/domain/infrastructure/Fsm.java | 70 -- .../abiquo/domain/infrastructure/LogicServer.java | 85 --- .../abiquo/domain/infrastructure/Machine.java | 260 +++++--- .../abiquo/domain/infrastructure/ManagedRack.java | 708 --------------------- .../abiquo/domain/infrastructure/Organization.java | 89 --- .../jclouds/abiquo/domain/infrastructure/Rack.java | 33 - .../domain/infrastructure/StorageDevice.java | 104 --- .../jclouds/abiquo/domain/infrastructure/Tier.java | 38 -- .../org/jclouds/abiquo/domain/network/Network.java | 18 +- .../events/handlers/AbstractEventHandler.java | 54 -- .../events/handlers/BlockingEventHandler.java | 146 ----- .../abiquo/events/monitor/CompletedEvent.java | 29 - .../jclouds/abiquo/events/monitor/FailedEvent.java | 29 - .../abiquo/events/monitor/MonitorEvent.java | 67 -- .../abiquo/events/monitor/TimeoutEvent.java | 29 - .../jclouds/abiquo/features/InfrastructureApi.java | 353 ---------- .../org/jclouds/abiquo/features/PricingApi.java | 404 ------------ .../features/services/AdministrationService.java | 89 --- .../abiquo/features/services/CloudService.java | 31 - .../features/services/MonitoringService.java | 2 +- .../abiquo/features/services/PricingService.java | 153 ----- .../abiquo/features/services/SearchService.java | 25 - .../jclouds/abiquo/internal/AbiquoContextImpl.java | 12 +- .../abiquo/internal/BaseAdministrationService.java | 83 --- .../jclouds/abiquo/internal/BaseCloudService.java | 32 - .../abiquo/internal/BaseMonitoringService.java | 10 +- .../abiquo/internal/BasePricingService.java | 178 ------ .../jclouds/abiquo/internal/BaseSearchService.java | 20 - .../abiquo/monitor/events/CompletedEvent.java | 29 + .../jclouds/abiquo/monitor/events/FailedEvent.java | 29 + .../abiquo/monitor/events/MonitorEvent.java | 67 ++ .../abiquo/monitor/events/TimeoutEvent.java | 29 + .../monitor/handlers/AbstractEventHandler.java | 54 ++ .../monitor/handlers/BlockingEventHandler.java | 146 +++++ .../jclouds/abiquo/predicates/ErrorPredicates.java | 42 -- .../jclouds/abiquo/predicates/IpPredicates.java | 48 ++ .../jclouds/abiquo/predicates/LinkPredicates.java | 9 +- .../predicates/NetworkServiceTypePredicates.java | 37 ++ .../predicates/VirtualDatacenterPredicates.java | 81 +++ .../VirtualMachineTemplatePredicates.java | 47 ++ .../predicates/cloud/ConversionPredicates.java | 81 --- .../cloud/VirtualAppliancePredicates.java | 55 -- .../cloud/VirtualDatacenterPredicates.java | 114 ---- .../predicates/cloud/VirtualMachinePredicates.java | 67 -- .../cloud/VirtualMachineTemplatePredicates.java | 96 --- .../abiquo/predicates/cloud/VolumePredicates.java | 86 --- .../predicates/config/CategoryPredicates.java | 45 -- .../predicates/config/LicensePredicates.java | 44 -- .../predicates/config/PricingPredicates.java | 68 -- .../predicates/config/PrivilegePredicates.java | 44 -- .../config/SystemPropertyPredicates.java | 45 -- .../enterprise/EnterprisePredicates.java | 43 -- .../predicates/enterprise/RolePredicates.java | 43 -- .../TemplateDefinitionListPredicates.java | 44 -- .../predicates/enterprise/UserPredicates.java | 43 -- .../predicates/infrastructure/BladePredicates.java | 59 -- .../infrastructure/DatacenterPredicates.java | 65 -- .../infrastructure/DatastorePredicates.java | 43 -- .../infrastructure/HypervisorPredicates.java | 43 -- .../infrastructure/LogicServerPredicates.java | 43 -- .../infrastructure/MachinePredicates.java | 59 -- .../infrastructure/ManagedRackPredicates.java | 44 -- .../infrastructure/NetworkInterfacePredicates.java | 44 -- .../predicates/infrastructure/RackPredicates.java | 44 -- .../infrastructure/RemoteServicePredicates.java | 45 -- .../StorageDeviceMetadataPredicates.java | 44 -- .../infrastructure/StorageDevicePredicates.java | 66 -- .../infrastructure/StoragePoolPredicates.java | 44 -- .../predicates/infrastructure/TierPredicates.java | 44 -- .../abiquo/predicates/network/IpPredicates.java | 73 --- .../predicates/network/NetworkPredicates.java | 44 -- .../network/NetworkServiceTypePredicates.java | 37 -- .../abiquo/predicates/network/NicPredicates.java | 54 -- .../predicates/task/AsyncTaskPredicates.java | 44 -- .../abiquo/reference/rest/ParentLinkName.java | 2 - .../org/jclouds/abiquo/strategy/ListEntities.java | 4 - .../jclouds/abiquo/strategy/ListRootEntities.java | 4 - .../abiquo/strategy/cloud/ListAttachedNics.java | 7 - .../strategy/cloud/ListVirtualAppliances.java | 5 - .../strategy/cloud/ListVirtualDatacenters.java | 5 - .../abiquo/strategy/cloud/ListVirtualMachines.java | 5 - .../enterprise/ListVirtualMachineTemplates.java | 6 - .../strategy/infrastructure/ListMachines.java | 5 - .../org/jclouds/abiquo/AbiquoDelegateApiTest.java | 1 - .../ucs/BindLogicServerParametersTest.java | 65 -- .../ucs/BindOrganizationParametersTest.java | 65 -- .../abiquo/domain/InfrastructureResources.java | 96 --- .../jclouds/abiquo/domain/PricingResources.java | 273 -------- .../abiquo/domain/admin/RoleLiveApiTest.java | 28 +- .../domain/cloud/VirtualApplianceLiveTest.java | 13 +- .../domain/cloud/VirtualDatacenterLiveApiTest.java | 31 +- .../domain/cloud/VirtualMachineLiveTest.java | 22 +- .../cloud/VirtualMachineNetworkingLiveApiTest.java | 22 +- .../cloud/VirtualMachineStorageLiveApiTest.java | 11 +- .../abiquo/domain/cloud/VolumeLiveApiTest.java | 30 +- .../abiquo/domain/config/CategoryLiveApiTest.java | 26 +- .../abiquo/domain/config/CostCodeLiveApiTest.java | 126 ---- .../abiquo/domain/config/CurrencyLiveApiTest.java | 67 -- .../domain/config/PricingTemplateLiveApiTest.java | 128 ---- .../TemplateDefinitionListLiveApiTest.java | 16 +- .../abiquo/domain/enterprise/UserLiveApiTest.java | 25 +- .../abiquo/domain/event/EventLiveApiTest.java | 19 +- .../domain/infrastructure/BladeLiveUcsTest.java | 81 --- .../domain/infrastructure/MachineLiveApiTest.java | 23 +- .../infrastructure/ManagedRackLiveUcsTest.java | 108 ---- .../domain/infrastructure/RackLiveApiTest.java | 30 +- .../infrastructure/RemoteServiceLiveApiTest.java | 31 +- .../infrastructure/StorageDeviceLiveApiTest.java | 33 +- .../infrastructure/StoragePoolLiveApiTest.java | 44 +- .../domain/infrastructure/TierLiveApiTest.java | 28 +- .../domain/network/ExternalNetworkLiveApiTest.java | 15 +- .../domain/network/PrivateNetworkLiveApiTest.java | 5 +- .../domain/network/PublicNetworkLiveApiTest.java | 5 +- .../network/UnmanagedNetworkLiveApiTest.java | 16 +- .../abiquo/environment/CloudTestEnvironment.java | 20 +- .../environment/InfrastructureTestEnvironment.java | 102 +-- .../events/handlers/BlockingEventHandlerTest.java | 109 ---- .../abiquo/features/InfrastructureApiTest.java | 431 ------------- .../jclouds/abiquo/features/PricingApiTest.java | 434 ------------- .../jclouds/abiquo/internal/AsyncMonitorTest.java | 2 +- .../abiquo/internal/BaseAbiquoApiLiveApiTest.java | 7 - .../monitor/handlers/BlockingEventHandlerTest.java | 110 ++++ .../cloud/ListAttachedNicsLiveApiTest.java | 32 +- .../cloud/ListVirtualAppliancesLiveApiTest.java | 15 - .../cloud/ListVirtualDatacentersLiveApiTest.java | 18 +- .../cloud/ListVirtualMachinesLiveApiTest.java | 15 - .../ListVirtualMachineTemplatesLiveApiTest.java | 17 - .../infrastructure/ListMachinesLiveApiTest.java | 14 - 155 files changed, 1293 insertions(+), 9884 deletions(-) delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCode.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java create mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/NetworkInterfacePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkServiceTypePredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java delete mode 100644 abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java delete mode 100644 abiquo/src/test/java/org/jclouds/abiquo/features/PricingApiTest.java create mode 100644 abiquo/src/test/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandlerTest.java diff --git a/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java b/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java index 56f019f..4381515 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/AbiquoApi.java @@ -18,6 +18,7 @@ package org.jclouds.abiquo; import java.io.Closeable; +import javax.inject.Named; import javax.ws.rs.GET; import org.jclouds.Fallbacks.NullOnNotFoundOr404; @@ -28,7 +29,6 @@ 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.abiquo.http.filters.AbiquoAuthentication; @@ -110,18 +110,13 @@ public interface AbiquoApi extends Closeable { EventApi getEventApi(); /** - * Provides synchronous access to Pricing features. - */ - @Delegate - PricingApi getPricingApi(); - - /** * Perform a GET request to the given link. * * @param link * The link to get. * @return The response. */ + @Named("link:get") @GET @Fallback(NullOnNotFoundOr404.class) HttpResponse get(@BinderParam(BindLinkToPathAndAcceptHeader.class) final RESTLink link); diff --git a/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java b/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java index 723b841..7f0d679 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/AbiquoContext.java @@ -20,7 +20,6 @@ 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; @@ -80,11 +79,4 @@ public interface AbiquoContext extends ComputeServiceContext { * 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/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java b/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java deleted file mode 100644 index 806cdd7..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParameters.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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", checkNotNull(server.getName(), "server.name")).build(); - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java b/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java deleted file mode 100644 index de5df6d..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParameters.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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", checkNotNull(org.getDn(), "org.dn")).build(); - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java index 6d12bcd..92cee74 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.contains; import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.transform; import java.util.List; @@ -43,9 +44,7 @@ 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.network.IpPredicates; +import org.jclouds.abiquo.predicates.IpPredicates; import org.jclouds.collect.Memoized; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; @@ -120,7 +119,13 @@ public class AbiquoComputeServiceAdapter .getId())); // Load the virtual appliance or create it if it does not exist - VirtualAppliance vapp = vdc.findVirtualAppliance(VirtualAppliancePredicates.name(tag)); + VirtualAppliance vapp = find(vdc.listVirtualAppliances(), new Predicate() { + @Override + public boolean apply(VirtualAppliance input) { + return input.getName().equals(tag); + } + }, null); + if (vapp == null) { vapp = VirtualAppliance.builder(context, vdc).name(tag).build(); vapp.save(); @@ -143,7 +148,7 @@ public class AbiquoComputeServiceAdapter // If no public ip is available in the virtual datacenter, the virtual // machine will be assigned by default an ip address in the default // private VLAN for the virtual datacenter - PublicIp publicIp = vdc.findPurchasedPublicIp(IpPredicates. notUsed()); + PublicIp publicIp = find(vdc.listPurchasedPublicIps(), IpPredicates. notUsed(), null); if (publicIp != null) { List ips = Lists.newArrayList(); ips.add(publicIp); @@ -189,7 +194,12 @@ public class AbiquoComputeServiceAdapter @Override public VirtualMachineTemplate getImage(final String id) { Enterprise enterprise = adminService.getCurrentEnterprise(); - return enterprise.findTemplate(VirtualMachineTemplatePredicates.id(Integer.valueOf(id))); + return find(enterprise.listTemplates(), new Predicate() { + @Override + public boolean apply(VirtualMachineTemplate input) { + return input.getId().equals(id); + } + }, null); } @Override @@ -199,7 +209,7 @@ public class AbiquoComputeServiceAdapter @Override public VirtualMachine getNode(final String id) { - return cloudService.findVirtualMachine(vmId(id)); + return find(cloudService.listVirtualMachines(), vmId(id), null); } @Override diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java index 407ebfa..949d9b7 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java @@ -19,7 +19,7 @@ package org.jclouds.abiquo.compute.strategy.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.abiquo.predicates.cloud.VirtualDatacenterPredicates.compatibleWithTemplateOrConversions; +import static org.jclouds.abiquo.predicates.VirtualDatacenterPredicates.compatibleWithTemplateOrConversions; import javax.inject.Inject; import javax.inject.Singleton; @@ -30,7 +30,7 @@ import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.features.services.CloudService; -import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates; +import org.jclouds.abiquo.predicates.VirtualDatacenterPredicates; import org.jclouds.abiquo.reference.rest.ParentLinkName; import org.jclouds.rest.ApiContext; @@ -67,8 +67,8 @@ public class FindCompatibleVirtualDatacentersForImageAndConversions implements F datacenterDto.setId(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY)); Datacenter datacenter = wrap(context, Datacenter.class, datacenterDto); - Iterable vdcs = cloudService.listVirtualDatacenters(VirtualDatacenterPredicates - .datacenter(datacenter)); + Iterable vdcs = filter(cloudService.listVirtualDatacenters(), + VirtualDatacenterPredicates.datacenter(datacenter)); return filter(vdcs, compatibleWithTemplateOrConversions(template)); } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java index 9873ec0..c6dd0ea 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java @@ -29,7 +29,7 @@ import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.features.services.CloudService; -import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates; +import org.jclouds.abiquo.predicates.VirtualDatacenterPredicates; import org.jclouds.abiquo.reference.rest.ParentLinkName; import org.jclouds.rest.ApiContext; @@ -71,8 +71,8 @@ public class FindCompatibleVirtualDatacentersForImageBaseFormat implements FindC datacenterDto.setId(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY)); Datacenter datacenter = wrap(context, Datacenter.class, datacenterDto); - Iterable vdcs = cloudService.listVirtualDatacenters(VirtualDatacenterPredicates - .datacenter(datacenter)); + Iterable vdcs = filter(cloudService.listVirtualDatacenters(), + VirtualDatacenterPredicates.datacenter(datacenter)); return filter(vdcs, new Predicate() { @Override diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java index b0cd9cb..5f6ddec 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java @@ -16,8 +16,6 @@ */ package org.jclouds.abiquo.domain; -import static com.google.common.collect.Iterables.filter; - import java.util.Collections; import java.util.List; @@ -28,9 +26,6 @@ import org.jclouds.rest.ApiContext; 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.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; @@ -60,12 +55,4 @@ public abstract class DomainWithTasksWrapper listTasks(final Predicate filter) { - return ImmutableList.copyOf(filter(listTasks(), filter)); - } - - public AsyncTask findTask(final Predicate filter) { - return Iterables.getFirst(filter(listTasks(), filter), null); - } } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java index c0fe11f..fb9aa3d 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java @@ -17,7 +17,6 @@ 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; @@ -39,9 +38,6 @@ 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.ImmutableList; -import com.google.common.collect.Iterables; /** * Represents a virtual appliance. @@ -165,32 +161,6 @@ public class VirtualAppliance extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java index c5ed0e5..c8e03f1 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java @@ -17,7 +17,7 @@ package org.jclouds.abiquo.domain.cloud; 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; @@ -30,11 +30,9 @@ 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.ApiContext; @@ -56,8 +54,6 @@ 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.ImmutableList; -import com.google.common.collect.Iterables; /** * Represents a virtual datacenter. @@ -140,8 +136,13 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper */ public Datacenter getDatacenter() { - Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); - datacenter = getEnterprise().findAllowedDatacenter(DatacenterPredicates.id(datacenterId)); + final Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); + datacenter = find(getEnterprise().listAllowedDatacenters(), new Predicate() { + @Override + public boolean apply(Datacenter input) { + return input.getId().equals(datacenterId); + } + }); return datacenter; } @@ -177,40 +178,6 @@ public class VirtualDatacenter extends DomainWithLimitsWrapperhttp://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource - * # VirtualApplianceResource-RetrievethelistofVirtualAppliances - */ - public List listVirtualAppliances(final Predicate filter) { - return ImmutableList.copyOf(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. * @@ -239,40 +206,6 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# VirtualDatacenterResource-Retrieveenabledtiers - */ - public List listStorageTiers(final Predicate filter) { - return ImmutableList.copyOf(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. * @@ -299,40 +232,6 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper http://community.abiquo.com/display/ABI20/Volume+Resource# - * VolumeResource- Retrievethelistofvolumes - */ - public List listVolumes(final Predicate filter) { - return ImmutableList.copyOf(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); @@ -349,14 +248,6 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper listHardDisks(final Predicate filter) { - return ImmutableList.copyOf(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); @@ -387,22 +278,11 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper listPrivateNetworks(final Predicate> filter) { - return ImmutableList.copyOf(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); @@ -415,14 +295,6 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper listAvailableTemplates(final Predicate filter) { - return ImmutableList.copyOf(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()); @@ -452,20 +324,10 @@ public class VirtualDatacenter extends DomainWithLimitsWrapper 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 ImmutableList.copyOf(filter(listAvailablePublicIps(), filter)); - } - - public PublicIp findAvailablePublicIp(final Predicate filter) { - return Iterables.getFirst(filter(listAvailablePublicIps(), filter), null); - } - /** * @see API: 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 ImmutableList.copyOf(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()); diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java index 9e675ef..eac026e 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java @@ -17,7 +17,6 @@ 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; @@ -285,42 +284,18 @@ public class VirtualMachine extends DomainWithTasksWrapper listAttachedHardDisks(final Predicate filter) { - return ImmutableList.copyOf(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 ImmutableList.copyOf(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.utils().injector().getInstance(ListAttachedNics.class); return ImmutableList.copyOf(strategy.execute(this)); } - public List> listAttachedNics(final Predicate> filter) { - return ImmutableList.copyOf(filter(listAttachedNics(), filter)); - } - - public Ip findAttachedNic(final Predicate> filter) { - return Iterables.getFirst(filter(listAttachedNics(), filter), null); - } - // Actions public AsyncTask deploy() { diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java index 8cac027..3a0e809 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachineTemplate.java @@ -17,7 +17,6 @@ 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; @@ -28,7 +27,6 @@ import org.jclouds.abiquo.AbiquoApi; 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.config.CostCode; import org.jclouds.abiquo.domain.enterprise.Enterprise; import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.domain.infrastructure.Tier; @@ -49,10 +47,6 @@ 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.abiquo.server.core.pricing.CostCodeDto; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.inject.TypeLiteral; /** @@ -223,32 +217,6 @@ public class VirtualMachineTemplate extends DomainWrapper listConversions(final Predicate filter) { - return ImmutableList.copyOf(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: - * Cloud administrators can create several cost codes and assign a price to each - * one, to have a flexible way to configure custom billings for each resource. - *

- * Cost codes can be assigned to {@link VirtualMachineTemplate}s and other - * resources to provide pricing information about them. - * - * @author Ignasi Barrera - * @author Susana Acedo - */ -public class CostCode extends DomainWrapper { - - private List defaultPrices; - - /** - * Constructor to be used only by the builder. This resource cannot be - * created. - */ - private CostCode(final ApiContext context, final CostCodeDto target) { - super(context, target); - } - - // Domain operations - - public void delete() { - context.getApi().getPricingApi().deleteCostCode(target); - target = null; - } - - public void save() { - target = context.getApi().getPricingApi().createCostCode(target); - - if (defaultPrices != null && !defaultPrices.isEmpty()) { - CostCodeCurrenciesDto costcodecurrencies = new CostCodeCurrenciesDto(); - for (CostCodePrice ccp : defaultPrices) { - CostCodeCurrencyDto costcodecurrency = new CostCodeCurrencyDto(); - Currency currency = ccp.getCurrency(); - - costcodecurrency.addLink(new RESTLink("currency", currency.unwrap().getEditLink().getHref())); - costcodecurrency.setPrice(ccp.getPrice()); - costcodecurrencies.add(costcodecurrency); - } - context.getApi().getPricingApi().updateCostCodeCurrencies(getId(), costcodecurrencies); - } - - } - - public void update() { - target = context.getApi().getPricingApi().updateCostCode(target); - } - - // Builder - - public static Builder builder(final ApiContext context) { - return new Builder(context); - } - - public static class Builder { - private ApiContext context; - - private String name; - - private String description; - - private List defaultPrices = Lists.newArrayList(); - - public Builder(final ApiContext context) { - super(); - this.context = context; - } - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Builder description(final String description) { - this.description = description; - return this; - } - - public Builder defaultPrices(final List prices) { - this.defaultPrices.addAll(prices); - return this; - } - - public CostCode build() { - CostCodeDto dto = new CostCodeDto(); - dto.setName(name); - dto.setDescription(description); - CostCode costcode = new CostCode(context, dto); - costcode.setDefaultPrices(defaultPrices); - return costcode; - } - - public static Builder fromCostCode(final CostCode in) { - Builder builder = CostCode.builder(in.context).name(in.getName()).description(in.getDescription()) - .defaultPrices(in.getDefaultPrices()); - 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 getDescription() { - return target.getDescription(); - } - - public void setDescription(final String description) { - target.setDescription(description); - } - - public List getDefaultPrices() { - return defaultPrices; - } - - public void setDefaultPrices(final List defaultPrices) { - this.defaultPrices = defaultPrices; - } - - @Override - public String toString() { - return "CostCode [id=" + getId() + ", name=" + getName() + ", description=" + getDescription() + "]"; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java deleted file mode 100644 index 387f1f2..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodeCurrency.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.pricing.CostCodeCurrencyDto; - -public class CostCodeCurrency extends DomainWrapper { - - protected CostCodeCurrency(final ApiContext context, final CostCodeCurrencyDto target) { - super(context, target); - } - - // Delegate methods - - public Integer getId() { - return target.getId(); - } - - public BigDecimal getPrice() { - return target.getPrice(); - } - - @Override - public String toString() { - return "CostCodeCurrency [id=" + getId() + ", price=" + getPrice() + "]"; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java deleted file mode 100644 index 86a08b4..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/CostCodePrice.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal; - -/** - * Gives a price to a {@link CostCode}. - * - * @author Susana Acedo - */ -public class CostCodePrice { - private Currency currency; - - private BigDecimal price; - - public CostCodePrice(final Currency currency, final BigDecimal price) { - super(); - this.currency = currency; - this.price = price; - } - - public Currency getCurrency() { - return currency; - } - - public void setCurrency(final Currency currency) { - this.currency = currency; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(final BigDecimal price) { - this.price = price; - } - - @Override - public String toString() { - return "CostCodePrice [currency=" + currency + ", price=" + price + "]"; - } - -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java deleted file mode 100644 index f3d03d7..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/Currency.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.domain.DomainWrapper; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.pricing.CurrencyDto; - -/** - * Adds high level functionality to {@link CurrencyDto}. - * - * @author Ignasi Barrera - * @author Susana Acedo - */ -public class Currency extends DomainWrapper { - - /** - * Constructor to be used only by the builder. This resource cannot be - * created. - */ - private Currency(final ApiContext context, final CurrencyDto target) { - super(context, target); - } - - // Domain operations - - public void delete() { - context.getApi().getPricingApi().deleteCurrency(target); - target = null; - } - - public void save() { - target = context.getApi().getPricingApi().createCurrency(target); - } - - public void update() { - target = context.getApi().getPricingApi().updateCurrency(target); - } - - // Builder - - public static Builder builder(final ApiContext context) { - return new Builder(context); - } - - public static class Builder { - private ApiContext context; - - private String name; - - private String symbol; - - private int digits; - - public Builder(final ApiContext 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/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java deleted file mode 100644 index 665d004..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingCostCode.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 com.google.common.base.Preconditions.checkNotNull; - -import java.math.BigDecimal; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.pricing.PricingCostCodeDto; - -/** - * Associates a {@link CostCode} with a pricing template. - * - * @author Susana Acedo - */ -public class PricingCostCode extends DomainWrapper { - private CostCode costcode; - - private PricingTemplate pricingTemplate; - - protected PricingCostCode(final ApiContext context, final PricingCostCodeDto target) { - super(context, target); - } - - // Builder - - public static Builder builder(final ApiContext context, final PricingTemplate pricingtemplate, - final CostCode costcode) { - return new Builder(context, pricingtemplate, costcode); - } - - public static class Builder { - private ApiContext context; - - private Integer id; - - private PricingTemplate pricingTemplate; - - private CostCode costcode; - - private BigDecimal price; - - public Builder(final ApiContext context, final PricingTemplate pricingTemplate, final CostCode costcode) { - super(); - this.pricingTemplate = checkNotNull(pricingTemplate, ValidationErrors.NULL_RESOURCE + PricingTemplate.class); - this.costcode = checkNotNull(costcode, ValidationErrors.NULL_RESOURCE + CostCode.class); - this.context = context; - } - - public Builder price(final BigDecimal price) { - this.price = price; - return this; - } - - public PricingCostCode build() { - PricingCostCodeDto dto = new PricingCostCodeDto(); - dto.setId(id); - dto.setPrice(price); - - RESTLink link = costcode.unwrap().searchLink("edit"); - checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); - dto.addLink(new RESTLink("costcode", link.getHref())); - - PricingCostCode pricingcostcode = new PricingCostCode(context, dto); - pricingcostcode.pricingTemplate = pricingTemplate; - pricingcostcode.costcode = costcode; - - return pricingcostcode; - } - - public static Builder fromPricingCostCode(final PricingCostCode in) { - return PricingCostCode.builder(in.context, in.pricingTemplate, in.costcode).price(in.getPrice()); - } - } - - // Delegate methods - - public Integer getId() { - return target.getId(); - } - - public BigDecimal getPrice() { - return target.getPrice(); - } - - @Override - public String toString() { - return "PricingCostCode [id=" + getId() + ", price=" + getPrice() + "]"; - } - -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java deleted file mode 100644 index 6860ee1..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTemplate.java +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 com.google.common.base.Preconditions.checkNotNull; - -import java.math.BigDecimal; -import java.util.Date; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.PricingPeriod; -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.pricing.PricingTemplateDto; - -/** - * A pricing template is a complete pricing schema that can be assigned to an - * {@link Enterprise}. - *

- * This pricing schema will provide detailed billing information for each - * resource consumed by the users of the enterprise. - * - * @author Ignasi Barrera - * @author Susana Acedo - */ - -public class PricingTemplate extends DomainWrapper { - - /** The currency used by the pricing template. */ - protected Currency currency; - - /** - * Constructor to be used only by the builder. This resource cannot be - * created. - */ - private PricingTemplate(final ApiContext context, final PricingTemplateDto target) { - super(context, target); - } - - // Domain operations - - public void delete() { - context.getApi().getPricingApi().deletePricingTemplate(target); - target = null; - } - - public void save() { - target = context.getApi().getPricingApi().createPricingTemplate(target); - } - - public void update() { - target = context.getApi().getPricingApi().updatePricingTemplate(target); - } - - // Builder - - public static Builder builder(final ApiContext context, final Currency currency) { - return new Builder(context, currency); - } - - public static class Builder { - private ApiContext context; - - private Currency currency; - - private String name; - - private String description; - - private BigDecimal hdGB; - - private BigDecimal standingChargePeriod; - - private BigDecimal vlan; - - private PricingPeriod chargingPeriod; - - private BigDecimal minimumChargePeriod; - - private boolean showChangesBefore; - - private boolean showMinimumCharge; - - private PricingPeriod minimumCharge; - - private BigDecimal publicIp; - - private BigDecimal vcpu; - - private BigDecimal memoryGB; - - private boolean defaultTemplate; - - private Date lastUpdate; - - public Builder(final ApiContext context, final Currency currency) { - super(); - this.currency = checkNotNull(currency, ValidationErrors.NULL_RESOURCE + Currency.class); - this.context = context; - } - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Builder description(final String description) { - this.description = description; - return this; - } - - public Builder hdGB(final BigDecimal hdGB) { - this.hdGB = hdGB; - return this; - } - - public Builder standingChargePeriod(final BigDecimal standingChargePeriod) { - this.standingChargePeriod = standingChargePeriod; - return this; - } - - public Builder chargingPeriod(final PricingPeriod chargingPeriod) { - this.chargingPeriod = chargingPeriod; - return this; - } - - public Builder vlan(final BigDecimal vlan) { - this.vlan = vlan; - return this; - } - - public Builder minimumChargePeriod(final BigDecimal minimumChargePeriod) { - this.minimumChargePeriod = minimumChargePeriod; - return this; - } - - public Builder minimumCharge(final PricingPeriod minimumCharge) { - this.minimumCharge = minimumCharge; - return this; - } - - public Builder showChangesBefore(final boolean showChangesBefore) { - this.showChangesBefore = showChangesBefore; - return this; - } - - public Builder showMinimumCharge(final boolean showMinimumCharge) { - this.showMinimumCharge = showMinimumCharge; - return this; - } - - public Builder publicIp(final BigDecimal publicIp) { - this.publicIp = publicIp; - return this; - } - - public Builder vcpu(final BigDecimal vcpu) { - this.vcpu = vcpu; - return this; - } - - public Builder memoryGB(final BigDecimal memoryGB) { - this.memoryGB = memoryGB; - return this; - } - - public Builder defaultTemplate(final boolean defaultTemplate) { - this.defaultTemplate = defaultTemplate; - return this; - } - - public Builder lastUpdate(final Date lastUpdate) { - this.lastUpdate = lastUpdate; - return this; - } - - public Builder currency(final Currency currency) { - this.currency = checkNotNull(currency, ValidationErrors.NULL_RESOURCE + Currency.class); - return this; - } - - public PricingTemplate build() { - PricingTemplateDto dto = new PricingTemplateDto(); - dto.setName(name); - dto.setDescription(description); - dto.setHdGB(hdGB); - dto.setStandingChargePeriod(standingChargePeriod); - dto.setVlan(vlan); - dto.setChargingPeriod(chargingPeriod.ordinal()); - dto.setMinimumCharge(minimumCharge.ordinal()); - dto.setMinimumChargePeriod(minimumChargePeriod); - dto.setShowChangesBefore(showChangesBefore); - dto.setShowMinimumCharge(showMinimumCharge); - dto.setPublicIp(publicIp); - dto.setVcpu(vcpu); - dto.setMemoryGB(memoryGB); - dto.setDefaultTemplate(defaultTemplate); - dto.setLastUpdate(lastUpdate); - - RESTLink link = currency.unwrap().searchLink("edit"); - checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); - dto.addLink(new RESTLink("currency", link.getHref())); - - PricingTemplate pricingTemplate = new PricingTemplate(context, dto); - pricingTemplate.currency = currency; - - return pricingTemplate; - } - - public static Builder fromPricingTemplate(final PricingTemplate in) { - Builder builder = PricingTemplate.builder(in.context, in.currency).name(in.getName()) - .description(in.getDescription()).hdGB(in.getHdGB()).standingChargePeriod(in.getStandingChargePeriod()) - .vcpu(in.getVlan()).chargingPeriod(in.getChargingPeriod()).minimumCharge(in.getMinimumCharge()) - .minimumChargePeriod(in.getMinimumChargePeriod()).showChangesBefore(in.isShowChangesBefore()) - .showMinimumCharge(in.isShowMinimumCharge()).publicIp(in.getPublicIp()).vcpu(in.getVcpu()) - .memoryGB(in.getMemoryGB()).defaultTemplate(in.isDefaultTemplate()).lastUpdate(in.getLastUpdate()); - 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 getDescription() { - return target.getDescription(); - } - - public void setDescription(final String description) { - target.setDescription(description); - } - - public BigDecimal getHdGB() { - return target.getHdGB(); - } - - public void setHdGB(final BigDecimal hdGB) { - target.setHdGB(hdGB); - } - - public BigDecimal getStandingChargePeriod() { - return target.getStandingChargePeriod(); - } - - public void setStandingChargePeriod(final BigDecimal standingChargePeriod) { - target.setStandingChargePeriod(standingChargePeriod); - } - - public BigDecimal getVlan() { - return target.getVlan(); - } - - public void setVlan(final BigDecimal vlan) { - target.getVlan(); - } - - public BigDecimal getMinimumChargePeriod() { - return target.getMinimumChargePeriod(); - } - - public void setMinimumChargePeriod(final BigDecimal minimumChargePeriod) { - target.setMinimumChargePeriod(minimumChargePeriod); - } - - public boolean isShowChangesBefore() { - return target.isShowChangesBefore(); - } - - public void setShowChangesBefore(final boolean showChangesBefore) { - target.setShowChangesBefore(showChangesBefore); - } - - public boolean isShowMinimumCharge() { - return target.isShowMinimumCharge(); - } - - public void setShowMinimumCharge(final boolean showMinimumCharge) { - target.setShowMinimumCharge(showMinimumCharge); - } - - public PricingPeriod getMinimumCharge() { - return PricingPeriod.fromId(target.getMinimumCharge()); - } - - public void setMinimumCharge(final PricingPeriod minimumCharge) { - target.setMinimumCharge(minimumCharge.ordinal()); - } - - public PricingPeriod getChargingPeriod() { - return PricingPeriod.fromId(target.getChargingPeriod()); - } - - public void setChargingPeriod(final PricingPeriod chargingPeriod) { - target.setChargingPeriod(chargingPeriod.ordinal()); - } - - public BigDecimal getPublicIp() { - return target.getPublicIp(); - } - - public void setPublicIp(final BigDecimal publicIp) { - target.setPublicIp(publicIp); - } - - public BigDecimal getVcpu() { - return target.getVcpu(); - } - - public void setVcpu(final BigDecimal vcpu) { - target.setVcpu(vcpu); - } - - public BigDecimal getMemoryGB() { - return target.getMemoryGB(); - } - - public void setMemoryGB(final BigDecimal memoryGB) { - target.setMemoryGB(memoryGB); - } - - public boolean isDefaultTemplate() { - return target.isDefaultTemplate(); - } - - public void setDefaultTemplate(final boolean defaultTemplate) { - target.setDefaultTemplate(defaultTemplate); - } - - public Date getLastUpdate() { - return target.getLastUpdate(); - } - - public void setLastUpdate(final Date lastUpdate) { - target.setLastUpdate(lastUpdate); - } - - @Override - public String toString() { - return "PricingTemplate [id=" + getId() + ", name=" + getName() + ", description=" + getDescription() - + ", hdGB =" + getHdGB() + ", standingChargePeriod =" + getStandingChargePeriod() + ", vlan = " + getVlan() - + ", chargingPeriod =" + getChargingPeriod() + ", minimumChargePeriod=" + getMinimumChargePeriod() - + ", showChangesBefore =" + isShowChangesBefore() + ", showMinimumCharge= " + isShowMinimumCharge() - + ", minimumCharge = " + getMinimumCharge() + ", publicIp = " + getPublicIp() + ", vcpu =" + getVcpu() - + ", memoryGB= " + getMemoryGB() + ", defaultTemplate= " + isDefaultTemplate() + ", lastUpdate = " - + getLastUpdate() + "]"; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java deleted file mode 100644 index 7001f58..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/config/PricingTier.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 com.google.common.base.Preconditions.checkNotNull; - -import java.math.BigDecimal; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.infrastructure.Tier; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.pricing.PricingTierDto; - -/** - * Associates an storage {@link Tier} with a {@link PricingTemplate}. - * - * @author Susana Acedo - */ -public class PricingTier extends DomainWrapper { - private Tier tier; - - private PricingTemplate pricingTemplate; - - protected PricingTier(final ApiContext context, final PricingTierDto target) { - super(context, target); - } - - // Builder - - public static Builder builder(final ApiContext context, final PricingTemplate pricingtemplate, - final Tier tier) { - return new Builder(context, pricingtemplate, tier); - } - - public static class Builder { - private ApiContext context; - - private Integer id; - - private PricingTemplate pricingTemplate; - - private Tier tier; - - private BigDecimal price; - - public Builder(final ApiContext context, final PricingTemplate pricingTemplate, final Tier tier) { - super(); - this.pricingTemplate = checkNotNull(pricingTemplate, ValidationErrors.NULL_RESOURCE + PricingTemplate.class); - this.tier = checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Tier.class); - this.context = context; - } - - public Builder price(final BigDecimal price) { - this.price = price; - return this; - } - - public PricingTier build() { - PricingTierDto dto = new PricingTierDto(); - dto.setId(id); - dto.setPrice(price); - - RESTLink link = tier.unwrap().searchLink("edit"); - checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK); - dto.addLink(new RESTLink("tier", link.getHref())); - - PricingTier pricingTier = new PricingTier(context, dto); - pricingTier.pricingTemplate = pricingTemplate; - pricingTier.tier = tier; - - return pricingTier; - } - - public static Builder fromPricingTier(final PricingTier in) { - return PricingTier.builder(in.context, in.pricingTemplate, in.tier).price(in.getPrice()); - } - } - - // Delegate methods - - public Integer getId() { - return target.getId(); - } - - public BigDecimal getPrice() { - return target.getPrice(); - } - - @Override - public String toString() { - return "PricingTier [id=" + getId() + ", price=" + getPrice() + "]"; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java index b570815..ac2400a 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java @@ -16,8 +16,6 @@ */ package org.jclouds.abiquo.domain.enterprise; -import static com.google.common.collect.Iterables.filter; - import java.util.List; import org.jclouds.abiquo.AbiquoApi; @@ -30,10 +28,7 @@ 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.strategy.enterprise.ListVirtualMachineTemplates; import org.jclouds.http.HttpResponse; @@ -142,40 +137,6 @@ public class Enterprise extends DomainWithLimitsWrapper { } /** - * 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 ImmutableList.copyOf(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: { } /** - * 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 ImmutableList.copyOf(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 @@ -259,38 +185,6 @@ public class Enterprise extends DomainWithLimitsWrapper { } /** - * 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 ImmutableList.copyOf(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: { } /** - * 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 ImmutableList.copyOf(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 @@ -381,46 +241,12 @@ public class Enterprise extends DomainWithLimitsWrapper { 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 ImmutableList.copyOf(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 ImmutableList.copyOf(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); @@ -432,29 +258,11 @@ public class Enterprise extends DomainWithLimitsWrapper { return ImmutableList.copyOf(strategy.execute(this)); } - public List listTemplates(final Predicate filter) { - ListVirtualMachineTemplates strategy = context.utils().injector().getInstance(ListVirtualMachineTemplates.class); - return ImmutableList.copyOf(strategy.execute(this, filter)); - } - - public VirtualMachineTemplate findTemplate(final Predicate filter) { - ListVirtualMachineTemplates strategy = context.utils().injector().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 ImmutableList.copyOf(filter(listAllowedDatacenters(), filter)); - } - - public Datacenter findAllowedDatacenter(final Predicate filter) { - return Iterables.getFirst(filter(listAllowedDatacenters(), filter), null); - } - /** * @see API: { return wrap(context, ExternalNetwork.class, parser.apply(response).getCollection()); } - public List listExternalNetworks(final Datacenter datacenter, - final Predicate> filter) { - return ImmutableList.copyOf(filter(listExternalNetworks(datacenter), filter)); - } - - public ExternalNetwork findExternalNetwork(final Datacenter datacenter, final Predicate> filter) { - return Iterables.getFirst(filter(listExternalNetworks(datacenter), filter), null); - } - public List listUnmanagedNetworks(final Datacenter datacenter) { DatacenterLimitsDto limitForDatacenter = getLimits(datacenter); @@ -494,16 +293,6 @@ public class Enterprise extends DomainWithLimitsWrapper { return wrap(context, UnmanagedNetwork.class, parser.apply(response).getCollection()); } - public List listUnmanagedNetworks(final Datacenter datacenter, - final Predicate> filter) { - return ImmutableList.copyOf(filter(listUnmanagedNetworks(datacenter), filter)); - } - - 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. * @@ -520,40 +309,6 @@ public class Enterprise extends DomainWithLimitsWrapper { } /** - * 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 ImmutableList.copyOf(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: { 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 ImmutableList.copyOf(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 ImmutableList.copyOf(filter(listVirtualMachines(), filter)); - } - - public VirtualMachine findReservedMachine(final Predicate filter) { - return Iterables.getFirst(filter(listVirtualMachines(), filter), null); - } - // Actions /** diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java index f8c2cf7..ba9b279 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Role.java @@ -17,7 +17,6 @@ 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; @@ -25,15 +24,11 @@ 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.rest.ApiContext; 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.ImmutableList; -import com.google.common.collect.Iterables; /** * Adds high level functionality to {@link RoleDto}. @@ -137,14 +132,6 @@ public class Role extends DomainWrapper { return wrap(context, Privilege.class, dto.getCollection()); } - public List listPrivileges(final Predicate filter) { - return ImmutableList.copyOf(filter(listPrivileges(), filter)); - } - - public Privilege findPrivileges(final Predicate filter) { - return Iterables.getFirst(filter(listPrivileges(), filter), null); - } - // Builder public static Builder builder(final ApiContext context) { diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java index 43490e3..4519f5c 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/User.java @@ -17,7 +17,6 @@ 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 java.util.StringTokenizer; @@ -36,9 +35,7 @@ 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.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; /** @@ -128,14 +125,6 @@ public class User extends DomainWrapper { return ImmutableList.copyOf(listVirtualDatacenters.execute(ids)); } - public List listPermittedVirtualDatacenters(final Predicate filter) { - return ImmutableList.copyOf(filter(listPermittedVirtualDatacenters(), filter)); - } - - public VirtualDatacenter findPermittedVirtualDatacenter(final Predicate filter) { - return Iterables.getFirst(filter(listPermittedVirtualDatacenters(), filter), null); - } - /** * Give access to all virtualdatacenters in the enterprise (requires update). */ @@ -191,14 +180,6 @@ public class User extends DomainWrapper { return wrap(context, VirtualMachine.class, machines.getCollection()); } - public List listMachines(final Predicate filter) { - return ImmutableList.copyOf(filter(listMachines(), filter)); - } - - public VirtualMachine findMachine(final Predicate filter) { - return Iterables.getFirst(filter(listMachines(), filter), null); - } - // Builder public static Builder builder(final ApiContext context, final Enterprise enterprise, final Role role) { diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java index e6f7f13..bc7e0ce 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java @@ -19,7 +19,6 @@ 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; @@ -27,6 +26,7 @@ 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.base.Predicate; import com.google.common.collect.ImmutableList; /** @@ -111,4 +111,13 @@ public class AbiquoException extends RuntimeException { public String getMessage() { return errors.toString(); } + + private static Predicate code(final String code) { + return new Predicate() { + @Override + public boolean apply(ErrorDto input) { + return input.getCode().equals(code); + } + }; + } } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java deleted file mode 100644 index cf924f2..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/AbstractPhysicalMachine.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.predicates.infrastructure.DatastorePredicates; -import org.jclouds.abiquo.predicates.infrastructure.NetworkInterfacePredicates; -import org.jclouds.rest.ApiContext; - -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; - -/** - * 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; - - /** - * Constructor to be used only by the builder. - */ - protected AbstractPhysicalMachine(final ApiContext context, final MachineDto target) { - super(context, target); - } - - 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); - } - - public List getNetworkInterfaces() { - return wrap(context, NetworkInterface.class, target.getNetworkInterfaces().getCollection()); - } - - public NetworkInterface findNetworkInterface(final String name) { - return find(getNetworkInterfaces(), NetworkInterfacePredicates.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 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 String getDescription() { - return target.getDescription(); - } - - // Aux operations - - public NetworkInterface findAvailableVirtualSwitch(final String virtualswitch) { - return find(getNetworkInterfaces(), NetworkInterfacePredicates.name(virtualswitch)); - } - - @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() + ", description=" - + getDescription() + "]"; - } - -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java deleted file mode 100644 index 89c3e21..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Blade.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.AbiquoApi; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.rest.ApiContext; - -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 ApiContext 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); - - HttpResponse response = context.getApi().get(link); - - ParseXMLWithJAXB parser = new ParseXMLWithJAXB(context.utils().xml(), - 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/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java deleted file mode 100644 index 6735df2..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/BladeLocatorLed.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; - -import org.jclouds.rest.ApiContext; - -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 - */ -public class BladeLocatorLed extends DomainWrapper { - /** - * Constructor to be used only by the builder. - */ - protected BladeLocatorLed(final ApiContext 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/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java index 1debb12..25f8664 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java @@ -16,9 +16,7 @@ */ package org.jclouds.abiquo.domain.infrastructure; -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 static com.google.common.collect.Iterables.transform; import java.util.List; @@ -35,7 +33,7 @@ import org.jclouds.abiquo.domain.network.Network; import org.jclouds.abiquo.domain.network.NetworkServiceType; import org.jclouds.abiquo.domain.network.PrivateNetwork; import org.jclouds.abiquo.domain.network.options.NetworkOptions; -import org.jclouds.abiquo.predicates.network.NetworkServiceTypePredicates; +import org.jclouds.abiquo.predicates.NetworkServiceTypePredicates; import org.jclouds.rest.ApiContext; import com.abiquo.model.enumerator.HypervisorType; @@ -57,8 +55,6 @@ 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.NetworkServiceTypeDto; import com.abiquo.server.core.infrastructure.network.NetworkServiceTypesDto; import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; @@ -69,7 +65,6 @@ 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.Function; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; /** @@ -183,38 +178,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 getFirst(filter(listRacks(), filter), null); - } - - /** * Retrieve a single unmanaged rack. * * @param id @@ -233,70 +196,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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. - */ - 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. - */ - public List listManagedRacks(final Predicate filter) { - return ImmutableList.copyOf(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. - */ - public ManagedRack findManagedRack(final Predicate filter) { - return 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. - */ - 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 @@ -312,34 +211,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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. - */ - public List listSupportedStorageDevices(final Predicate filter) { - return ImmutableList.copyOf(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. - */ - public StorageDeviceMetadata findSupportedStorageDevice(final Predicate filter) { - return getFirst(filter(listSupportedStorageDevices(), filter), null); - } - - /** * Retrieve the list of storage devices in this datacenter. * * @see API: { } /** - * 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. - */ - public List listStorageDevices(final Predicate filter) { - return ImmutableList.copyOf(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. - */ - public StorageDevice findStorageDevice(final Predicate filter) { - return getFirst(filter(listStorageDevices(), filter), null); - } - - /** * Retrieve a single storage device. * * @param id @@ -415,30 +254,6 @@ public class Datacenter extends DomainWrapper { } /** - * Retrieve a filtered list of network service types in this datacenter. - * - * @param filter - * Filter to be applied to the list. - * @return Filtered list of storage devices in this datacenter. - */ - public List listNetworkServiceTypes(final Predicate filter) { - return ImmutableList.copyOf(filter(listNetworkServiceTypes(), filter)); - } - - /** - * Retrieve the first network service type matching the filter within the - * list of nsts in this datacenter. - * - * @param filter - * Filter to be applied to the list. - * @return First network service type matching the filter or - * null if there is none. - */ - public NetworkServiceType findNetworkServiceType(final Predicate filter) { - return getFirst(filter(listNetworkServiceTypes(), filter), null); - } - - /** * Retrieve a single network service type. * * @param id @@ -476,38 +291,6 @@ public class Datacenter extends DomainWrapper { 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 ImmutableList.copyOf(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 getFirst(filter(listRemoteServices(), filter), null); - } - private void createRemoteServices() { createRemoteService(RemoteServiceType.BPM_SERVICE); createRemoteService(RemoteServiceType.DHCP_SERVICE); @@ -539,42 +322,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 getFirst(filter(listLimits(), filter), null); - } - - /** * Retrieve the list of tiers in ths datacenter. * * @see API: { } /** - * 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. - */ - public List listTiers(final Predicate filter) { - return ImmutableList.copyOf(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. - */ - public Tier findTier(final Predicate filter) { - return getFirst(filter(listTiers(), filter), null); - } - - /** * Retrieve the list of public, external and unmanaged networks in this * datacenter. * @@ -639,38 +353,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 getFirst(filter(listNetworks(), filter), null); - } - - /** * Retrieve the list of networks of this datacenter matching the given type. * * @param type @@ -688,43 +370,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 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}, @@ -781,42 +426,9 @@ public class Datacenter extends DomainWrapper { */ 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. - */ - public List listAvailableHypervisors(final Predicate filter) { - return ImmutableList.copyOf(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. - */ - public HypervisorType findHypervisor(final Predicate filter) { - return getFirst(filter(listAvailableHypervisors(), filter), null); - } - private List getHypervisorTypes(final HypervisorTypesDto dtos) { return ImmutableList.copyOf(transform(dtos.getCollection(), new Function() { @Override @@ -1082,48 +694,6 @@ public class Datacenter extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 getFirst(filter(listTemplatesInRepository(enterprise), filter), null); - } - - /** * Retrieve a single virtual machine template in of this datacenter from the * given enterprise. * diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java deleted file mode 100644 index 4c63125..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Fsm.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; - -import org.jclouds.rest.ApiContext; - -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 - */ -public class Fsm extends DomainWrapper { - /** - * Constructor to be used only by the builder. - */ - protected Fsm(final ApiContext 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/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java deleted file mode 100644 index 78ce59a..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/LogicServer.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; - -import org.jclouds.rest.ApiContext; - -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 - */ -public class LogicServer extends DomainWrapper { - /** - * Constructor to be used only by the builder. - */ - protected LogicServer(final ApiContext 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/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java index 3b7b0ad..dd851a8 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java @@ -17,17 +17,14 @@ 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.domain.DomainWrapper; 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.predicates.infrastructure.NetworkInterfacePredicates; import org.jclouds.abiquo.reference.ValidationErrors; import org.jclouds.abiquo.reference.rest.ParentLinkName; import org.jclouds.http.HttpResponse; @@ -35,6 +32,7 @@ import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.rest.ApiContext; import com.abiquo.model.enumerator.HypervisorType; +import com.abiquo.model.enumerator.MachineIpmiState; import com.abiquo.model.enumerator.MachineState; import com.abiquo.model.rest.RESTLink; import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; @@ -42,12 +40,10 @@ 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.MachineIpmiStateDto; import com.abiquo.server.core.infrastructure.MachineStateDto; import com.abiquo.server.core.infrastructure.RackDto; import com.abiquo.server.core.infrastructure.network.NetworkInterfacesDto; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.inject.TypeLiteral; /** @@ -60,7 +56,13 @@ import com.google.inject.TypeLiteral; * href="http://community.abiquo.com/display/ABI20/MachineResource"> * http://community.abiquo.com/display/ABI20/MachineResource */ -public class Machine extends AbstractPhysicalMachine { +public class Machine 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; + /** The rack where the machine belongs. */ protected Rack rack; @@ -91,7 +93,15 @@ public class Machine extends AbstractPhysicalMachine { target = context.getApi().getInfrastructureApi().createMachine(rack.unwrap(), target); } - @Override + 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(); @@ -99,6 +109,11 @@ public class Machine extends AbstractPhysicalMachine { return state; } + public MachineIpmiState checkIpmi() { + MachineIpmiStateDto dto = context.getApi().getInfrastructureApi().checkMachineIpmiState(target); + return dto.getState(); + } + // Parent access /** * Retrieve the unmanaged rack where the machine is. @@ -123,26 +138,14 @@ public class Machine extends AbstractPhysicalMachine { // 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); - } - - @Override public List getNetworkInterfaces() { return wrap(context, NetworkInterface.class, target.getNetworkInterfaces().getCollection()); } - @Override - public NetworkInterface findNetworkInterface(final String name) { - return find(getNetworkInterfaces(), NetworkInterfacePredicates.name(name), null); - } - /** * Gets the list of virtual machines in the physical machine. * @@ -160,30 +163,10 @@ public class Machine extends AbstractPhysicalMachine { 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 ImmutableList.copyOf(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); + public VirtualMachine getVirtualMachine(final Integer virtualMachineId) { + VirtualMachineWithNodeExtendedDto vm = context.getApi().getInfrastructureApi() + .getVirtualMachine(target, virtualMachineId); + return wrap(context, VirtualMachine.class, vm); } /** @@ -205,34 +188,6 @@ public class Machine extends AbstractPhysicalMachine { } /** - * Gets the list of virtual machines in the physical machine matching the - * given filter synchronizing 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 ImmutableList.copyOf(filter(listVirtualMachines(), filter)); - } - - /** - * Gets a single virtual machine in the physical machine matching the given - * filter synchronizing 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 @@ -508,14 +463,165 @@ public class Machine extends AbstractPhysicalMachine { // 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 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 String getDescription() { + return target.getDescription(); + } + 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); + @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() + ", description=" + + getDescription() + "]"; } } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java deleted file mode 100644 index 29d5a39..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/ManagedRack.java +++ /dev/null @@ -1,708 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.reference.ValidationErrors; - -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.rest.ApiContext; - -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.ImmutableList; -import com.google.common.collect.Iterables; - -/** - * Adds high level functionality to {@link RackDto}. - * - * @author Ignasi Barrera - * @author Francesc Montserrat - * @see API: - * http://community.abiquo.com/display/ABI20/RackResource - */ -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 ApiContext 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 ImmutableList.copyOf(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 ImmutableList.copyOf(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 ImmutableList.copyOf(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 ImmutableList.copyOf(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 ApiContext context, final Datacenter datacenter) { - return new Builder(context, datacenter); - } - - public static class Builder { - private ApiContext 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 ApiContext 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/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java deleted file mode 100644 index df8cdb3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Organization.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; - -import org.jclouds.rest.ApiContext; - -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 - */ -public class Organization extends DomainWrapper { - /** - * Constructor to be used only by the builder. - */ - protected Organization(final ApiContext 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/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java index 5c2dc21..d8f31c2 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Rack.java @@ -17,7 +17,6 @@ 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; @@ -30,9 +29,6 @@ import org.jclouds.rest.ApiContext; 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.ImmutableList; -import com.google.common.collect.Iterables; /** * Adds high level functionality to {@link RackDto}. Represents unmanaged racks @@ -137,35 +133,6 @@ public class Rack extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java index 3fb2f6b..166cf82 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StorageDevice.java @@ -17,7 +17,6 @@ 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; @@ -25,7 +24,6 @@ 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.rest.ParentLinkName; import org.jclouds.rest.ApiContext; @@ -34,9 +32,6 @@ 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.ImmutableList; -import com.google.common.collect.Iterables; /** * Adds high level functionality to {@link StorageDeviceDto}. The Storage Device @@ -140,39 +135,6 @@ public class StorageDevice extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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). * @@ -189,39 +151,6 @@ public class StorageDevice extends DomainWrapper { } /** - * 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 ImmutableList.copyOf(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 @@ -262,39 +191,6 @@ public class StorageDevice extends DomainWrapper { 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 ImmutableList.copyOf(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 ApiContext context, final Datacenter datacenter) { return new Builder(context, datacenter); } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java index e88edc7..0bc615a 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Tier.java @@ -16,22 +16,16 @@ */ 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.domain.DomainWrapper; - import org.jclouds.abiquo.reference.rest.ParentLinkName; import org.jclouds.rest.ApiContext; 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.ImmutableList; -import com.google.common.collect.Iterables; /** * Adds high level functionality to {@link TierDto}. The Tier Resource offers @@ -84,38 +78,6 @@ public class Tier extends DomainWrapper { 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 ImmutableList.copyOf(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 /** diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java index 3e1eeec..0f1a4e7 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/domain/network/Network.java @@ -25,16 +25,14 @@ import java.util.List; 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.predicates.IpPredicates; import org.jclouds.abiquo.reference.ValidationErrors; import org.jclouds.rest.ApiContext; import com.abiquo.model.enumerator.NetworkType; import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; import com.google.common.base.Function; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; /** * Adds generic high level functionality to {@link VLANNetworkDto}. @@ -67,20 +65,8 @@ public abstract class Network> extends DomainWrapper listIps(final Predicate filter) { - return ImmutableList.copyOf(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); + return ImmutableList.copyOf(filter(listIps(), IpPredicates. notUsed())); } // Builder diff --git a/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java b/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java deleted file mode 100644 index aac4273..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/AbstractEventHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java b/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java deleted file mode 100644 index 116e3cc..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/events/handlers/BlockingEventHandler.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java deleted file mode 100644 index 81d7516..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/CompletedEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java deleted file mode 100644 index 3a7d5b9..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/FailedEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java deleted file mode 100644 index 7cf46d3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/MonitorEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java deleted file mode 100644 index d86391c..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/events/monitor/TimeoutEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java b/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java index 953e216..391d48d 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/features/InfrastructureApi.java @@ -39,15 +39,12 @@ 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.infrastructure.ParseDatacenterId; import org.jclouds.abiquo.http.filters.AbiquoAuthentication; import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; @@ -68,24 +65,16 @@ 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.NetworkServiceTypeDto; @@ -538,280 +527,6 @@ public interface InfrastructureApi extends Closeable { @DELETE void deleteRack(@EndpointLink("edit") @BinderParam(BindToPath.class) RackDto rack); - /*********************** Managed Rack **********************/ - - /** - * List all managed racks for a datacenter. - * - * @param datacenter - * The datacenter. - * @return The list of managed racks for the datacenter. - */ - @Named("ucs:listracks") - @GET - @Consumes(UcsRacksDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - UcsRacksDto listManagedRacks(@EndpointLink("racks") @BinderParam(BindToPath.class) 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. - */ - @Named("ucs:createrack") - @POST - @Produces(UcsRackDto.BASE_MEDIA_TYPE) - @Consumes(UcsRackDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - UcsRackDto createManagedRack(@EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter, - @BinderParam(BindToXMLPayload.class) 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. - */ - @Named("ucs:getrack") - @GET - @Consumes(UcsRackDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - UcsRackDto getManagedRack(@EndpointLink("racks") @BinderParam(BindToPath.class) DatacenterDto datacenter, - @BinderParam(AppendToPath.class) Integer rackId); - - /** - * Updates an existing managed rack from the given datacenter. - * - * @param rack - * The new attributes for the rack. - * @return The updated rack. - */ - @Named("ucs:updaterack") - @PUT - @Consumes(UcsRackDto.BASE_MEDIA_TYPE) - @Produces(UcsRackDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - UcsRackDto updateManagedRack(@EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) UcsRackDto rack); - - /** - * List all service profiles of the ucs rack. - * - * @param rack - * The ucs rack. - * @return The list of service profiles for the rack. - */ - @Named("ucs:listserviceprofiles") - @GET - @Consumes(LogicServersDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - LogicServersDto listServiceProfiles(@EndpointLink("logicservers") @BinderParam(BindToPath.class) 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. - */ - @Named("ucs:listserviceprofiles") - @GET - @Consumes(LogicServersDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - LogicServersDto listServiceProfiles(@EndpointLink("logicservers") @BinderParam(BindToPath.class) 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. - */ - @Named("ucs:listserviceprofiletemplates") - @GET - @Consumes(LogicServersDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - LogicServersDto listServiceProfileTemplates( - @EndpointLink("ls-templates") @BinderParam(BindToPath.class) 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. - */ - @Named("ucs:listserviceproviletemplates") - @GET - @Consumes(LogicServersDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - LogicServersDto listServiceProfileTemplates( - @EndpointLink("ls-templates") @BinderParam(BindToPath.class) UcsRackDto rack, FilterOptions options); - - /** - * List all organizations of the ucs rack. - * - * @param rack - * The ucs rack. - * @return The list of organizations for the rack. - */ - @Named("ucs:listorganizations") - @GET - @Consumes(OrganizationsDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - OrganizationsDto listOrganizations(@EndpointLink("organizations") @BinderParam(BindToPath.class) 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. - */ - @Named("ucs:listorganizations") - @GET - @Consumes(OrganizationsDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - OrganizationsDto listOrganizations(@EndpointLink("organizations") @BinderParam(BindToPath.class) UcsRackDto rack, - FilterOptions options); - - /** - * Clone a service profile. - * - * @param rack - * The managed rack where the 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. - */ - @Named("ucs:clonelogicserver") - @POST - void cloneLogicServer(@EndpointLink("ls-clone") @BinderParam(BindToPath.class) UcsRackDto rack, - @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer, - @BinderParam(BindOrganizationParameters.class) OrganizationDto organization, - @QueryParam("newName") String newName); - - /** - * Delete a service profile. - * - * @param rack - * The managed rack where the service profile will be created. - * @param logicServer - * The original logic server. - */ - @Named("ucs:deletelogicserver") - @POST - void deleteLogicServer(@EndpointLink("ls-delete") @BinderParam(BindToPath.class) UcsRackDto rack, - @BinderParam(BindLogicServerParameters.class) 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. - */ - @Named("ucs:associatelogicserver") - @POST - void associateLogicServer(@EndpointLink("ls-associate") @BinderParam(BindToPath.class) UcsRackDto rack, - @BinderParam(BindLogicServerParameters.class) LogicServerDto logicServer, - @BinderParam(BindOrganizationParameters.class) OrganizationDto organization, - @QueryParam("bladeDn") 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. - */ - @Named("ucs:associatetemplate") - @POST - void 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); - - /** - * 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. - */ - @Named("ucs:cloneandassociatelogicserver") - @POST - void 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); - - /** - * Dissociate a service profile from a blade. - * - * @param rack - * The managed rack where the service profile is. - * @param logicServer - * The logic server. - */ - @Named("ucs:dissociatelogicserver") - @POST - void dissociateLogicServer(@EndpointLink("ls-dissociate") @BinderParam(BindToPath.class) UcsRackDto rack, - @BinderParam(BindLogicServerParameters.class) 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. - */ - @Named("ucs:listfsms") - @GET - @Consumes(FsmsDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - FsmsDto listFsms(@EndpointLink("fsm") @BinderParam(BindToPath.class) UcsRackDto rack, @QueryParam("dn") String dn); - /*********************** Remote Service ********************** */ /** @@ -1038,74 +753,6 @@ public interface InfrastructureApi extends Closeable { @JAXBResponseParser MachinesDto listMachines(@EndpointLink("machines") @BinderParam(BindToPath.class) RackDto rack); - /*********************** Blade ***********************/ - - /** - * Power off a physical machine in a UCS rack. - * - * @param machine - * The physical machine. - */ - @Named("machine:poweroff") - @PUT - void powerOff(@EndpointLink("poweroff") @BinderParam(BindToPath.class) MachineDto machine); - - /** - * Power on a physical machine in a UCS rack. - * - * @param machine - * The physical machine. - */ - @Named("machine:poweron") - @PUT - void powerOn(@EndpointLink("poweron") @BinderParam(BindToPath.class) MachineDto machine); - - /** - * Get the logic server associated with a machine in a Cisco UCS rack. - * - * @param machine - * The physical machine. - * @return The logic server. - */ - @Named("machine:getlogicserver") - @GET - @Consumes(LogicServerDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - LogicServerDto getLogicServer(@EndpointLink("logicserver") @BinderParam(BindToPath.class) MachineDto machine); - - /** - * Turn off locator led of a physical machine in a UCS rack. - * - * @param machine - * The physical machine. - */ - @Named("machine:ledon") - @POST - void ledOn(@EndpointLink("ledon") @BinderParam(BindToPath.class) MachineDto machine); - - /** - * Light locator led of a physical machine in a UCS rack. - * - * @param machine - * The physical machine. - */ - @Named("machine:ledoff") - @POST - void ledOff(@EndpointLink("ledoff") @BinderParam(BindToPath.class) MachineDto machine); - - /** - * Get led locator info from a physical machine in a UCS rack. - * - * @param machine - * The physical machine. - * @return Led locator information. - */ - @Named("machine:getlocatorled") - @GET - @Consumes(BladeLocatorLedDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - BladeLocatorLedDto getLocatorLed(@EndpointLink("led") @BinderParam(BindToPath.class) MachineDto machine); - /** * List all virtual machines in a physical machine. * diff --git a/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java b/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java deleted file mode 100644 index 83da1ed..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/PricingApi.java +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.Closeable; - -import javax.inject.Named; -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.Fallbacks.NullOnNotFoundOr404; -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.Fallback; -import org.jclouds.rest.annotations.JAXBResponseParser; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.binders.BindToXMLPayload; - -import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; -import com.abiquo.server.core.pricing.CostCodeDto; -import com.abiquo.server.core.pricing.CostCodesDto; -import com.abiquo.server.core.pricing.CurrenciesDto; -import com.abiquo.server.core.pricing.CurrencyDto; -import com.abiquo.server.core.pricing.PricingCostCodeDto; -import com.abiquo.server.core.pricing.PricingCostCodesDto; -import com.abiquo.server.core.pricing.PricingTemplateDto; -import com.abiquo.server.core.pricing.PricingTemplatesDto; -import com.abiquo.server.core.pricing.PricingTierDto; -import com.abiquo.server.core.pricing.PricingTiersDto; - -/** - * Provides synchronous access to Abiquo Pricing API. - * - * @see API: - * http://community.abiquo.com/display/ABI20/APIReference - * @author Ignasi Barrera - * @author Susana Acedo - */ -@RequestFilters({ AbiquoAuthentication.class, AppendApiVersionToMediaType.class }) -@Path("/config") -public interface PricingApi extends Closeable { - - /*********************** Currency ********************** */ - - /** - * List all currencies - * - * @return The list of currencies - */ - @Named("currency:list") - @GET - @Path("/currencies") - @Consumes(CurrenciesDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CurrenciesDto listCurrencies(); - - /** - * Get the given currency - * - * @param currencyId - * The id of the currency - * @return The currency - */ - @Named("currency:get") - @GET - @Path("/currencies/{currency}") - @Consumes(CurrencyDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - CurrencyDto getCurrency(@PathParam("currency") Integer currencyId); - - /** - * Create a new currency - * - * @param currency - * The currency to be created. - * @return The created currency. - */ - @Named("currency:create") - @POST - @Path("/currencies") - @Produces(CurrencyDto.BASE_MEDIA_TYPE) - @Consumes(CurrencyDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CurrencyDto createCurrency(@BinderParam(BindToXMLPayload.class) CurrencyDto currency); - - /** - * Updates an existing currency - * - * @param currency - * The new attributes for the currency - * @return The updated currency - */ - @Named("currency:update") - @PUT - @Produces(CurrencyDto.BASE_MEDIA_TYPE) - @Consumes(CurrencyDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CurrencyDto updateCurrency(@EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) CurrencyDto currency); - - /** - * Deletes an existing currency - * - * @param currency - * The currency to delete - */ - @Named("currency:delete") - @DELETE - void deleteCurrency(@EndpointLink("edit") @BinderParam(BindToPath.class) CurrencyDto currency); - - /*********************** CostCode ********************** */ - - /** - * List all costcodes - * - * @return The list of costcodes - */ - @Named("costcode:list") - @GET - @Path("/costcodes") - @Consumes(CostCodesDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CostCodesDto listCostCodes(); - - /** - * Get the given costcode - * - * @param costcodeId - * The id of the costcode - * @return The costcode - */ - @Named("costcode:get") - @GET - @Path("/costcodes/{costcode}") - @Consumes(CostCodeDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - CostCodeDto getCostCode(@PathParam("costcode") Integer costcodeId); - - /** - * Create a new costcode - * - * @param costcode - * The costcode to be created. - * @return The created costcode. - */ - @Named("costcode:create") - @POST - @Path("/costcodes") - @Produces(CostCodeDto.BASE_MEDIA_TYPE) - @Consumes(CostCodeDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CostCodeDto createCostCode(@BinderParam(BindToXMLPayload.class) CostCodeDto costcode); - - /** - * Updates an existing costcode - * - * @param costcode - * The new attributes for the costcode - * @return The updated costcode - */ - @Named("costcode:update") - @PUT - @Produces(CostCodeDto.BASE_MEDIA_TYPE) - @Consumes(CostCodeDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CostCodeDto updateCostCode(@EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) CostCodeDto costcode); - - /** - * Deletes an existing costcode - * - * @param currency - * The costcode to delete - */ - @Named("costcode:delete") - @DELETE - void deleteCostCode(@EndpointLink("edit") @BinderParam(BindToPath.class) CostCodeDto costcode); - - /*********************** PricingTemplate ********************** */ - - /** - * List all pricingtemplates - * - * @return The list of pricingtemplates - */ - @Named("pricingtemplate:list") - @GET - @Path("/pricingtemplates") - @Consumes(PricingTemplatesDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - PricingTemplatesDto listPricingTemplates(); - - /** - * Get the given pricingtemplate - * - * @param pricingTemplateId - * The id of the pricingtemplate - * @return The pricingtemplate - */ - @Named("pricingtemplate:get") - @GET - @Path("/pricingtemplates/{pricingtemplate}") - @Consumes(PricingTemplateDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - PricingTemplateDto getPricingTemplate(@PathParam("pricingtemplate") Integer pricingTemplateId); - - /** - * Create a new pricing template - * - * @param pricingtemplate - * The pricingtemplate to be created - * @return The created pricingtemplate - */ - @Named("pricingtemplate:create") - @POST - @Path("/pricingtemplates") - @Produces(PricingTemplateDto.BASE_MEDIA_TYPE) - @Consumes(PricingTemplateDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - PricingTemplateDto createPricingTemplate(@BinderParam(BindToXMLPayload.class) PricingTemplateDto pricingtemplate); - - /** - * Updates an existing pricing template - * - * @param pricingtemplate - * The new attributes for the pricingtemplate - * @return The updated pricingtemplate - */ - @Named("pricingtemplate:update") - @PUT - @Produces(PricingTemplateDto.BASE_MEDIA_TYPE) - @Consumes(PricingTemplateDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - PricingTemplateDto updatePricingTemplate( - @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingTemplateDto pricingtemplate); - - /** - * Deletes an existing pricingtemplate - * - * @param pricingtemplate - * The pricingtemplate to delete - */ - @Named("pricingtemplate:delete") - @DELETE - void deletePricingTemplate(@EndpointLink("edit") @BinderParam(BindToPath.class) PricingTemplateDto pricingtemplate); - - /*********************** CostCodeCurrency ********************** */ - - /** - * Get the given costcodecurrency - * - * @param costcodecurrencyId - * The id of the costcodecurrency - * @return The costcodecurrency - */ - @Named("costcodecurrency:get") - @GET - @Path("/costcodes/{costcode}/currencies") - @Consumes(CostCodeCurrenciesDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - CostCodeCurrenciesDto getCostCodeCurrencies(@PathParam("costcode") Integer costcodeId, - @QueryParam("idCurrency") Integer currencyId); - - /** - * Updates cost code currencies - * - * @param costcodeCurrency - * The new attributes for the costcodecurrencies - * @return The updated costcodecurrencies - */ - @Named("costcodecurrency:update") - @PUT - @Path("/costcodes/{costcode}/currencies") - @Produces(CostCodeCurrenciesDto.BASE_MEDIA_TYPE) - @Consumes(CostCodeCurrenciesDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - CostCodeCurrenciesDto updateCostCodeCurrencies(@PathParam("costcode") Integer costcodeId, - @BinderParam(BindToXMLPayload.class) CostCodeCurrenciesDto costcodecurrencies); - - /*********************** PricingTemplateCostCode ********************** */ - - /** - * Get the pricing cost codes for a pricing template - * - * @param pricingTemplateId - * @return pricingcostcodes - */ - @Named("pricingcostcode:get") - @GET - @Path("/pricingtemplates/{pricingtemplate}/costcodes") - @Consumes(PricingCostCodesDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - PricingCostCodesDto getPricingCostCodes(@PathParam("pricingtemplate") Integer pricingTemplateId); - - /** - * Get the given pricing cost code - * - * @param pricingCostCodeId - * the id of the pricing cost code - * @return The pricingcostcode - */ - @Named("pricingcostcode:get") - @GET - @Path("/pricingtemplates/{pricingtemplate}/costcodes/{costcode}") - @Consumes(PricingCostCodeDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - PricingCostCodeDto getPricingCostCode(@PathParam("pricingtemplate") Integer pricingTemplateId, - @PathParam("costcode") Integer pricingCostcodeId); - - /** - * Updates an existing pricingcostcode - * - * @param costcodeCurrency - * The new attributes for the pricingcostcode - * @return The updated pricingcostcode - */ - @Named("pricingcostcode:update") - @PUT - @Path("/pricingtemplates/{pricingtemplate}/costcodes/{costcode}") - @Produces(PricingCostCodeDto.BASE_MEDIA_TYPE) - @Consumes(PricingCostCodeDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - PricingCostCodeDto updatePricingCostCode( - @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingCostCodeDto pricingcostcode, - @PathParam("pricingtemplate") Integer pricingTemplateId, @PathParam("costcode") Integer pricingCostcodeId); - - /*********************** PricingTemplateTier ********************** */ - - /** - * Get the pricing tiers for a pricing template - * - * @param pricingTemplateId - * @return pricingtiers - */ - @Named("pricingtier:get") - @GET - @Path("/pricingtemplates/{pricingtemplate}/tiers") - @Consumes(PricingTiersDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - PricingTiersDto getPricingTiers(@PathParam("pricingtemplate") Integer pricingTemplateId); - - /** - * Get the given pricing tier - * - * @param pricingTierId - * The id of the pricing tier - * @return The pricingtier - */ - @Named("pricingtier:get") - @GET - @Path("/pricingtemplates/{pricingtemplate}/tiers/{tier}") - @Consumes(PricingTierDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - @Fallback(NullOnNotFoundOr404.class) - PricingTierDto getPricingTier(@PathParam("pricingtemplate") Integer pricingTemplateId, - @PathParam("tier") Integer pricingTierId); - - /** - * Updates an existing pricing tier - * - * @param costcodeCurrency - * The new attributes for the pricing tier - * @return The updated pricing tier - */ - @Named("pricingtier:update") - @PUT - @Path("/pricingtemplates/{pricingtemplate}/tiers/{tier}") - @Produces(PricingTierDto.BASE_MEDIA_TYPE) - @Consumes(PricingTierDto.BASE_MEDIA_TYPE) - @JAXBResponseParser - PricingTierDto updatePricingTier( - @EndpointLink("edit") @BinderParam(BindToXMLPayloadAndPath.class) PricingTierDto pricingtier, - @PathParam("pricingtemplate") Integer pricingTemplateId, @PathParam("tier") Integer pricingTierId); -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java b/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java index 836b98b..2278708 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/features/services/AdministrationService.java @@ -28,7 +28,6 @@ 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; /** @@ -47,17 +46,6 @@ public interface AdministrationService { 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); @@ -69,17 +57,6 @@ public interface AdministrationService { */ 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 ***********************/ /** @@ -88,17 +65,6 @@ public interface AdministrationService { 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); @@ -117,17 +83,6 @@ public interface AdministrationService { 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); @@ -140,17 +95,6 @@ public interface AdministrationService { 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); - - /** * Get a privilege given its id. * * @param privilegeId @@ -187,17 +131,6 @@ public interface AdministrationService { */ 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 ***********************/ /** @@ -206,17 +139,6 @@ public interface AdministrationService { 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. */ @@ -235,17 +157,6 @@ public interface AdministrationService { 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); - - /** * Get the category identified by the given id. * * @param categoryId diff --git a/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java b/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java index c81c2fa..fc1aeed 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/features/services/CloudService.java @@ -24,7 +24,6 @@ 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; /** @@ -53,17 +52,6 @@ public interface CloudService { 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); @@ -80,16 +68,6 @@ public interface CloudService { */ 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 ***********************/ /** @@ -97,13 +75,4 @@ public interface CloudService { */ 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/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java b/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java index 4602c5a..2a3d558 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/features/services/MonitoringService.java @@ -18,13 +18,13 @@ 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 org.jclouds.abiquo.monitor.handlers.AbstractEventHandler; import com.google.common.base.Function; import com.google.inject.ImplementedBy; diff --git a/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java b/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java deleted file mode 100644 index 1c2004b..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/services/PricingService.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.Collection; - -import org.jclouds.abiquo.domain.config.CostCode; -import org.jclouds.abiquo.domain.config.CostCodeCurrency; -import org.jclouds.abiquo.domain.config.Currency; -import org.jclouds.abiquo.domain.config.PricingCostCode; -import org.jclouds.abiquo.domain.config.PricingTemplate; -import org.jclouds.abiquo.domain.config.PricingTier; -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); - - /** - * Get the currency with the given id. - * - * @param currencyId - * The id of the currency to get. - * @return The currency with the gicen id. - */ - Currency getCurrency(final Integer currencyId); - - /*********************** CostCode ***********************/ - - /** - * Get the list of costcodes. - */ - Iterable listCostCodes(); - - /** - * Get the list of costcodes matching the given filter. - */ - Iterable listCostCodes(final Predicate filter); - - /** - * Get the first costcodes that matches the given filter or null - * if none is found. - */ - CostCode findCostCode(final Predicate filter); - - /** - * Get a cost code given its id. - * - * @param costCodeId - * The id of the cost code. - * @return The cost code. - */ - CostCode getCostCode(Integer costCodeId); - - /*********************** PricingTemplate ***********************/ - - /** - * Get the list of pricingtemplates. - */ - Iterable listPricingTemplates(); - - /** - * Get the list of pricingtemplates matching the given filter. - */ - Iterable listPricingTemplates(final Predicate filter); - - /** - * Get the first pricingtemplates that matches the given filter or - * null if none is found. - */ - PricingTemplate findPricingTemplate(final Predicate filter); - - /** - * Get a pricing template given its id. - * - * @param pricingTemplateId - * The id of the pricing template. - * @return The pricing template. - */ - PricingTemplate getPricingTemplate(Integer pricingTemplateId); - - /*********************** CostCodeCurrency ***********************/ - - /** - * Get a cost code currency - */ - Iterable getCostCodeCurrencies(Integer costcodeid, Integer currencyid); - - /*********************** PricingCostCode ***********************/ - - /** - * Get pricing cost codes - */ - Collection getPricingCostCodes(Integer pricingTemplateId); - - /** - * Get a pricing cost code - */ - PricingCostCode getPricingCostCode(Integer pricingTemplateId, Integer pricingCostCodeId); - - /*********************** PricingTier ***********************/ - - /** - * Get pricing tiers - */ - Collection getPricingTiers(Integer pricingTemplateId); - - /** - * Get a pricing tier - */ - PricingTier getPricingTier(Integer pricingTemplateId, Integer pricingTierId); - -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java b/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java index 3473468..7588879 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/features/services/SearchService.java @@ -22,8 +22,6 @@ 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; @@ -31,7 +29,6 @@ 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; @@ -125,26 +122,4 @@ public interface SearchService { * 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/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java b/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java index 66a541c..9ab82e4 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/internal/AbiquoContextImpl.java @@ -28,7 +28,6 @@ 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; @@ -56,21 +55,17 @@ public class AbiquoContextImpl extends ComputeServiceContextImpl implements Abiq private final EventService eventService; - private final PricingService pricingService; - @Inject public AbiquoContextImpl(@Provider final Context wrapped, @Provider final TypeToken wrappedType, final ComputeService computeService, final Utils utils, final ApiContext providerSpecificContext, final AdministrationService administrationService, final CloudService cloudService, - final SearchService searchService, final MonitoringService monitoringService, final EventService eventService, - final PricingService pricingService) { + final SearchService searchService, final MonitoringService monitoringService, final EventService eventService) { 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 @@ -102,9 +97,4 @@ public class AbiquoContextImpl extends ComputeServiceContextImpl implements Abiq public EventService getEventService() { return eventService; } - - @Override - public PricingService getPricingService() { - return pricingService; - } } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java index b5bb885..ceffaa4 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseAdministrationService.java @@ -17,7 +17,6 @@ package org.jclouds.abiquo.internal; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.getFirst; import static org.jclouds.abiquo.domain.DomainWrapper.wrap; @@ -57,9 +56,7 @@ import com.abiquo.server.core.enterprise.RolesDto; import com.abiquo.server.core.infrastructure.DatacenterDto; import com.abiquo.server.core.infrastructure.DatacentersDto; 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. @@ -99,16 +96,6 @@ public class BaseAdministrationService implements AdministrationService { } @Override - public Iterable listDatacenters(final Predicate filter) { - return filter(listDatacenters(), filter); - } - - @Override - public Datacenter findDatacenter(final Predicate filter) { - return getFirst(listDatacenters(filter), null); - } - - @Override public Datacenter getDatacenter(final Integer datacenterId) { DatacenterDto datacenter = context.getApi().getInfrastructureApi().getDatacenter(datacenterId); return wrap(context, Datacenter.class, datacenter); @@ -121,16 +108,6 @@ public class BaseAdministrationService implements AdministrationService { 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 @@ -140,16 +117,6 @@ public class BaseAdministrationService implements AdministrationService { } @Override - public Iterable listEnterprises(final Predicate filter) { - return filter(listEnterprises(), 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); @@ -175,16 +142,6 @@ public class BaseAdministrationService implements AdministrationService { } @Override - public Iterable listRoles(final Predicate filter) { - return filter(listRoles(), filter); - } - - @Override - public Role findRole(final Predicate filter) { - return getFirst(listRoles(filter), null); - } - - @Override public Role getRole(final Integer roleId) { RoleDto role = context.getApi().getAdminApi().getRole(roleId); return wrap(context, Role.class, role); @@ -199,16 +156,6 @@ public class BaseAdministrationService implements AdministrationService { } @Override - public Iterable listPrivileges(final Predicate filter) { - return filter(listPrivileges(), filter); - } - - @Override - public Privilege findPrivilege(final Predicate filter) { - return getFirst(listPrivileges(filter), null); - } - - @Override public Privilege getPrivilege(Integer privilegeId) { PrivilegeDto result = context.getApi().getConfigApi().getPrivilege(privilegeId); return wrap(context, Privilege.class, result); @@ -241,16 +188,6 @@ public class BaseAdministrationService implements AdministrationService { return wrap(context, License.class, result.getCollection()); } - @Override - public Iterable listLicenses(final Predicate filter) { - return filter(listLicenses(), filter); - } - - @Override - public License findLicense(final Predicate filter) { - return getFirst(listLicenses(filter), null); - } - /*********************** System Properties ***********************/ @Override @@ -260,16 +197,6 @@ public class BaseAdministrationService implements AdministrationService { } @Override - public Iterable listSystemProperties(final Predicate filter) { - return filter(listSystemProperties(), filter); - } - - @Override - public SystemProperty findSystemProperty(final Predicate filter) { - return getFirst(listSystemProperties(filter), null); - } - - @Override public SystemProperty getSystemProperty(final String name) { PropertyOptions options = PropertyOptions.builder().name(name).build(); SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties(options); @@ -290,16 +217,6 @@ public class BaseAdministrationService implements AdministrationService { } @Override - public Iterable listCategories(final Predicate filter) { - return filter(listCategories(), filter); - } - - @Override - public Category findCategory(final Predicate filter) { - return Iterables.getFirst(listCategories(filter), null); - } - - @Override public Category getCategory(Integer categoryId) { CategoryDto result = context.getApi().getConfigApi().getCategory(categoryId); return wrap(context, Category.class, result); diff --git a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java index 5a434c7..6d0ca53 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseCloudService.java @@ -39,8 +39,6 @@ import org.jclouds.rest.ApiContext; 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. @@ -89,11 +87,6 @@ public class BaseCloudService implements CloudService { } @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); @@ -104,11 +97,6 @@ public class BaseCloudService implements CloudService { return listVirtualDatacenters.execute(virtualDatacenterIds); } - @Override - public VirtualDatacenter findVirtualDatacenter(final Predicate filter) { - return Iterables.getFirst(listVirtualDatacenters(filter), null); - } - /*********************** Virtual Appliance ********************** */ @Override @@ -116,30 +104,10 @@ public class BaseCloudService implements CloudService { 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/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java index eb682e8..5ee4d2c 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseMonitoringService.java @@ -29,17 +29,17 @@ import javax.inject.Named; import javax.inject.Singleton; 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.abiquo.monitor.events.CompletedEvent; +import org.jclouds.abiquo.monitor.events.FailedEvent; +import org.jclouds.abiquo.monitor.events.TimeoutEvent; +import org.jclouds.abiquo.monitor.handlers.AbstractEventHandler; +import org.jclouds.abiquo.monitor.handlers.BlockingEventHandler; import org.jclouds.logging.Logger; import org.jclouds.rest.ApiContext; diff --git a/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java b/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java deleted file mode 100644 index d5f2159..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/internal/BasePricingService.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.getFirst; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import java.util.Collection; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.config.CostCode; -import org.jclouds.abiquo.domain.config.CostCodeCurrency; -import org.jclouds.abiquo.domain.config.Currency; -import org.jclouds.abiquo.domain.config.PricingCostCode; -import org.jclouds.abiquo.domain.config.PricingTemplate; -import org.jclouds.abiquo.domain.config.PricingTier; -import org.jclouds.abiquo.features.services.PricingService; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; -import com.abiquo.server.core.pricing.CostCodeDto; -import com.abiquo.server.core.pricing.CostCodesDto; -import com.abiquo.server.core.pricing.CurrenciesDto; -import com.abiquo.server.core.pricing.CurrencyDto; -import com.abiquo.server.core.pricing.PricingCostCodeDto; -import com.abiquo.server.core.pricing.PricingCostCodesDto; -import com.abiquo.server.core.pricing.PricingTemplateDto; -import com.abiquo.server.core.pricing.PricingTemplatesDto; -import com.abiquo.server.core.pricing.PricingTierDto; -import com.abiquo.server.core.pricing.PricingTiersDto; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -/** - * Provides access to Abiquo pricing features. - * - * @author Ignasi Barrera - * @author Susana Acedo - */ -@Singleton -public class BasePricingService implements PricingService { - @VisibleForTesting - protected ApiContext context; - - @Inject - protected BasePricingService(final ApiContext context) { - this.context = checkNotNull(context, "context"); - } - - /*********************** Currency ********************** */ - - @Override - public Iterable listCurrencies() { - CurrenciesDto result = context.getApi().getPricingApi().listCurrencies(); - return wrap(context, Currency.class, result.getCollection()); - } - - @Override - public Iterable listCurrencies(final Predicate filter) { - return filter(listCurrencies(), filter); - } - - @Override - public Currency findCurrency(final Predicate filter) { - return getFirst(listCurrencies(filter), null); - } - - @Override - public Currency getCurrency(final Integer currencyId) { - CurrencyDto result = context.getApi().getPricingApi().getCurrency(currencyId); - return wrap(context, Currency.class, result); - } - - /*********************** CostCode ********************** */ - - @Override - public Iterable listCostCodes() { - CostCodesDto result = context.getApi().getPricingApi().listCostCodes(); - return wrap(context, CostCode.class, result.getCollection()); - } - - @Override - public Iterable listCostCodes(final Predicate filter) { - return filter(listCostCodes(), filter); - } - - @Override - public CostCode findCostCode(final Predicate filter) { - return Iterables.getFirst(listCostCodes(filter), null); - } - - @Override - public CostCode getCostCode(Integer costCodeId) { - CostCodeDto result = context.getApi().getPricingApi().getCostCode(costCodeId); - return wrap(context, CostCode.class, result); - } - - /*********************** PricingTemplate ********************** */ - - @Override - public Iterable listPricingTemplates() { - PricingTemplatesDto result = context.getApi().getPricingApi().listPricingTemplates(); - return wrap(context, PricingTemplate.class, result.getCollection()); - } - - @Override - public Iterable listPricingTemplates(final Predicate filter) { - return filter(listPricingTemplates(), filter); - } - - @Override - public PricingTemplate findPricingTemplate(final Predicate filter) { - return getFirst(listPricingTemplates(filter), null); - } - - @Override - public PricingTemplate getPricingTemplate(Integer pricingTemplateId) { - PricingTemplateDto result = context.getApi().getPricingApi().getPricingTemplate(pricingTemplateId); - return wrap(context, PricingTemplate.class, result); - } - - /*********************** CostCodeCurrency ********************** */ - - @Override - public Iterable getCostCodeCurrencies(final Integer costcodeId, final Integer currencyId) { - CostCodeCurrenciesDto result = context.getApi().getPricingApi().getCostCodeCurrencies(costcodeId, currencyId); - return wrap(context, CostCodeCurrency.class, result.getCollection()); - } - - /*********************** Pricing Cost Code ********************** */ - - @Override - public Collection getPricingCostCodes(final Integer pricingTemplateId) { - PricingCostCodesDto result = context.getApi().getPricingApi().getPricingCostCodes(pricingTemplateId); - return wrap(context, PricingCostCode.class, result.getCollection()); - } - - @Override - public PricingCostCode getPricingCostCode(final Integer pricingTemplateId, final Integer pricingCostCodeId) { - PricingCostCodeDto pricingcostcode = context.getApi().getPricingApi() - .getPricingCostCode(pricingTemplateId, pricingCostCodeId); - return wrap(context, PricingCostCode.class, pricingcostcode); - } - - /*********************** Pricing Tier********************** */ - - @Override - public Collection getPricingTiers(final Integer pricingTemplateId) { - PricingTiersDto result = context.getApi().getPricingApi().getPricingTiers(pricingTemplateId); - return wrap(context, PricingTier.class, result.getCollection()); - } - - @Override - public PricingTier getPricingTier(final Integer pricingTemplateId, final Integer pricingTierId) { - PricingTierDto pricingtier = context.getApi().getPricingApi().getPricingTier(pricingTemplateId, pricingTierId); - return wrap(context, PricingTier.class, pricingtier); - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java index 803f94b..42070e9 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/internal/BaseSearchService.java @@ -31,8 +31,6 @@ 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; @@ -40,12 +38,10 @@ 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.ApiContext; 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; @@ -133,20 +129,4 @@ public class BaseSearchService implements SearchService { 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/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java new file mode 100644 index 0000000..352f304 --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.events; + +/** + * 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/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java new file mode 100644 index 0000000..af18d1d --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.events; + +/** + * 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/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java new file mode 100644 index 0000000..0d43335 --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.events; + +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/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java new file mode 100644 index 0000000..e46c3d6 --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.events; + +/** + * 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/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java new file mode 100644 index 0000000..a1bec36 --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.handlers; + +import javax.annotation.Resource; + +import org.jclouds.abiquo.monitor.events.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/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java new file mode 100644 index 0000000..0419e1a --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.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.monitor.events.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/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java deleted file mode 100644 index c2b06a9..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/ErrorPredicates.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java new file mode 100644 index 0000000..3a918f9 --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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 org.jclouds.abiquo.domain.network.AbstractPublicIp; +import org.jclouds.abiquo.domain.network.Ip; + +import com.google.common.base.Predicate; + +/** + * Container for {@link Network} filters. + * + * @author Francesc Montserrat + */ +public class IpPredicates { + + 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java index cfcc818..524fcfe 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java @@ -18,8 +18,6 @@ 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; @@ -29,13 +27,12 @@ import com.google.common.base.Predicate; * @author Ignasi Barrera */ public class LinkPredicates { - public static Predicate rel(final String... rels) { - checkNotNull(rels, "rels must be defined"); - + public static Predicate rel(final String rel) { + checkNotNull(rel, "rel must be defined"); return new Predicate() { @Override public boolean apply(final RESTLink link) { - return Arrays.asList(rels).contains(link.getRel()); + return link.getRel().equals(rel); } }; } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java new file mode 100644 index 0000000..1e8b16e --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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 org.jclouds.abiquo.domain.network.NetworkServiceType; + +import com.google.common.base.Predicate; + +/** + * Container for {@link NetworkServiceType} filters. + * + * @author Jaume Devesa + */ +public class NetworkServiceTypePredicates { + public static Predicate isDefault() { + return new Predicate() { + @Override + public boolean apply(final NetworkServiceType ni) { + return ni.isDefaultNST(); + } + }; + } +} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java new file mode 100644 index 0000000..ac71720 --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.List; + +import org.jclouds.abiquo.domain.cloud.Conversion; +import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; +import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; +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.ConversionState; +import com.abiquo.model.enumerator.HypervisorType; +import com.google.common.base.Predicate; + +/** + * Container for {@link VirtualDatacenter} filters. + * + * @author Ignasi Barrera + */ +public class VirtualDatacenterPredicates { + + public static Predicate datacenter(final Datacenter datacenter) { + checkNotNull(datacenter, "datacenter must be defined"); + + 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 datacenterId.equals(datacenter.getId()); + } + }; + } + + /** + * Check if the given template type is compatible with the given virtual + * datacenter type taking into account the conversions of the template. + * + * @param template + * The template to check. + * @return Predicate to check if the template or its conversions are + * compatibles with the given virtual datacenter. + */ + public static Predicate compatibleWithTemplateOrConversions(final VirtualMachineTemplate template) { + return new Predicate() { + @Override + public boolean apply(final VirtualDatacenter vdc) { + HypervisorType type = vdc.getHypervisorType(); + 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java new file mode 100644 index 0000000..445566e --- /dev/null +++ b/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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 org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; + +import com.google.common.base.Predicate; + +/** + * Container for {@link VirtualMachineTemplate} filters. + * + * @author Francesc Montserrat + */ +public class VirtualMachineTemplatePredicates { + + public static Predicate isShared() { + return new Predicate() { + @Override + public boolean apply(final VirtualMachineTemplate input) { + return input.unwrap().isShared(); + } + }; + } + + public static Predicate isInstance() { + return new Predicate() { + @Override + public boolean apply(final VirtualMachineTemplate input) { + return input.unwrap().searchLink("master") != null; + } + }; + } +} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java deleted file mode 100644 index 777df74..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/ConversionPredicates.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java deleted file mode 100644 index 00a1f02..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualAppliancePredicates.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.abiquo.server.core.cloud.VirtualApplianceState; -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()); - } - }; - } - - public static Predicate state(final VirtualApplianceState... states) { - checkNotNull(states, "states must be defined"); - - return new Predicate() { - @Override - public boolean apply(final VirtualAppliance virtualAppliance) { - return Arrays.asList(states).contains(virtualAppliance.getState()); - } - }; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java deleted file mode 100644 index de91d69..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualDatacenterPredicates.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.Conversion; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -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.ConversionState; -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); - } - }; - } - - /** - * Check if the given template type is compatible with the given virtual - * datacenter type taking into account the conversions of the template. - * - * @param template - * The template to check. - * @return Predicate to check if the template or its conversions are - * compatibles with the given virtual datacenter. - */ - public static Predicate compatibleWithTemplateOrConversions(final VirtualMachineTemplate template) { - return new Predicate() { - @Override - public boolean apply(final VirtualDatacenter vdc) { - HypervisorType type = vdc.getHypervisorType(); - 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java deleted file mode 100644 index 6746e76..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachinePredicates.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java deleted file mode 100644 index 49b8d6e..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VirtualMachineTemplatePredicates.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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()); - } - }; - } - - public static Predicate isShared() { - return new Predicate() { - @Override - public boolean apply(final VirtualMachineTemplate input) { - return input.unwrap().isShared(); - } - }; - } - - public static Predicate isInstance() { - return new Predicate() { - @Override - public boolean apply(final VirtualMachineTemplate input) { - return input.unwrap().searchLink("master") != null; - } - }; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java deleted file mode 100644 index e708ace..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/cloud/VolumePredicates.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.abiquo.model.enumerator.VolumeState; -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)); - } - - public static Predicate state(final VolumeState... states) { - checkNotNull(states, "states must be defined"); - - return new Predicate() { - @Override - public boolean apply(final Volume volume) { - return Arrays.asList(states).contains(VolumeState.valueOf(volume.getState())); - } - }; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java deleted file mode 100644 index b15da49..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/CategoryPredicates.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java deleted file mode 100644 index c306a65..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/LicensePredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java deleted file mode 100644 index 22ece23..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PricingPredicates.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.CostCode; -import org.jclouds.abiquo.domain.config.Currency; -import org.jclouds.abiquo.domain.config.PricingTemplate; - -import com.google.common.base.Predicate; - -/** - * Container for pricing related filters. - * - * @author Ignasi Barrera - * @author Susana Acedo - */ -public class PricingPredicates { - public static Predicate currency(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()); - } - }; - } - - public static Predicate costCode(final String... names) { - checkNotNull(names, "names must be defined"); - - return new Predicate() { - @Override - public boolean apply(final CostCode costcode) { - return Arrays.asList(names).contains(costcode.getName()); - } - }; - } - - public static Predicate pricingTemplate(final String... names) { - checkNotNull(names, "names must be defined"); - - return new Predicate() { - @Override - public boolean apply(final PricingTemplate pricingTemplate) { - return Arrays.asList(names).contains(pricingTemplate.getName()); - } - }; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java deleted file mode 100644 index dd89528..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/PrivilegePredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java deleted file mode 100644 index 88d93e7..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/config/SystemPropertyPredicates.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java deleted file mode 100644 index 5f8424e..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/EnterprisePredicates.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java deleted file mode 100644 index af4aac9..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/RolePredicates.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java deleted file mode 100644 index 7ba9216..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/TemplateDefinitionListPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java deleted file mode 100644 index 76e225f..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/enterprise/UserPredicates.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java deleted file mode 100644 index e769fb0..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/BladePredicates.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java deleted file mode 100644 index b77d2ce..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatacenterPredicates.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java deleted file mode 100644 index 78af71d..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/DatastorePredicates.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java deleted file mode 100644 index 09acc8c..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/HypervisorPredicates.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java deleted file mode 100644 index 497868e..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/LogicServerPredicates.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java deleted file mode 100644 index 38a1542..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/MachinePredicates.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java deleted file mode 100644 index 1b47566..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/ManagedRackPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/NetworkInterfacePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/NetworkInterfacePredicates.java deleted file mode 100644 index 289652e..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/NetworkInterfacePredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.NetworkInterface; - -import com.google.common.base.Predicate; - -/** - * Container for {@link NetworkInterface} filters. - * - * @author Jaume Devesa - */ -public class NetworkInterfacePredicates { - public static Predicate name(final String... names) { - checkNotNull(names, "names must be defined"); - - return new Predicate() { - @Override - public boolean apply(final NetworkInterface ni) { - return Arrays.asList(names).contains(ni.getName()); - } - }; - } - -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java deleted file mode 100644 index 35074dc..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RackPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java deleted file mode 100644 index aa28571..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/RemoteServicePredicates.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java deleted file mode 100644 index e14e9d6..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDeviceMetadataPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java deleted file mode 100644 index 0623537..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StorageDevicePredicates.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java deleted file mode 100644 index 7fda6b5..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/StoragePoolPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java deleted file mode 100644 index 726a3ce..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/infrastructure/TierPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java deleted file mode 100644 index 5ac19d1..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/IpPredicates.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java deleted file mode 100644 index a5e737f..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkServiceTypePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkServiceTypePredicates.java deleted file mode 100644 index 8439b88..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NetworkServiceTypePredicates.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 org.jclouds.abiquo.domain.network.NetworkServiceType; - -import com.google.common.base.Predicate; - -/** - * Container for {@link NetworkServiceType} filters. - * - * @author Jaume Devesa - */ -public class NetworkServiceTypePredicates { - public static Predicate isDefault() { - return new Predicate() { - @Override - public boolean apply(final NetworkServiceType ni) { - return ni.isDefaultNST(); - } - }; - } -} diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java deleted file mode 100644 index a45735c..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/network/NicPredicates.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java deleted file mode 100644 index 95bb6fd..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/task/AsyncTaskPredicates.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java b/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java index 9289b1b..996812b 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java @@ -42,8 +42,6 @@ public class ParentLinkName { public static final String DATACENTER_REPOSITORY = "datacenterrepository"; - public static final String COST_CODE = "costcode"; - public static final String CATEGORY = "category"; public static final String ICON = "icon"; diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java index e49d023..5597af7 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java @@ -18,8 +18,6 @@ package org.jclouds.abiquo.strategy; import org.jclouds.abiquo.domain.DomainWrapper; -import com.google.common.base.Predicate; - /** * List all entities of the given type. * @@ -27,6 +25,4 @@ import com.google.common.base.Predicate; */ public interface ListEntities, P extends DomainWrapper> { Iterable execute(P parent); - - Iterable execute(P parent, Predicate selector); } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java index 38fe6d1..defb068 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java @@ -18,8 +18,6 @@ package org.jclouds.abiquo.strategy; import org.jclouds.abiquo.domain.DomainWrapper; -import com.google.common.base.Predicate; - /** * List all entities of the given type. * @@ -27,6 +25,4 @@ import com.google.common.base.Predicate; */ public interface ListRootEntities> { Iterable execute(); - - Iterable execute(Predicate selector); } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java index de2900a..0bf459c 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java @@ -17,7 +17,6 @@ package org.jclouds.abiquo.strategy.cloud; 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; @@ -40,7 +39,6 @@ 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.Singleton; import com.google.inject.TypeLiteral; @@ -66,11 +64,6 @@ public class ListAttachedNics implements ListEntities, VirtualMachine> 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 diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java index 02015df..00261a9 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java @@ -77,11 +77,6 @@ public class ListVirtualAppliances implements ListRootEntities return execute(userExecutor); } - @Override - public Iterable execute(final Predicate selector) { - return execute(userExecutor, selector); - } - private Iterable listConcurrentVirtualAppliances(final ListeningExecutorService executor, final Iterable vdcs) { ListenableFuture> futures = allAsList(transform(vdcs, diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java index 7bc99a1..2fd033c 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java @@ -73,11 +73,6 @@ public class ListVirtualDatacenters implements ListRootEntities execute(final Predicate selector) { - return execute(userExecutor, selector); - } - public Iterable execute(final VirtualDatacenterOptions virtualDatacenterOptions) { VirtualDatacentersDto result = context.getApi().getCloudApi().listVirtualDatacenters(virtualDatacenterOptions); return wrap(context, VirtualDatacenter.class, result.getCollection()); diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java index 50cd9aa..aeb8ac0 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachines.java @@ -79,11 +79,6 @@ public class ListVirtualMachines implements ListRootEntities { return execute(userExecutor); } - @Override - public Iterable execute(final Predicate selector) { - return execute(userExecutor, selector); - } - public Iterable execute(ListeningExecutorService executor) { return execute(executor, VirtualMachineOptions.builder().disablePagination().build()); } diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java index 79b5ada..d82d3ad 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java @@ -75,12 +75,6 @@ public class ListVirtualMachineTemplates implements ListEntities execute(final Enterprise parent, - final Predicate selector) { - return execute(userExecutor, parent, selector); - } - public Iterable execute(ListeningExecutorService executor, final Enterprise parent) { // Find virtual machine templates in concurrent requests Iterable dcs = parent.listAllowedDatacenters(); diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java index f4656e6..df98a03 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java @@ -77,11 +77,6 @@ public class ListMachines implements ListRootEntities { return execute(userExecutor); } - @Override - public Iterable execute(final Predicate selector) { - return execute(userExecutor, selector); - } - public Iterable execute(ListeningExecutorService executor) { // Find machines in concurrent requests DatacentersDto result = context.getApi().getInfrastructureApi().listDatacenters(); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java index e7a51c2..59601cd 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java @@ -51,7 +51,6 @@ public class AbiquoDelegateApiTest extends BaseAbiquoApiTest { assertNotNull(syncApi.getCloudApi()); assertNotNull(syncApi.getVirtualMachineTemplateApi()); assertNotNull(syncApi.getTaskApi()); - assertNotNull(syncApi.getPricingApi()); } @Override diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java deleted file mode 100644 index 4992c6b..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindLogicServerParametersTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java deleted file mode 100644 index 7735b48..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/ucs/BindOrganizationParametersTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java index 82df566..2c46e51 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/InfrastructureResources.java @@ -21,12 +21,9 @@ 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; @@ -56,18 +53,6 @@ public class InfrastructureResources { 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"); @@ -136,46 +121,6 @@ public class InfrastructureResources { 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); @@ -269,20 +214,6 @@ public class InfrastructureResources { return buffer.toString(); } - public static String managedRackPostPayload() { - StringBuilder buffer = new StringBuilder(); - 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() { StringBuilder buffer = new StringBuilder(); buffer.append(""); @@ -402,33 +333,6 @@ public class InfrastructureResources { return buffer.toString(); } - public static String managedRackPutPayload() { - StringBuilder buffer = new StringBuilder(); - 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() { StringBuilder buffer = new StringBuilder(); buffer.append(""); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java deleted file mode 100644 index f8fe258..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/PricingResources.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.math.BigDecimal; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; -import com.abiquo.server.core.pricing.CostCodeCurrencyDto; -import com.abiquo.server.core.pricing.CostCodeDto; -import com.abiquo.server.core.pricing.CurrencyDto; -import com.abiquo.server.core.pricing.PricingCostCodeDto; -import com.abiquo.server.core.pricing.PricingTemplateDto; -import com.abiquo.server.core.pricing.PricingTierDto; - -/** - * 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("DUMMY"); - currency.setDigits(3); - return currency; - } - - public static CurrencyDto currencyPut() { - CurrencyDto currency = new CurrencyDto(); - currency.setName("yuan"); - currency.setSymbol("DUMMY"); - currency.setDigits(3); - currency.setId(1); - currency.addLink(new RESTLink("edit", "http://localhost/api/config/currencies/1")); - return currency; - } - - public static String currencyPostPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append("DUMMY"); - buffer.append("3"); - buffer.append("yuan"); - buffer.append(""); - return buffer.toString(); - } - - public static String currencyPutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(link("/config/currencies/1", "edit")); - buffer.append("DUMMY"); - buffer.append("3"); - buffer.append("1"); - buffer.append("yuan"); - buffer.append(""); - return buffer.toString(); - } - - public static Object costcodePost() { - CostCodeDto costcode = new CostCodeDto(); - costcode.setName("cost code"); - costcode.setDescription("description"); - return costcode; - } - - public static Object costcodePut() { - CostCodeDto costcode = new CostCodeDto(); - costcode.setName("cost code"); - costcode.setDescription("description"); - costcode.setId(1); - costcode.addLink(new RESTLink("edit", "http://localhost/api/config/costcodes/1")); - return costcode; - } - - public static String costcodePostPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append("cost code"); - buffer.append("description"); - buffer.append(""); - return buffer.toString(); - } - - public static String costcodePutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(link("/config/costcodes/1", "edit")); - buffer.append("description"); - buffer.append("1"); - buffer.append("cost code"); - buffer.append(""); - return buffer.toString(); - } - - public static Object pricingtemplatePost() { - PricingTemplateDto pricingtemplate = new PricingTemplateDto(); - pricingtemplate.setName("pricing template"); - pricingtemplate.setDescription("pt_description"); - pricingtemplate.setHdGB(new BigDecimal(0)); - pricingtemplate.setStandingChargePeriod(new BigDecimal(0)); - pricingtemplate.setVlan(new BigDecimal(0)); - pricingtemplate.setChargingPeriod(1); - pricingtemplate.setMinimumChargePeriod(new BigDecimal(0)); - pricingtemplate.setShowChangesBefore(true); - pricingtemplate.setShowMinimumCharge(false); - pricingtemplate.setMinimumCharge(2); - pricingtemplate.setPublicIp(new BigDecimal(0)); - pricingtemplate.setVcpu(new BigDecimal(0)); - pricingtemplate.setMemoryGB(new BigDecimal(0)); - pricingtemplate.setDefaultTemplate(true); - pricingtemplate.addLink(new RESTLink("currency", "http://localhost/api/config/currencies/1")); - return pricingtemplate; - } - - public static Object pricingtemplatePut() { - PricingTemplateDto pricingtemplate = new PricingTemplateDto(); - pricingtemplate.setName("pricing template"); - pricingtemplate.setDescription("pt_description"); - pricingtemplate.setHdGB(new BigDecimal(0)); - pricingtemplate.setStandingChargePeriod(new BigDecimal(0)); - pricingtemplate.setVlan(new BigDecimal(0)); - pricingtemplate.setChargingPeriod(1); - pricingtemplate.setMinimumChargePeriod(new BigDecimal(0)); - pricingtemplate.setShowChangesBefore(true); - pricingtemplate.setShowMinimumCharge(false); - pricingtemplate.setMinimumCharge(2); - pricingtemplate.setPublicIp(new BigDecimal(0)); - pricingtemplate.setVcpu(new BigDecimal(0)); - pricingtemplate.setMemoryGB(new BigDecimal(0)); - pricingtemplate.setDefaultTemplate(true); - pricingtemplate.addLink(new RESTLink("currency", "http://localhost/api/config/currencies/1")); - pricingtemplate.setId(1); - pricingtemplate.addLink(new RESTLink("edit", "http://localhost/api/config/pricingtemplates/1")); - return pricingtemplate; - } - - public static String pricingtemplatePostPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append("pricing template"); - buffer.append("pt_description"); - buffer.append("0"); - buffer.append("0"); - buffer.append("0"); - buffer.append("1"); - buffer.append("0"); - buffer.append("true"); - buffer.append("false"); - buffer.append("2"); - buffer.append("0"); - buffer.append("0"); - buffer.append("0"); - buffer.append("0"); - buffer.append("true"); - buffer.append(""); - buffer.append(""); - return buffer.toString(); - } - - public static String pricingtemplatePutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append("pricing template"); - buffer.append("pt_description"); - buffer.append("0"); - buffer.append("0"); - buffer.append("0"); - buffer.append("1"); - buffer.append("0"); - buffer.append("true"); - buffer.append("false"); - buffer.append("2"); - buffer.append("0"); - buffer.append("0"); - buffer.append("0"); - buffer.append("0"); - buffer.append("true"); - buffer.append(""); - buffer.append("1"); - buffer.append(link("/config/pricingtemplates/1", "edit")); - buffer.append(""); - return buffer.toString(); - } - - public static Object costcodecurrencyPut() { - CostCodeCurrencyDto costcodecurrency = new CostCodeCurrencyDto(); - costcodecurrency.addLink(new RESTLink("edit", "http://localhost/api/config/costcodes/1/currencies")); - costcodecurrency.addLink(new RESTLink("currency", "http://localhost/api/config/currencies/1")); - costcodecurrency.setPrice(new BigDecimal("300")); - CostCodeCurrenciesDto costcodecurrencies = new CostCodeCurrenciesDto(); - costcodecurrencies.add(costcodecurrency); - return costcodecurrencies; - } - - public static String costcodecurrencyPutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - buffer.append("300"); - buffer.append(""); - buffer.append(""); - buffer.append(""); - - buffer.append(""); - return buffer.toString(); - } - - public static Object pricingCostcodePut() { - PricingCostCodeDto pricingcostcode = new PricingCostCodeDto(); - pricingcostcode.setId(1); - pricingcostcode.setPrice(new BigDecimal("400")); - pricingcostcode.addLink(new RESTLink("costcode", "http://localhost/api/config/costcodes/1")); - pricingcostcode.addLink(new RESTLink("pricingtemplate", "http://localhost/api/config/pricingtemplates/1")); - pricingcostcode.addLink(new RESTLink("edit", "http://localhost/api/config/pricingtemplates/1/costcodes/1")); - return pricingcostcode; - } - - public static String pricingCostCodePutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append("400"); - buffer.append("1"); - buffer.append(link("/config/pricingtemplates/1/costcodes/1", "edit")); - buffer.append(""); - return buffer.toString(); - } - - public static Object pricingTierPut() { - PricingTierDto pricingtier = new PricingTierDto(); - pricingtier.setId(1); - pricingtier.setPrice(new BigDecimal("600")); - pricingtier.addLink(new RESTLink("tier", "http://localhost/api/admin/datacenters/1/storage/tiers/2")); - pricingtier.addLink(new RESTLink("pricingtemplate", "http://localhost/api/config/pricingtemplates/1")); - pricingtier.addLink(new RESTLink("edit", "http://localhost/api/config/pricingtemplates/1/tiers/2")); - return pricingtier; - } - - public static String pricingTierPutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append("600"); - buffer.append("1"); - buffer.append(link("/config/pricingtemplates/1/tiers/2", "edit")); - buffer.append(""); - return buffer.toString(); - } - -} diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java index b99c9cb..38f139a 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/admin/RoleLiveApiTest.java @@ -16,9 +16,9 @@ */ package org.jclouds.abiquo.domain.admin; +import static com.google.common.collect.Iterables.find; 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; @@ -30,12 +30,11 @@ 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; +import com.google.common.base.Predicate; import com.google.common.collect.Lists; /** @@ -73,28 +72,33 @@ public class RoleLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testCreateEnterpriseRole() { - Role entRole = Role.Builder.fromRole(env.role).build(); + final 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); + find(env.enterprise.listRoles(), new Predicate() { + @Override + public boolean apply(Role input) { + return input.getName().equals(entRole.getName()); + } + }); } public void testAddPrivilege() { PrivilegeDto dto = env.configApi.getPrivilege(8); - Privilege privilege = DomainWrapper.wrap(env.context.getApiContext(), Privilege.class, dto); + final Privilege privilege = DomainWrapper.wrap(env.context.getApiContext(), Privilege.class, dto); List privileges = Lists.newArrayList(env.role.listPrivileges()); privileges.add(privilege); env.role.setPrivileges(privileges); - env.role.update(); - privilege = env.role.findPrivileges(PrivilegePredicates.name(dto.getName())); - - assertNotNull(privilege); + find(env.role.listPrivileges(), new Predicate() { + @Override + public boolean apply(Privilege input) { + return input.getName().equals(privilege.getName()); + } + }); } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveTest.java index f9856f7..4be19aa 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualApplianceLiveTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.cloud; +import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.getLast; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.testng.Assert.assertEquals; @@ -27,12 +28,12 @@ import java.util.concurrent.TimeUnit; import org.jclouds.abiquo.domain.task.AsyncTask; import org.jclouds.abiquo.features.services.MonitoringService; import org.jclouds.abiquo.internal.BaseAbiquoLiveApiTest; -import org.jclouds.abiquo.predicates.cloud.VirtualAppliancePredicates; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.abiquo.server.core.cloud.VirtualApplianceState; import com.abiquo.server.core.cloud.VirtualMachineState; +import com.google.common.base.Predicate; import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; @@ -109,9 +110,15 @@ public class VirtualApplianceLiveTest extends BaseAbiquoLiveApiTest { @Test(dependsOnMethods = "testUndeployVirtualAppliance") public void testDeleteVirtualAppliance() { + final String name = vapp.getName(); vapp.delete(); - assertNull(view.getCloudService().findVirtualAppliance( - VirtualAppliancePredicates.name(PREFIX + "Virtual Appliance Updated"))); + + assertNull(find(view.getCloudService().listVirtualAppliances(), new Predicate() { + @Override + public boolean apply(VirtualAppliance input) { + return input.getName().equals(name); + } + }, null)); } private static Ordering templateBySize() { diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java index 5f542a0..c6c6fdd 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenterLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.cloud; +import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.size; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.testng.Assert.assertEquals; @@ -33,12 +34,11 @@ 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; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link VirtualDatacenter} domain class. @@ -130,15 +130,24 @@ public class VirtualDatacenterLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testPurchaseIp() { - PublicIp publicIp = env.virtualDatacenter.listAvailablePublicIps().get(0); + final PublicIp publicIp = env.virtualDatacenter.listAvailablePublicIps().get(0); assertNotNull(publicIp); env.virtualDatacenter.purchasePublicIp(publicIp); - PublicIp apiIp = env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(publicIp.getIp())); - assertNotNull(apiIp); + PublicIp apiIp = find(env.virtualDatacenter.listPurchasedPublicIps(), new Predicate() { + @Override + public boolean apply(PublicIp input) { + return input.getIp().equals(publicIp.getIp()); + } + }); env.virtualDatacenter.releasePublicIp(apiIp); - apiIp = env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(publicIp.getIp())); + apiIp = find(env.virtualDatacenter.listPurchasedPublicIps(), new Predicate() { + @Override + public boolean apply(PublicIp input) { + return input.getIp().equals(publicIp.getIp()); + } + }, null); assertNull(apiIp); } @@ -159,16 +168,6 @@ public class VirtualDatacenterLiveApiTest extends BaseAbiquoApiLiveApiTest { } @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); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveTest.java index aaba872..1d2aedd 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineLiveTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.cloud; +import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.getLast; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.jclouds.abiquo.util.Assert.assertHasError; @@ -34,13 +35,12 @@ import org.jclouds.abiquo.domain.network.Ip; import org.jclouds.abiquo.domain.task.AsyncTask; import org.jclouds.abiquo.features.services.MonitoringService; import org.jclouds.abiquo.internal.BaseAbiquoLiveApiTest; -import org.jclouds.abiquo.predicates.cloud.VirtualMachinePredicates; -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.cloud.VirtualMachineState; +import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; @@ -99,8 +99,12 @@ public class VirtualMachineLiveTest extends BaseAbiquoLiveApiTest { AsyncTask task = vm.update(); assertNull(task); - VirtualMachine updated = vapp.findVirtualMachine(VirtualMachinePredicates.nameLabel(PREFIX + "VM Kane Updated")); - assertNotNull(updated); + find(vapp.listVirtualMachines(), new Predicate() { + @Override + public boolean apply(VirtualMachine input) { + return input.getNameLabel().equals(PREFIX + "VM Kane Updated"); + } + }); } @Test(dependsOnMethods = "testUpdateVirtualMachineWhenNotDeployed") @@ -123,13 +127,19 @@ public class VirtualMachineLiveTest extends BaseAbiquoLiveApiTest { @Test(dependsOnMethods = "testChangeVirtualMachineState") public void testReconfigure() { - Ip ip = getLast(vdc.getDefaultNetwork().listUnusedIps()); + final Ip ip = getLast(vdc.getDefaultNetwork().listUnusedIps()); AsyncTask task = vm.setNics(Lists.> newArrayList(ip)); assertNotNull(task); monitoringService.getVirtualMachineMonitor().awaitState(MAX_WAIT, TimeUnit.MINUTES, VirtualMachineState.OFF, vm); - assertNotNull(vm.findAttachedNic(IpPredicates.address(ip.getIp()))); + + find(vm.listAttachedNics(), new Predicate>() { + @Override + public boolean apply(Ip input) { + return input.getIp().equals(ip.getIp()); + } + }); } @Test(dependsOnMethods = "testReconfigure") diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java index baa6aee..c1fc61b 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineNetworkingLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.cloud; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -36,11 +37,11 @@ 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.base.Predicate; import com.google.common.collect.Lists; /** @@ -73,9 +74,12 @@ public class VirtualMachineNetworkingLiveApiTest extends BaseAbiquoApiLiveApiTes publicIpInfrastructure = env.virtualDatacenter.listAvailablePublicIps().get(0); env.virtualDatacenter.purchasePublicIp(publicIpInfrastructure); - publicIpCloud = env.virtualDatacenter.findPurchasedPublicIp(IpPredicates - . address(publicIpInfrastructure.getIp())); - assertNotNull(publicIpCloud); + publicIpCloud = find(env.virtualDatacenter.listPurchasedPublicIps(), new Predicate() { + @Override + public boolean apply(PublicIp input) { + return input.getIp().equals(publicIpInfrastructure.getIp()); + } + }); } @AfterClass @@ -87,9 +91,15 @@ public class VirtualMachineNetworkingLiveApiTest extends BaseAbiquoApiLiveApiTes assertEquals(nics.size(), 1); assertEquals(nics.get(0).getId(), privateIp.getId()); - String address = publicIpCloud.getIp(); + final String address = publicIpCloud.getIp(); env.virtualDatacenter.releasePublicIp(publicIpCloud); - assertNull(env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(address))); + + assertNull(find(env.virtualDatacenter.listPurchasedPublicIps(), new Predicate() { + @Override + public boolean apply(PublicIp input) { + return input.getIp().equals(address); + } + }, null)); } // TODO: Infrastructure edit link for public ips can not be used to attach diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java index 05d2889..82a2708 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VirtualMachineStorageLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.cloud; +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; @@ -27,9 +28,10 @@ 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; +import com.google.common.base.Predicate; + /** * Live integration tests for the {@link VirtualMachine} storage operations. * @@ -110,7 +112,12 @@ public class VirtualMachineStorageLiveApiTest extends BaseAbiquoApiLiveApiTest { } private Volume createVolume() { - Tier tier = env.virtualDatacenter.findStorageTier(TierPredicates.name(env.tier.getName())); + Tier tier = find(env.virtualDatacenter.listStorageTiers(), new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals(env.tier.getName()); + } + }); Volume volume = Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) .name(PREFIX + "Hawaian volume").sizeInMb(32).build(); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java index 1a20e3a..a671989 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/cloud/VolumeLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.cloud; +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; @@ -29,11 +30,10 @@ 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; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link Volume} domain class. @@ -44,7 +44,12 @@ import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; public class VolumeLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testCreateVolume() { // We need the vdc-relative tier - Tier tier = env.virtualDatacenter.findStorageTier(TierPredicates.name(env.tier.getName())); + Tier tier = find(env.virtualDatacenter.listStorageTiers(), new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals(env.tier.getName()); + } + }); Volume volume = Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) .name(PREFIX + "Hawaian volume").sizeInMb(32).build(); @@ -71,8 +76,7 @@ public class VolumeLiveApiTest extends BaseAbiquoApiLiveApiTest { @Test(dependsOnMethods = "testFilterVolumes") public void testUpdateVolume() { - Volume volume = env.virtualDatacenter.findVolume(VolumePredicates.name(PREFIX + "Hawaian volume")); - assertNotNull(volume); + Volume volume = find(env.virtualDatacenter.listVolumes(), volumeName(PREFIX + "Hawaian volume")); volume.setName("Hawaian volume updated"); AsyncTask task = volume.update(); @@ -94,9 +98,7 @@ public class VolumeLiveApiTest extends BaseAbiquoApiLiveApiTest { newVdc.save(); assertNotNull(newVdc.getId()); - Volume volume = env.virtualDatacenter.findVolume(VolumePredicates.name("Hawaian volume updated")); - assertNotNull(volume); - + Volume volume = find(env.virtualDatacenter.listVolumes(), volumeName("Hawaian volume updated")); volume.moveTo(newVdc); // Check that the underlying Dto has been updated to the new VDC @@ -115,8 +117,7 @@ public class VolumeLiveApiTest extends BaseAbiquoApiLiveApiTest { @Test(dependsOnMethods = "testMoveVolume") public void testDeleteVolume() { - Volume volume = env.virtualDatacenter.findVolume(VolumePredicates.name("Hawaian volume updated")); - assertNotNull(volume); + Volume volume = find(env.virtualDatacenter.listVolumes(), volumeName("Hawaian volume updated")); Integer id = volume.getId(); volume.delete(); @@ -124,4 +125,13 @@ public class VolumeLiveApiTest extends BaseAbiquoApiLiveApiTest { assertNull(env.virtualDatacenter.getVolume(id)); } + private static Predicate volumeName(final String name) { + return new Predicate() { + @Override + public boolean apply(Volume input) { + return input.getName().equals(name); + } + }; + } + } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java index 2341e3f..33cb292 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CategoryLiveApiTest.java @@ -16,14 +16,15 @@ */ package org.jclouds.abiquo.domain.config; +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 org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.config.CategoryPredicates; import org.testng.annotations.Test; +import com.google.common.base.Predicate; + /** * Live integration tests for the {@link Category} domain class. * @@ -35,10 +36,12 @@ public class CategoryLiveApiTest extends BaseAbiquoApiLiveApiTest { 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()); + Category apiCategory = find(env.context.getAdministrationService().listCategories(), new Predicate() { + @Override + public boolean apply(Category input) { + return input.getName().equals(PREFIX + "-test-category"); + } + }); apiCategory.delete(); } @@ -54,11 +57,12 @@ public class CategoryLiveApiTest extends BaseAbiquoApiLiveApiTest { 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()); + find(env.context.getAdministrationService().listCategories(), new Predicate() { + @Override + public boolean apply(Category input) { + return input.getName().equals(PREFIX + "-test-category-updated"); + } + }); category.setName(name); category.update(); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java deleted file mode 100644 index 0a55f88..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CostCodeLiveApiTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.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.math.BigDecimal; -import java.util.List; - -import javax.ws.rs.core.Response.Status; - -import com.google.common.collect.Lists; - -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.config.PricingPredicates; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Live integration tests for the {@link CostCode} domain class. - * - * @author Susana Acedo - */ -@Test(groups = "api", testName = "CostCodeLiveApiTest") -public class CostCodeLiveApiTest extends BaseAbiquoApiLiveApiTest { - private CostCode costcode; - - private Currency currency; - - private CostCodePrice costcodeprice; - - private List defaultPrices; - - @BeforeClass - public void setupCostCode() { - currency = Currency.builder(env.context.getApiContext()).name(PREFIX + "test-currency").symbol("test-$") - .digits(2).build(); - currency.save(); - - costcode = CostCode.builder(env.context.getApiContext()).name(PREFIX + "test-costcode") - .description("description").build(); - - costcode.save(); - } - - @AfterClass - public void tearDownCostCode() { - currency.delete(); - costcode.delete(); - } - - public void testCreateRepeated() { - CostCode repeated = CostCode.Builder.fromCostCode(costcode).build(); - - try { - repeated.save(); - fail("Should not be able to create costcodes with the same name"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "COSTCODE-2"); - } - } - - public void testUpdate() { - costcode.setName(PREFIX + "costcode-updated"); - costcode.update(); - - CostCode apiCostCode = env.context.getPricingService().findCostCode( - PricingPredicates.costCode(PREFIX + "costcode-updated")); - - assertNotNull(apiCostCode); - assertEquals(PREFIX + "costcode-updated", apiCostCode.getName()); - - } - - public void testCreateCostCodewithDefaultPrices() { - CostCode costcode2 = CostCode.builder(env.context.getApiContext()).name(PREFIX + "ccdefaultprice") - .description("description").build(); - - costcodeprice = new CostCodePrice(currency, new BigDecimal(100)); - this.defaultPrices = Lists.newArrayList(); - defaultPrices.add(costcodeprice); - costcode2.setDefaultPrices(defaultPrices); - // When a cost code is created it is also created a costcodecurrency with - // price 0 and after - // that if a list of prices(CostCodePrice) has been sent this costcode is - // updated with the - // new price - costcode2.save(); - - // check that costcode has been created - CostCode apiCostCode = env.context.getPricingService().findCostCode( - PricingPredicates.costCode(PREFIX + "ccdefaultprice")); - - assertNotNull(apiCostCode); - assertEquals(PREFIX + "ccdefaultprice", apiCostCode.getName()); - - // check that the price has been modified in the - Iterable costcodecurrencies = env.context.getPricingService().getCostCodeCurrencies( - costcode2.getId(), currency.getId()); - for (CostCodeCurrency costcodecurrency : costcodecurrencies) { - assertEquals(costcodecurrency.getPrice().compareTo(new BigDecimal(100)), 0); - } - - costcode2.delete(); - } -} diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java deleted file mode 100644 index 2bb7e1f..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/CurrencyLiveApiTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.PricingPredicates; -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( - PricingPredicates.currency(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( - PricingPredicates.currency(PREFIX + "t-currency-upd")); - - assertNotNull(apiCurrency); - assertEquals(PREFIX + "t-currency-upd", apiCurrency.getName()); - - currency.setName(name); - currency.update(); - } -} diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java deleted file mode 100644 index 9155f49..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/config/PricingTemplateLiveApiTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.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.math.BigDecimal; -import java.util.Collection; -import java.util.Date; - -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.config.PricingPredicates; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.PricingPeriod; - -/** - * Live integration tests for the {@link PricingTemplate} domain class. - * - * @author Susana Acedo - */ -@Test(groups = "api", testName = "PricingTemplateLiveApiTest") -public class PricingTemplateLiveApiTest extends BaseAbiquoApiLiveApiTest { - private PricingTemplate pricingTemplate; - - private Currency currency; - - private CostCode costcode; - - private BigDecimal zero = new BigDecimal(0); - - @BeforeClass - public void setupPricingTemplate() { - Iterable currencies = env.context.getPricingService().listCurrencies(); - currency = currencies.iterator().next(); - - costcode = CostCode.builder(env.context.getApiContext()).name(PREFIX + "test-costcode") - .description("description").build(); - - costcode.save(); - - pricingTemplate = PricingTemplate.builder(env.context.getApiContext(), currency).name("pricing_template") - .description("description").hdGB(zero).standingChargePeriod(zero).vlan(zero) - .chargingPeriod(PricingPeriod.MONTH).minimumChargePeriod(zero).showChangesBefore(true) - .showMinimumCharge(false).minimumCharge(PricingPeriod.WEEK).publicIp(zero).vcpu(zero).memoryGB(zero) - .defaultTemplate(true).lastUpdate(new Date()).build(); - - pricingTemplate.save(); - } - - @AfterClass - public void tearDownPricingTemplate() { - pricingTemplate.delete(); - costcode.delete(); - } - - public void testCreateRepeated() { - PricingTemplate repeated = PricingTemplate.Builder.fromPricingTemplate(pricingTemplate).build(); - - try { - repeated.save(); - fail("Should not be able to create pricingtemplates with the same name"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "PRICINGTEMPLATE-2"); - } - } - - public void testUpdate() { - pricingTemplate.setName(PREFIX + "pt-updated"); - pricingTemplate.update(); - - PricingTemplate apiPricingTemplate = env.context.getPricingService().findPricingTemplate( - PricingPredicates.pricingTemplate(PREFIX + "pt-updated")); - - assertNotNull(apiPricingTemplate); - assertEquals(PREFIX + "pt-updated", apiPricingTemplate.getName()); - - } - - // when a pricing template is created, pricing cost codes for each existent - // cost code are also - // created with price 0 - public void getPricingCostCodes() { - Collection pricingCostCodes = env.context.getPricingService().getPricingCostCodes( - pricingTemplate.getId()); - assertEquals(pricingCostCodes.size(), 1); - assertNotNull(pricingCostCodes); - for (PricingCostCode pc : pricingCostCodes) { - assertEquals(pc.getPrice().compareTo(zero), 0); - } - } - - // when a pricing template is created, pricing tiers are also created with - // price 0 - public void getPricingTiers() { - Collection pricingTiers = - - env.context.getPricingService().getPricingTiers(pricingTemplate.getId()); - assertEquals(pricingTiers.size(), 4); - assertNotNull(pricingTiers); - for (PricingTier pt : pricingTiers) { - assertEquals(pt.getPrice().compareTo(zero), 0); - } - } -} diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java index d9af7f3..b5909a5 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/TemplateDefinitionListLiveApiTest.java @@ -16,6 +16,8 @@ */ package org.jclouds.abiquo.domain.enterprise; +import static com.google.common.collect.Iterables.filter; +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; @@ -23,11 +25,12 @@ 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; +import com.google.common.base.Predicate; + /** * Live integration tests for the {@link TemplateDefinitionList} domain class. * @@ -41,10 +44,15 @@ public class TemplateDefinitionListLiveApiTest extends BaseAbiquoApiLiveApiTest list.setName(list.getName() + "Updated"); list.update(); - List lists = env.enterprise.listTemplateDefinitionLists(TemplateDefinitionListPredicates - .name("myListUpdated")); + Iterable lists = filter(env.enterprise.listTemplateDefinitionLists(), + new Predicate() { + @Override + public boolean apply(TemplateDefinitionList input) { + return input.getName().equals("myListUpdated"); + } + }); - assertEquals(lists.size(), 1); + assertEquals(size(lists), 1); } public void testListStates() { diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java index 02dadec..4250431 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java @@ -16,7 +16,9 @@ */ package org.jclouds.abiquo.domain.enterprise; -import static org.jclouds.abiquo.predicates.enterprise.UserPredicates.nick; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.size; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -26,10 +28,10 @@ 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.base.Predicate; import com.google.common.collect.Iterables; /** @@ -69,7 +71,7 @@ public class UserLiveApiTest extends BaseAbiquoApiLiveApiTest { env.user.setRole(env.anotherRole); env.user.update(); - Role role2 = env.enterprise.findUser(UserPredicates.nick(env.user.getNick())).getRole(); + Role role2 = find(env.enterprise.listUsers(), nick(env.user.getNick())).getRole(); assertEquals(env.anotherRole.getId(), role2.getId()); assertEquals(role2.getName(), "Another role"); @@ -82,11 +84,11 @@ public class UserLiveApiTest extends BaseAbiquoApiLiveApiTest { Iterable users = env.enterprise.listUsers(); assertEquals(Iterables.size(users), 2); - users = env.enterprise.listUsers(nick(env.user.getNick())); - assertEquals(Iterables.size(users), 1); + users = filter(env.enterprise.listUsers(), nick(env.user.getNick())); + assertEquals(size(users), 1); - users = env.enterprise.listUsers(nick(env.user.getName() + "FAIL")); - assertEquals(Iterables.size(users), 0); + users = filter(env.enterprise.listUsers(), nick(env.user.getName() + "FAIL")); + assertEquals(size(users), 0); } public void testGetCurrentUser() { @@ -94,4 +96,13 @@ public class UserLiveApiTest extends BaseAbiquoApiLiveApiTest { assertNotNull(user); assertEquals(user.getNick(), env.context.getApiContext().getIdentity()); } + + private static Predicate nick(final String nick) { + return new Predicate() { + @Override + public boolean apply(User input) { + return input.getNick().equals(nick); + } + }; + } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java index d4e2dcf..5fd46e1 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.event; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -29,12 +30,12 @@ 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.base.Predicate; import com.google.common.collect.Iterables; /** @@ -81,8 +82,12 @@ public class EventLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testListEventsFilteredByStoragePool() { - Tier tier = env.datacenter.findTier(TierPredicates.name("Default Tier 2")); - assertNotNull(tier); + Tier tier = find(env.datacenter.listTiers(), new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals("Default Tier 2"); + } + }); try { env.storagePool.setTier(tier); @@ -215,7 +220,13 @@ public class EventLiveApiTest extends BaseAbiquoApiLiveApiTest { } private Volume createVolume() { - Tier tier = env.virtualDatacenter.findStorageTier(TierPredicates.name(env.tier.getName())); + Tier tier = find(env.virtualDatacenter.listStorageTiers(), new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals(env.tier.getName()); + } + }); + Volume volume = Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) .name(PREFIX + "Event vol").sizeInMb(32).build(); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java deleted file mode 100644 index 636ead6..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/BladeLiveUcsTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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.jclouds.abiquo.util.Config; -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 = Config.get("abiquo.hypervisor.vswitch"); - NetworkInterface found = env.machine.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/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java index 535860b..e4eafd7 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.infrastructure; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -32,7 +33,6 @@ 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; @@ -40,6 +40,7 @@ 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; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link Machine} domain class. @@ -50,8 +51,12 @@ import com.abiquo.server.core.infrastructure.MachineDto; public class MachineLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testDiscoverMachineWithouRemoteService() { // Delete node collector - RemoteService nc = env.datacenter.findRemoteService(RemoteServicePredicates - .type(RemoteServiceType.NODE_COLLECTOR)); + RemoteService nc = find(env.datacenter.listRemoteServices(), new Predicate() { + @Override + public boolean apply(RemoteService input) { + return input.getType().equals(RemoteServiceType.NODE_COLLECTOR); + } + }); nc.delete(); try { @@ -103,18 +108,6 @@ public class MachineLiveApiTest extends BaseAbiquoApiLiveApiTest { 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 = Config.get("abiquo.hypervisor.vswitch"); - NetworkInterface found = env.machine.findAvailableVirtualSwitch(vswitch); - assertEquals(found.getName(), vswitch); - } - public void testGetRack() { Rack rack = env.machine.getRack(); assertNotNull(rack); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java deleted file mode 100644 index 4c4e491..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/ManagedRackLiveUcsTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java index 9cdcff3..71f87f7 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java @@ -16,16 +16,15 @@ */ package org.jclouds.abiquo.domain.infrastructure; -import static org.jclouds.abiquo.predicates.infrastructure.RackPredicates.name; +import static com.google.common.collect.Iterables.filter; +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 org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; import org.testng.annotations.Test; import com.abiquo.server.core.infrastructure.RackDto; -import com.google.common.collect.Iterables; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link Rack} domain class. @@ -47,21 +46,22 @@ public class RackLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testListRacks() { Iterable racks = env.datacenter.listRacks(); - assertEquals(Iterables.size(racks), 1); + assertEquals(size(racks), 1); - racks = env.datacenter.listRacks(name(env.rack.getName())); - assertEquals(Iterables.size(racks), 1); + racks = filter(env.datacenter.listRacks(), name(env.rack.getName())); + assertEquals(size(racks), 1); - racks = env.datacenter.listRacks(name(env.rack.getName() + "FAIL")); - assertEquals(Iterables.size(racks), 0); + racks = filter(env.datacenter.listRacks(), name(env.rack.getName() + "FAIL")); + assertEquals(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); + private static Predicate name(final String name) { + return new Predicate() { + @Override + public boolean apply(Rack input) { + return input.getName().equals(name); + } + }; } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java index c837208..4c75f62 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java @@ -16,10 +16,11 @@ */ package org.jclouds.abiquo.domain.infrastructure; -import static org.jclouds.abiquo.predicates.infrastructure.RemoteServicePredicates.type; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.size; 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; @@ -35,7 +36,7 @@ import org.testng.annotations.Test; import com.abiquo.model.enumerator.RemoteServiceType; import com.abiquo.server.core.infrastructure.RemoteServiceDto; -import com.google.common.collect.Iterables; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link RemoteService} domain class. @@ -46,7 +47,7 @@ import com.google.common.collect.Iterables; public class RemoteServiceLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testUpdate() { // Update the remote service - RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.VIRTUAL_FACTORY)); + RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.VIRTUAL_FACTORY)); rs.setUri(rs.getUri()); rs.update(); @@ -58,7 +59,7 @@ public class RemoteServiceLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testDelete() { - RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.BPM_SERVICE)); + RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.BPM_SERVICE)); rs.delete(); // Recover the deleted remote service @@ -76,12 +77,12 @@ public class RemoteServiceLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testIsAvailableNonCheckeable() { - RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.DHCP_SERVICE)); + RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.DHCP_SERVICE)); assertTrue(rs.isAvailable()); } public void testIsAvailable() { - RemoteService rs = env.datacenter.findRemoteService(type(RemoteServiceType.NODE_COLLECTOR)); + RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.NODE_COLLECTOR)); assertTrue(rs.isAvailable()); } @@ -98,15 +99,19 @@ public class RemoteServiceLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testListRemoteServices() { Iterable remoteServices = env.datacenter.listRemoteServices(); - assertEquals(Iterables.size(remoteServices), env.remoteServices.size()); + assertEquals(size(remoteServices), env.remoteServices.size()); - remoteServices = env.datacenter.listRemoteServices(type(RemoteServiceType.NODE_COLLECTOR)); - assertEquals(Iterables.size(remoteServices), 1); + remoteServices = filter(env.datacenter.listRemoteServices(), type(RemoteServiceType.NODE_COLLECTOR)); + assertEquals(size(remoteServices), 1); } - public void testFindRemoteService() { - RemoteService remoteService = env.datacenter.findRemoteService(type(RemoteServiceType.NODE_COLLECTOR)); - assertNotNull(remoteService); + private static Predicate type(final RemoteServiceType type) { + return new Predicate() { + @Override + public boolean apply(RemoteService input) { + return input.getType().equals(type); + } + }; } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java index 1cf339f..c8cc8d6 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java @@ -16,16 +16,15 @@ */ package org.jclouds.abiquo.domain.infrastructure; +import static com.google.common.collect.Iterables.filter; +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 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; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link StorageDevice} domain class. @@ -49,24 +48,22 @@ public class StorageDeviceLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testListStorageDevices() { Iterable storageDevices = env.datacenter.listStorageDevices(); - assertEquals(Iterables.size(storageDevices), 1); + assertEquals(size(storageDevices), 1); - storageDevices = env.datacenter.listStorageDevices(StorageDevicePredicates.name(env.storageDevice.getName())); - assertEquals(Iterables.size(storageDevices), 1); + storageDevices = filter(env.datacenter.listStorageDevices(), name(env.storageDevice.getName())); + assertEquals(size(storageDevices), 1); - storageDevices = env.datacenter.listStorageDevices(StorageDevicePredicates.name(env.storageDevice.getName() - + "FAIL")); - assertEquals(Iterables.size(storageDevices), 0); + storageDevices = filter(env.datacenter.listStorageDevices(), name(env.storageDevice.getName() + "FAIL")); + assertEquals(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); + private static Predicate name(final String name) { + return new Predicate() { + @Override + public boolean apply(StorageDevice input) { + return input.getName().equals(name); + } + }; } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java index 2d49d95..7c2d2d9 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java @@ -16,16 +16,16 @@ */ package org.jclouds.abiquo.domain.infrastructure; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +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 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; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link StorageDevice} domain class. @@ -43,8 +43,12 @@ public class StoragePoolLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testUpdate() { try { - Tier tier3 = env.datacenter.findTier(TierPredicates.name("Default Tier 3")); - assertNotNull(tier3); + Tier tier3 = find(env.datacenter.listTiers(), new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals("Default Tier 3"); + } + }); env.storagePool.setTier(tier3); env.storagePool.update(); @@ -59,26 +63,26 @@ public class StoragePoolLiveApiTest extends BaseAbiquoApiLiveApiTest { public void testListStoragePool() { Iterable storagePools = env.storageDevice.listStoragePools(); - assertEquals(Iterables.size(storagePools), 1); + assertEquals(size(storagePools), 1); - storagePools = env.storageDevice.listStoragePools(StoragePoolPredicates.name(env.storagePool.getName())); - assertEquals(Iterables.size(storagePools), 1); + storagePools = filter(env.storageDevice.listStoragePools(), name(env.storagePool.getName())); + assertEquals(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); + storagePools = filter(env.storageDevice.listStoragePools(), name(env.storagePool.getName() + "FAIL")); + assertEquals(size(storagePools), 0); } public void testRefreshStoragePool() { env.storagePool.refresh(); } + private static Predicate name(final String name) { + return new Predicate() { + @Override + public boolean apply(StoragePool input) { + return input.getName().equals(name); + } + }; + } + } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java index 1a139b6..c04b3b6 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java @@ -16,14 +16,16 @@ */ package org.jclouds.abiquo.domain.infrastructure; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.size; 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; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link StorageDevice} domain class. @@ -42,20 +44,28 @@ public class TierLiveApiTest extends BaseAbiquoApiLiveApiTest { tier.setName("Updated tier"); tier.update(); - // Recover the updated tier - Tier updated = env.datacenter.findTier(TierPredicates.name("Updated tier")); - assertEquals(updated.getName(), "Updated tier"); + // Verify the tier has been updated + find(env.datacenter.listTiers(), name("Updated tier")); - // Set original name + // Restore the original name tier.setName(previousName); tier.update(); } public void testListTiers() { Iterable tiers = env.datacenter.listTiers(); - assertEquals(Iterables.size(tiers), 4); + assertEquals(size(tiers), 4); - tiers = env.datacenter.listTiers(TierPredicates.name("FAIL")); - assertEquals(Iterables.size(tiers), 0); + tiers = filter(env.datacenter.listTiers(), name("FAIL")); + assertEquals(size(tiers), 0); + } + + private static Predicate name(final String name) { + return new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals(name); + } + }; } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java index 69ca332..e0056dc 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.network; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; @@ -29,13 +30,13 @@ 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.jclouds.abiquo.predicates.IpPredicates; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link ExternalNetwork} domain class. @@ -91,8 +92,12 @@ public class ExternalNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { assertEquals(externalNetwork.getSecondaryDNS(), "8.8.8.8"); // Refresh the external network - ExternalNetwork en = env.enterprise.findExternalNetwork(env.datacenter, - NetworkPredicates. name(externalNetwork.getName())); + ExternalNetwork en = find(env.enterprise.listExternalNetworks(env.datacenter), new Predicate() { + @Override + public boolean apply(ExternalNetwork input) { + return input.getName().equals(externalNetwork.getName()); + } + }); assertEquals(en.getId(), externalNetwork.getId()); assertEquals(en.getName(), "External network Updated"); @@ -141,7 +146,7 @@ public class ExternalNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testGetNetworkFromIp() { - ExternalIp ip = externalNetwork.findIp(IpPredicates. notUsed()); + ExternalIp ip = find(externalNetwork.listIps(), IpPredicates. notUsed()); ExternalNetwork network = ip.getNetwork(); assertEquals(network.getId(), externalNetwork.getId()); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java index 20f9541..ac1fb2b 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.network; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; @@ -30,7 +31,7 @@ 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.jclouds.abiquo.predicates.IpPredicates; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -131,7 +132,7 @@ public class PrivateNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testGetNetworkFromIp() { - PrivateIp ip = privateNetwork.findIp(IpPredicates. notUsed()); + PrivateIp ip = find(privateNetwork.listIps(), IpPredicates. notUsed()); PrivateNetwork network = ip.getNetwork(); assertEquals(network.getId(), privateNetwork.getId()); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java index f221e14..203aba6 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.network; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; @@ -29,7 +30,7 @@ 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.IpPredicates; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -135,7 +136,7 @@ public class PublicNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testGetNetworkFromIp() { - PublicIp ip = publicNetwork.findIp(IpPredicates. notUsed()); + PublicIp ip = find(publicNetwork.listIps(), IpPredicates. notUsed()); PublicNetwork network = ip.getNetwork(); assertEquals(network.getId(), publicNetwork.getId()); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java index 239caca..96981b3 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.domain.network; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.jclouds.abiquo.util.Assert.assertHasError; import static org.testng.Assert.assertEquals; @@ -30,13 +31,13 @@ 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.jclouds.abiquo.predicates.IpPredicates; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; +import com.google.common.base.Predicate; /** * Live integration tests for the {@link UnmanagedNetwork} domain class. @@ -93,8 +94,13 @@ public class UnmanagedNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { assertEquals(unmanagedNetwork.getSecondaryDNS(), "8.8.8.8"); // Refresh the unmanaged network - UnmanagedNetwork en = env.enterprise.findUnmanagedNetwork(env.datacenter, - NetworkPredicates. name(unmanagedNetwork.getName())); + UnmanagedNetwork en = find(env.enterprise.listUnmanagedNetworks(env.datacenter), + new Predicate() { + @Override + public boolean apply(UnmanagedNetwork input) { + return input.getName().equals(unmanagedNetwork.getName()); + } + }); assertEquals(en.getId(), unmanagedNetwork.getId()); assertEquals(en.getName(), "Unmanaged network Updated"); @@ -143,7 +149,7 @@ public class UnmanagedNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { } public void testGetNetworkFromIp() { - UnmanagedIp ip = unmanagedNetwork.findIp(IpPredicates. notUsed()); + UnmanagedIp ip = find(unmanagedNetwork.listIps(), IpPredicates. notUsed(), null); // Unmanaged networks do not have IPs until attached to VMs assertNull(ip); } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java b/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java index 86fdd48..4a3579c 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java @@ -17,6 +17,7 @@ package org.jclouds.abiquo.environment; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.find; import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -33,14 +34,12 @@ 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 org.testng.collections.Lists; +import com.google.common.base.Predicate; import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; @@ -127,7 +126,12 @@ public class CloudTestEnvironment extends InfrastructureTestEnvironment { } protected void findDefaultEnterprise() { - defaultEnterprise = context.getAdministrationService().findEnterprise(EnterprisePredicates.name("Abiquo")); + defaultEnterprise = find(context.getAdministrationService().listEnterprises(), new Predicate() { + @Override + public boolean apply(Enterprise input) { + return input.getName().equals("Abiquo"); + } + }); } protected void createVirtualDatacenter() { @@ -142,8 +146,12 @@ public class CloudTestEnvironment extends InfrastructureTestEnvironment { virtualDatacenter.save(); assertNotNull(virtualDatacenter.getId()); - privateNetwork = virtualDatacenter - .findPrivateNetwork(NetworkPredicates. name(privateNetwork.getName())); + privateNetwork = find(virtualDatacenter.listPrivateNetworks(), new Predicate() { + @Override + public boolean apply(PrivateNetwork input) { + return input.getName().equals(privateNetwork.getName()); + } + }); } protected void createVirtualAppliance() { diff --git a/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java b/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java index b8101fc..0c2add5 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java @@ -38,7 +38,6 @@ 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.NetworkInterface; import org.jclouds.abiquo.domain.infrastructure.Rack; import org.jclouds.abiquo.domain.infrastructure.RemoteService; @@ -55,17 +54,10 @@ 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.util.Config; import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.enumerator.RemoteServiceType; -import com.google.common.collect.Iterables; +import com.google.common.base.Predicate; import com.google.common.io.LineProcessor; import com.google.common.io.Resources; @@ -124,8 +116,6 @@ public class InfrastructureTestEnvironment implements TestEnvironment { public Role anotherRole; - public ManagedRack ucsRack; - public InfrastructureTestEnvironment(final AbiquoContext context) { super(); this.context = context; @@ -173,7 +163,6 @@ public class InfrastructureTestEnvironment implements TestEnvironment { deleteStoragePool(); deleteStorageDevice(); deleteMachine(); - deleteUcsRack(); deleteRack(); deleteDatacenter(); deleteEnterprise(); @@ -209,14 +198,26 @@ public class InfrastructureTestEnvironment implements TestEnvironment { HypervisorType type = HypervisorType.valueOf(Config.get("abiquo.hypervisor.type")); String user = Config.get("abiquo.hypervisor.user"); String pass = Config.get("abiquo.hypervisor.pass"); + final String vswitchName = Config.get("abiquo.hypervisor.vswitch"); + final String datastoreName = Config.get("abiquo.hypervisor.datastore"); machine = datacenter.discoverSingleMachine(ip, type, user, pass); NetworkServiceType nst = datacenter.defaultNetworkServiceType(); - NetworkInterface vswitch = machine.findAvailableVirtualSwitch(Config.get("abiquo.hypervisor.vswitch")); + NetworkInterface vswitch = find(machine.getNetworkInterfaces(), new Predicate() { + @Override + public boolean apply(NetworkInterface input) { + return input.getName().equals(vswitchName); + } + }); vswitch.setNetworkServiceType(nst); - Datastore datastore = machine.findDatastore(Config.get("abiquo.hypervisor.datastore")); + Datastore datastore = find(machine.getDatastores(), new Predicate() { + @Override + public boolean apply(Datastore input) { + return input.getName().equals(datastoreName); + } + }); datastore.setEnabled(true); machine.setRack(rack); @@ -230,27 +231,19 @@ public class InfrastructureTestEnvironment implements TestEnvironment { 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"); + final 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)); + StorageDeviceMetadata metadata = find(devices, new Predicate() { + @Override + public boolean apply(StorageDeviceMetadata input) { + return input.getType().equals(type); + } + }); storageDevice = StorageDevice.builder(context.getApiContext(), datacenter) // .name(PREFIX + "Storage Device")// @@ -266,10 +259,20 @@ public class InfrastructureTestEnvironment implements TestEnvironment { } protected void createStoragePool() { - String pool = Config.get("abiquo.storage.pool"); + final String pool = Config.get("abiquo.storage.pool"); - storagePool = storageDevice.findRemoteStoragePool(StoragePoolPredicates.name(pool)); - tier = datacenter.findTier(TierPredicates.name("Default Tier 1")); + storagePool = find(storageDevice.listRemoteStoragePools(), new Predicate() { + @Override + public boolean apply(StoragePool input) { + return input.getName().equals(pool); + } + }); + tier = find(datacenter.listTiers(), new Predicate() { + @Override + public boolean apply(Tier input) { + return input.getName().equals("Default Tier 1"); + } + }); storagePool.setTier(tier); storagePool.save(); @@ -278,8 +281,9 @@ public class InfrastructureTestEnvironment implements TestEnvironment { } protected void createUsers() { - Role userRole = administrationService.findRole(RolePredicates.name("USER")); - Role enterpriseAdminRole = administrationService.findRole(RolePredicates.name("ENTERPRISE_ADMIN")); + Iterable roles = administrationService.listRoles(); + Role userRole = find(roles, role("USER")); + Role enterpriseAdminRole = find(roles, role("ENTERPRISE_ADMIN")); user = User.builder(context.getApiContext(), enterprise, userRole).name(randomName(), randomName()) .nick("jclouds").authType("ABIQUO").description(randomName()).email(randomName() + "@abiquo.com") @@ -370,14 +374,14 @@ public class InfrastructureTestEnvironment implements TestEnvironment { String nick = user.getNick(); user.delete(); // Nick is unique in an enterprise - assertNull(enterprise.findUser(UserPredicates.nick(nick))); + assertNull(find(enterprise.listUsers(), nick(nick), null)); } if (enterpriseAdmin != null) { String nick = enterpriseAdmin.getNick(); enterpriseAdmin.delete(); // Nick is unique in an enterprise - assertNull(enterprise.findUser(UserPredicates.nick(nick))); + assertNull(find(enterprise.listUsers(), nick(nick), null)); } } @@ -422,14 +426,6 @@ public class InfrastructureTestEnvironment implements TestEnvironment { } } - 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 @@ -479,7 +475,21 @@ public class InfrastructureTestEnvironment implements TestEnvironment { }); } - public RemoteService findRemoteService(final RemoteServiceType type) { - return find(remoteServices, RemoteServicePredicates.type(type)); + private static Predicate role(final String role) { + return new Predicate() { + @Override + public boolean apply(Role input) { + return input.getName().equals(role); + } + }; + } + + private static Predicate nick(final String nick) { + return new Predicate() { + @Override + public boolean apply(User input) { + return input.getNick().equals(nick); + } + }; } } diff --git a/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java b/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java deleted file mode 100644 index 0c1c89b..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/events/handlers/BlockingEventHandlerTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureApiTest.java index 04bb6ac..3064935 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/features/InfrastructureApiTest.java @@ -35,7 +35,6 @@ 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.fallbacks.MapHttp4xxCodesToExceptions; import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.http.functions.ReleasePayloadAndReturn; @@ -53,24 +52,16 @@ 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; @@ -317,325 +308,6 @@ public class InfrastructureApiTest extends BaseAbiquoApiTest checkFilters(request); } - /*********************** Managed Rack ***********************/ - - public void testListManagedRacks() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "listManagedRacks", DatacenterDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testCreateManagedRack() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "createManagedRack", DatacenterDto.class, - UcsRackDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create( - method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetManagedRack() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "getManagedRack", DatacenterDto.class, Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testUpdateManagedRack() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "updateManagedRack", UcsRackDto.class); - - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListServiceProfiles() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "listServiceProfiles", UcsRackDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListServiceProfilesWithOptions() throws SecurityException, NoSuchMethodException, IOException { - FilterOptions options = FilterOptions.builder().startWith(1).limit(2).build(); - - Invokable method = method(InfrastructureApi.class, "listServiceProfiles", UcsRackDto.class, - FilterOptions.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListOrganizations() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "listOrganizations", UcsRackDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListOrganizationsWithOptions() throws SecurityException, NoSuchMethodException, IOException { - FilterOptions options = FilterOptions.builder().has("org").build(); - - Invokable method = method(InfrastructureApi.class, "listOrganizations", UcsRackDto.class, - FilterOptions.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListServiceProfileTemplates() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "listServiceProfileTemplates", UcsRackDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListServiceProfileTemplatesWithOptions() throws SecurityException, NoSuchMethodException, - IOException { - FilterOptions options = FilterOptions.builder().ascendant(true).build(); - - Invokable method = method(InfrastructureApi.class, "listServiceProfileTemplates", UcsRackDto.class, - FilterOptions.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testAssociateLogicServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "associateLogicServer", UcsRackDto.class, - LogicServerDto.class, OrganizationDto.class, String.class); - GeneratedHttpRequest request = processor.apply(Invocation.create( - method, - ImmutableList. of(InfrastructureResources.managedRackPut(), - InfrastructureResources.logicServerPut(), InfrastructureResources.organizationPut(), "blade"))); - - assertRequestLineEquals( - request, - "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/associate?bladeDn=blade&lsName=server&org=org-root/org-Finance HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testAssociateTemplate() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "associateTemplate", UcsRackDto.class, - LogicServerDto.class, OrganizationDto.class, String.class, String.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of( - 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&lsName=server&org=org-root/org-Finance HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testCloneAndAssociateLogicServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "cloneAndAssociateLogicServer", UcsRackDto.class, - LogicServerDto.class, OrganizationDto.class, String.class, String.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of( - 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&lsName=server&org=org-root/org-Finance HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testDissociateLogicServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "dissociateLogicServer", UcsRackDto.class, - LogicServerDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create( - method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testCloneLogicServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "cloneLogicServer", UcsRackDto.class, - LogicServerDto.class, OrganizationDto.class, String.class); - GeneratedHttpRequest request = processor.apply(Invocation.create( - method, - ImmutableList. of(InfrastructureResources.managedRackPut(), - InfrastructureResources.logicServerPut(), InfrastructureResources.organizationPut(), "name"))); - - assertRequestLineEquals( - request, - "POST http://localhost/api/admin/datacenters/1/racks/1/logicservers/clone?newName=name&lsName=server&org=org-root/org-Finance HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testDeleteLogicServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "deleteLogicServer", UcsRackDto.class, - LogicServerDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create( - method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testListFsms() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "listFsms", UcsRackDto.class, String.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - /*********************** Remote Service **********************/ public void testListRemoteServices() throws SecurityException, NoSuchMethodException, IOException { @@ -1130,109 +802,6 @@ public class InfrastructureApiTest extends BaseAbiquoApiTest checkFilters(request); } - /*********************** Blade ***********************/ - - public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "powerOff", MachineDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "powerOn", MachineDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetLogicServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "getLogicServer", MachineDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testLedOn() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "ledOn", MachineDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testLedOff() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "ledOff", MachineDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetLocatorLed() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(InfrastructureApi.class, "getLocatorLed", MachineDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - /*********************** Storage Device ***********************/ public void testListStorageDevices() throws SecurityException, NoSuchMethodException, IOException { diff --git a/abiquo/src/test/java/org/jclouds/abiquo/features/PricingApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/features/PricingApiTest.java deleted file mode 100644 index 94ef8ed..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/features/PricingApiTest.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF 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 static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.abiquo.domain.PricingResources; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.pricing.CostCodeCurrenciesDto; -import com.abiquo.server.core.pricing.CostCodeDto; -import com.abiquo.server.core.pricing.CostCodesDto; -import com.abiquo.server.core.pricing.CurrenciesDto; -import com.abiquo.server.core.pricing.CurrencyDto; -import com.abiquo.server.core.pricing.PricingCostCodeDto; -import com.abiquo.server.core.pricing.PricingCostCodesDto; -import com.abiquo.server.core.pricing.PricingTemplateDto; -import com.abiquo.server.core.pricing.PricingTemplatesDto; -import com.abiquo.server.core.pricing.PricingTierDto; -import com.abiquo.server.core.pricing.PricingTiersDto; -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; - -/** - * Tests annotation parsing of {@code PricingApi}. - * - * @author Ignasi Barrera - * @author Susana Acedo - */ -@Test(groups = "unit", singleThreaded = true, testName = "PricingApiTest") -public class PricingApiTest extends BaseAbiquoApiTest { - /*********************** Currency ***********************/ - - public void testListCurrencies() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "listCurrencies"); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.of())); - - 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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetCurrency() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getCurrency", Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(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); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCreateCurrency() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "createCurrency", CurrencyDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testUpdateCurrency() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "updateCurrency", CurrencyDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testDeleteCurrency() throws SecurityException, NoSuchMethodException { - Invokable method = method(PricingApi.class, "deleteCurrency", CurrencyDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(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); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - /*********************** Cost Code ***********************/ - - public void testListCostCodes() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "listCostCodes"); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.of())); - - assertRequestLineEquals(request, "GET http://localhost/api/config/costcodes HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + CostCodesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetCostCode() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getCostCode", Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/costcodes/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCreateCostCode() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "createCostCode", CostCodeDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.costcodePost()))); - - assertRequestLineEquals(request, "POST http://localhost/api/config/costcodes HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.costcodePostPayload()), CostCodeDto.class, - CostCodeDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testUpdateCostCode() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "updateCostCode", CostCodeDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.costcodePut()))); - - assertRequestLineEquals(request, "PUT http://localhost/api/config/costcodes/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.costcodePutPayload()), CostCodeDto.class, - CostCodeDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testDeleteCostCode() throws SecurityException, NoSuchMethodException { - Invokable method = method(PricingApi.class, "deleteCostCode", CostCodeDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.costcodePut()))); - - assertRequestLineEquals(request, "DELETE http://localhost/api/config/costcodes/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - /*********************** Pricing Template ***********************/ - - public void testListPricingTemplates() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "listPricingTemplates"); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.of())); - - assertRequestLineEquals(request, "GET http://localhost/api/config/pricingtemplates HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplatesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetPricingTemplate() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getPricingTemplate", Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/pricingtemplates/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplateDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCreatePricingTemplate() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "createPricingTemplate", PricingTemplateDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.pricingtemplatePost()))); - - assertRequestLineEquals(request, "POST http://localhost/api/config/pricingtemplates HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplateDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.pricingtemplatePostPayload()), PricingTemplateDto.class, - PricingTemplateDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testUpdatePricingTemplate() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "updatePricingTemplate", PricingTemplateDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.pricingtemplatePut()))); - - assertRequestLineEquals(request, "PUT http://localhost/api/config/pricingtemplates/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTemplateDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.pricingtemplatePutPayload()), PricingTemplateDto.class, - PricingTemplateDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testDeletePricingTemplate() throws SecurityException, NoSuchMethodException { - Invokable method = method(PricingApi.class, "deletePricingTemplate", PricingTemplateDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.pricingtemplatePut()))); - - assertRequestLineEquals(request, "DELETE http://localhost/api/config/pricingtemplates/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - /*********************** Cost Code Currency ***********************/ - - public void testGetCostCodeCurrencies() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getCostCodeCurrencies", Integer.class, Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1, 1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/costcodes/1/currencies?idCurrency=1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeCurrenciesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testUpdateCostCodeCurrencies() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "updateCostCodeCurrencies", Integer.class, - CostCodeCurrenciesDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(1, PricingResources.costcodecurrencyPut()))); - - assertRequestLineEquals(request, "PUT http://localhost/api/config/costcodes/1/currencies HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + CostCodeCurrenciesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.costcodecurrencyPutPayload()), - CostCodeCurrenciesDto.class, CostCodeCurrenciesDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - /*********************** Pricing Cost Code ***********************/ - - public void testGetPricingCostCodes() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getPricingCostCodes", Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/pricingtemplates/1/costcodes HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingCostCodesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testGetPricingCostCode() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getPricingCostCode", Integer.class, Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1, 1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/pricingtemplates/1/costcodes/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingCostCodeDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testUpdatePricingCostCode() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "updatePricingCostCode", PricingCostCodeDto.class, - Integer.class, Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.pricingCostcodePut(), 1, 1))); - - assertRequestLineEquals(request, "PUT http://localhost/api/config/pricingtemplates/1/costcodes/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingCostCodeDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.pricingCostCodePutPayload()), PricingCostCodeDto.class, - PricingCostCodeDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - /*********************** Pricing Tier ***************************/ - - public void testGetPricingTiers() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getPricingTiers", Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/pricingtemplates/1/tiers HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTiersDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testGetPricingTier() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "getPricingTier", Integer.class, Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList. of(1, 1))); - - assertRequestLineEquals(request, "GET http://localhost/api/config/pricingtemplates/1/tiers/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTierDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testUpdatePricingTier() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(PricingApi.class, "updatePricingTier", PricingTierDto.class, Integer.class, - Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList. of(PricingResources.pricingTierPut(), 1, 2))); - - assertRequestLineEquals(request, "PUT http://localhost/api/config/pricingtemplates/1/tiers/2 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PricingTierDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(PricingResources.pricingTierPutPayload()), PricingTierDto.class, - PricingTierDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } -} diff --git a/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java b/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java index 8dc00a2..e11e43a 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/internal/AsyncMonitorTest.java @@ -32,9 +32,9 @@ 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.abiquo.monitor.events.MonitorEvent; import org.jclouds.rest.ApiContext; import org.testng.annotations.Test; diff --git a/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java index 534f072..b230525 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/internal/BaseAbiquoApiLiveApiTest.java @@ -38,13 +38,6 @@ public abstract class BaseAbiquoApiLiveApiTest extends BaseAbiquoLiveApiTest { setupEnvironment(); } - // @BeforeSuite(groups = "ucs", dependsOnMethods = "setupContext") - protected void setupUcsEnvironment() throws Exception { - if (env != null) { - env.createUcsRack(); - } - } - @Override @AfterSuite(groups = "api") protected void tearDownContext() { diff --git a/abiquo/src/test/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandlerTest.java b/abiquo/src/test/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandlerTest.java new file mode 100644 index 0000000..a438abb --- /dev/null +++ b/abiquo/src/test/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandlerTest.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF 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.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.monitor.events.MonitorEvent; +import org.jclouds.abiquo.monitor.events.MonitorEvent.Type; +import org.jclouds.abiquo.monitor.handlers.BlockingEventHandler; +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/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNicsLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNicsLiveApiTest.java index d8d7981..7bb9a7b 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNicsLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNicsLiveApiTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.abiquo.strategy.cloud; +import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.size; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -26,12 +27,12 @@ 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.base.Predicate; import com.google.common.collect.Lists; /** @@ -62,8 +63,12 @@ public class ListAttachedNicsLiveApiTest extends BaseAbiquoStrategyLiveApiTest { publicIp = env.virtualDatacenter.listAvailablePublicIps().get(0); env.virtualDatacenter.purchasePublicIp(publicIp); - publicIp = env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(publicIp.getIp())); - assertNotNull(publicIp); + publicIp = find(env.virtualDatacenter.listPurchasedPublicIps(), new Predicate() { + @Override + public boolean apply(PublicIp input) { + return input.getIp().equals(publicIp.getIp()); + } + }); env.virtualMachine.setNics(Lists.> newArrayList(privateIp, externalIp, publicIp), Lists. newArrayList(env.unmanagedNetwork)); @@ -72,9 +77,14 @@ public class ListAttachedNicsLiveApiTest extends BaseAbiquoStrategyLiveApiTest { @AfterClass(groups = "api") protected void tearDownStrategy() { env.virtualMachine.setNics(Lists.> newArrayList(privateIp)); - String address = publicIp.getIp(); + final String address = publicIp.getIp(); env.virtualDatacenter.releasePublicIp(publicIp); - assertNull(env.virtualDatacenter.findPurchasedPublicIp(IpPredicates. address(address))); + assertNull(find(env.virtualDatacenter.listPurchasedPublicIps(), new Predicate() { + @Override + public boolean apply(PublicIp input) { + return input.getIp().equals(address); + } + }, null)); } public void testExecute() { @@ -82,16 +92,4 @@ public class ListAttachedNicsLiveApiTest extends BaseAbiquoStrategyLiveApiTest { assertNotNull(vapps); assertEquals(4, size(vapps)); } - - 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/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliancesLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliancesLiveApiTest.java index 1db2e04..4817913 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliancesLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliancesLiveApiTest.java @@ -17,12 +17,10 @@ package org.jclouds.abiquo.strategy.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 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; @@ -47,17 +45,4 @@ public class ListVirtualAppliancesLiveApiTest extends BaseAbiquoStrategyLiveApiT 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/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacentersLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacentersLiveApiTest.java index 314f714..a3a6aca 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacentersLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacentersLiveApiTest.java @@ -23,7 +23,6 @@ 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; @@ -49,27 +48,14 @@ public class ListVirtualDatacentersLiveApiTest extends BaseAbiquoStrategyLiveApi 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() { + public void testExecuteOptionsWithResults() { Iterable vdcs = strategy.execute(VirtualDatacenterOptions.builder() .datacenterId(env.datacenter.getId()).enterpriseId(env.defaultEnterprise.getId()).build()); assertNotNull(vdcs); assertEquals(size(vdcs), 1); } - public void testExecutePredicateOptionsWithoutResults() { + public void testExecuteOptionsWithoutResults() { Iterable vdcs = strategy.execute(VirtualDatacenterOptions.builder() .enterpriseId(env.enterprise.getId()).build()); assertNotNull(vdcs); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachinesLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachinesLiveApiTest.java index 09568d7..a5aed62 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachinesLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/strategy/cloud/ListVirtualMachinesLiveApiTest.java @@ -17,14 +17,12 @@ package org.jclouds.abiquo.strategy.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.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; @@ -52,19 +50,6 @@ public class ListVirtualMachinesLiveApiTest extends BaseAbiquoStrategyLiveApiTes 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 = Lists.newArrayList(); diff --git a/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplatesLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplatesLiveApiTest.java index 9d1275f..cc5f9b9 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplatesLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplatesLiveApiTest.java @@ -17,12 +17,10 @@ package org.jclouds.abiquo.strategy.enterprise; 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.ListVirtualAppliances; import org.testng.annotations.BeforeClass; @@ -48,19 +46,4 @@ public class ListVirtualMachineTemplatesLiveApiTest extends BaseAbiquoStrategyLi 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/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/ListMachinesLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/ListMachinesLiveApiTest.java index 059c336..18ece95 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/ListMachinesLiveApiTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/strategy/infrastructure/ListMachinesLiveApiTest.java @@ -17,12 +17,10 @@ package org.jclouds.abiquo.strategy.infrastructure; 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; @@ -47,16 +45,4 @@ public class ListMachinesLiveApiTest extends BaseAbiquoStrategyLiveApiTest { 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); - } } -- 1.7.12.4 (Apple Git-37)