Merge pull request #936 from abiquo/cleanup-strategies

Cleanup unnecessary strategies
This commit is contained in:
Adrian Cole 2012-11-01 13:12:32 -07:00
commit d4eb847a55
54 changed files with 683 additions and 2596 deletions

View File

@ -19,8 +19,6 @@
package org.jclouds.abiquo.features.services;
import java.util.List;
import org.jclouds.abiquo.domain.config.Category;
import org.jclouds.abiquo.domain.config.License;
import org.jclouds.abiquo.domain.config.Privilege;
@ -67,11 +65,6 @@ public interface AdministrationService {
*/
Datacenter getDatacenter(final Integer datacenterId);
/**
* Get the list of datacenters with the given ids.
*/
Iterable<Datacenter> getDatacenters(final List<Integer> datacenterIds);
/*********************** Machine ***********************/
/**
@ -160,6 +153,15 @@ public interface AdministrationService {
*/
Privilege findPrivilege(final Predicate<Privilege> filter);
/**
* Get a privilege given its id.
*
* @param privilegeId
* The id of the privilege.
* @return The privilege.
*/
Privilege getPrivilege(Integer privilegeId);
/*********************** User ***********************/
/**
@ -245,4 +247,13 @@ public interface AdministrationService {
* <code>null</code> if none is found.
*/
Category findCategory(final Predicate<Category> filter);
/**
* Get the category identified by the given id.
*
* @param categoryId
* The id of the category.
* @return The requested category.
*/
Category getCategory(Integer categoryId);
}

View File

@ -59,6 +59,15 @@ public interface PricingService {
*/
Currency findCurrency(final Predicate<Currency> 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 ***********************/
/**
@ -77,37 +86,55 @@ public interface PricingService {
*/
CostCode findCostCode(final Predicate<CostCode> 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.
*/
public Iterable<PricingTemplate> listPricingTemplates();
Iterable<PricingTemplate> listPricingTemplates();
/**
* Get the list of pricingtemplates matching the given filter.
*/
public Iterable<PricingTemplate> listPricingTemplates(final Predicate<PricingTemplate> filter);
Iterable<PricingTemplate> listPricingTemplates(final Predicate<PricingTemplate> filter);
/**
* Get the first pricingtemplates that matches the given filter or
* <code>null</code> if none is found.
*/
public PricingTemplate findPricingTemplate(final Predicate<PricingTemplate> filter);
PricingTemplate findPricingTemplate(final Predicate<PricingTemplate> 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
*/
public Iterable<CostCodeCurrency> getCostCodeCurrencies(Integer costcodeid, Integer currencyid);
Iterable<CostCodeCurrency> getCostCodeCurrencies(Integer costcodeid, Integer currencyid);
/*********************** PricingCostCode ***********************/
/**
* Get pricing cost codes
*/
public Collection<PricingCostCode> getPricingCostCodes(Integer pricingTemplateId);
Collection<PricingCostCode> getPricingCostCodes(Integer pricingTemplateId);
/**
* Get a pricing cost code

View File

@ -20,15 +20,15 @@
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.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.config.Category;
import org.jclouds.abiquo.domain.config.License;
import org.jclouds.abiquo.domain.config.Privilege;
@ -43,21 +43,23 @@ import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.domain.infrastructure.Machine;
import org.jclouds.abiquo.features.services.AdministrationService;
import org.jclouds.abiquo.reference.ValidationErrors;
import org.jclouds.abiquo.strategy.admin.ListRoles;
import org.jclouds.abiquo.strategy.config.ListCategories;
import org.jclouds.abiquo.strategy.config.ListLicenses;
import org.jclouds.abiquo.strategy.config.ListPrivileges;
import org.jclouds.abiquo.strategy.config.ListProperties;
import org.jclouds.abiquo.strategy.enterprise.ListEnterprises;
import org.jclouds.abiquo.strategy.infrastructure.ListDatacenters;
import org.jclouds.abiquo.strategy.infrastructure.ListMachines;
import org.jclouds.collect.Memoized;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.appslibrary.CategoriesDto;
import com.abiquo.server.core.appslibrary.CategoryDto;
import com.abiquo.server.core.config.LicensesDto;
import com.abiquo.server.core.config.SystemPropertiesDto;
import com.abiquo.server.core.enterprise.EnterpriseDto;
import com.abiquo.server.core.enterprise.EnterprisePropertiesDto;
import com.abiquo.server.core.enterprise.EnterprisesDto;
import com.abiquo.server.core.enterprise.PrivilegeDto;
import com.abiquo.server.core.enterprise.PrivilegesDto;
import com.abiquo.server.core.enterprise.RoleDto;
import com.abiquo.server.core.enterprise.RolesDto;
import com.abiquo.server.core.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;
@ -74,30 +76,9 @@ public class BaseAdministrationService implements AdministrationService {
@VisibleForTesting
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
@VisibleForTesting
protected final ListDatacenters listDatacenters;
@VisibleForTesting
protected final ListMachines listMachines;
@VisibleForTesting
protected final ListEnterprises listEnterprises;
@VisibleForTesting
protected final ListRoles listRoles;
@VisibleForTesting
protected final ListLicenses listLicenses;
@VisibleForTesting
protected final ListPrivileges listPrivileges;
@VisibleForTesting
protected final ListProperties listProperties;
@VisibleForTesting
protected final ListCategories listCategories;
@VisibleForTesting
protected final Supplier<User> currentUser;
@ -106,19 +87,10 @@ public class BaseAdministrationService implements AdministrationService {
@Inject
protected BaseAdministrationService(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
final ListDatacenters listDatacenters, final ListMachines listMachines, final ListEnterprises listEnterprises,
final ListRoles listRoles, final ListLicenses listLicenses, final ListPrivileges listPrivileges,
final ListProperties listProperties, final ListCategories listCategories,
@Memoized final Supplier<User> currentUser, @Memoized final Supplier<Enterprise> currentEnterprise) {
final ListMachines listMachines, @Memoized final Supplier<User> currentUser,
@Memoized final Supplier<Enterprise> currentEnterprise) {
this.context = checkNotNull(context, "context");
this.listDatacenters = checkNotNull(listDatacenters, "listDatacenters");
this.listMachines = checkNotNull(listMachines, "listMachines");
this.listEnterprises = checkNotNull(listEnterprises, "listEnterprises");
this.listRoles = checkNotNull(listRoles, "listRoles");
this.listLicenses = checkNotNull(listLicenses, "listLicenses");
this.listPrivileges = checkNotNull(listPrivileges, "listPrivileges");
this.listProperties = checkNotNull(listProperties, "listProperties");
this.listCategories = checkNotNull(listCategories, "listCategories");
this.currentUser = checkNotNull(currentUser, "currentUser");
this.currentEnterprise = checkNotNull(currentEnterprise, "currentEnterprise");
}
@ -127,12 +99,18 @@ public class BaseAdministrationService implements AdministrationService {
@Override
public Iterable<Datacenter> listDatacenters() {
return listDatacenters.execute();
DatacentersDto result = context.getApi().getInfrastructureApi().listDatacenters();
return wrap(context, Datacenter.class, result.getCollection());
}
@Override
public Iterable<Datacenter> listDatacenters(final Predicate<Datacenter> filter) {
return listDatacenters.execute(filter);
return filter(listDatacenters(), filter);
}
@Override
public Datacenter findDatacenter(final Predicate<Datacenter> filter) {
return getFirst(listDatacenters(filter), null);
}
@Override
@ -141,16 +119,6 @@ public class BaseAdministrationService implements AdministrationService {
return wrap(context, Datacenter.class, datacenter);
}
@Override
public Datacenter findDatacenter(final Predicate<Datacenter> filter) {
return Iterables.getFirst(listDatacenters(filter), null);
}
@Override
public Iterable<Datacenter> getDatacenters(final List<Integer> datacenterIds) {
return listDatacenters.execute(datacenterIds);
}
/*********************** Machine ***********************/
@Override
@ -172,12 +140,13 @@ public class BaseAdministrationService implements AdministrationService {
@Override
public Iterable<Enterprise> listEnterprises() {
return listEnterprises.execute();
EnterprisesDto result = context.getApi().getEnterpriseApi().listEnterprises();
return wrap(context, Enterprise.class, result.getCollection());
}
@Override
public Iterable<Enterprise> listEnterprises(final Predicate<Enterprise> filter) {
return listEnterprises.execute(filter);
return filter(listEnterprises(), filter);
}
@Override
@ -206,17 +175,18 @@ public class BaseAdministrationService implements AdministrationService {
@Override
public Iterable<Role> listRoles() {
return listRoles.execute();
RolesDto result = context.getApi().getAdminApi().listRoles();
return wrap(context, Role.class, result.getCollection());
}
@Override
public Iterable<Role> listRoles(final Predicate<Role> filter) {
return listRoles.execute(filter);
return filter(listRoles(), filter);
}
@Override
public Role findRole(final Predicate<Role> filter) {
return Iterables.getFirst(listRoles(filter), null);
return getFirst(listRoles(filter), null);
}
@Override
@ -227,19 +197,26 @@ public class BaseAdministrationService implements AdministrationService {
/*********************** Privilege ***********************/
@Override
public Privilege findPrivilege(final Predicate<Privilege> filter) {
return Iterables.getFirst(listPrivileges(filter), null);
}
@Override
public Iterable<Privilege> listPrivileges() {
return listPrivileges.execute();
PrivilegesDto result = context.getApi().getConfigApi().listPrivileges();
return wrap(context, Privilege.class, result.getCollection());
}
@Override
public Iterable<Privilege> listPrivileges(final Predicate<Privilege> filter) {
return listPrivileges.execute(filter);
return filter(listPrivileges(), filter);
}
@Override
public Privilege findPrivilege(final Predicate<Privilege> 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);
}
/*********************** User ***********************/
@ -258,52 +235,68 @@ public class BaseAdministrationService implements AdministrationService {
@Override
public Iterable<License> listLicenses() {
return listLicenses.execute();
LicensesDto result = context.getApi().getConfigApi().listLicenses();
return wrap(context, License.class, result.getCollection());
}
@Override
public Iterable<License> listLicenses(final boolean active) {
LicenseOptions options = LicenseOptions.builder().active(active).build();
return listLicenses.execute(options);
LicensesDto result = context.getApi().getConfigApi().listLicenses(options);
return wrap(context, License.class, result.getCollection());
}
@Override
public Iterable<License> listLicenses(final Predicate<License> filter) {
return listLicenses.execute(filter);
return filter(listLicenses(), filter);
}
@Override
public License findLicense(final Predicate<License> filter) {
return Iterables.getFirst(listLicenses(filter), null);
return getFirst(listLicenses(filter), null);
}
/*********************** System Properties ***********************/
@Override
public Iterable<SystemProperty> listSystemProperties() {
return listProperties.execute();
SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties();
return wrap(context, SystemProperty.class, result.getCollection());
}
@Override
public Iterable<SystemProperty> listSystemProperties(final Predicate<SystemProperty> filter) {
return listProperties.execute(filter);
return filter(listSystemProperties(), filter);
}
@Override
public SystemProperty findSystemProperty(final Predicate<SystemProperty> filter) {
return Iterables.getFirst(listSystemProperties(filter), null);
return getFirst(listSystemProperties(filter), null);
}
@Override
public SystemProperty getSystemProperty(final String name) {
PropertyOptions options = PropertyOptions.builder().name(name).build();
return Iterables.getFirst(listProperties.execute(options), null);
SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties(options);
return getFirst(wrap(context, SystemProperty.class, result.getCollection()), null);
}
@Override
public Iterable<SystemProperty> listSystemProperties(final String component) {
PropertyOptions options = PropertyOptions.builder().component(component).build();
return listProperties.execute(options);
SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties(options);
return wrap(context, SystemProperty.class, result.getCollection());
}
@Override
public Iterable<Category> listCategories() {
CategoriesDto result = context.getApi().getConfigApi().listCategories();
return wrap(context, Category.class, result.getCollection());
}
@Override
public Iterable<Category> listCategories(final Predicate<Category> filter) {
return filter(listCategories(), filter);
}
@Override
@ -312,12 +305,8 @@ public class BaseAdministrationService implements AdministrationService {
}
@Override
public Iterable<Category> listCategories() {
return listCategories.execute();
}
@Override
public Iterable<Category> listCategories(final Predicate<Category> filter) {
return listCategories.execute(filter);
public Category getCategory(Integer categoryId) {
CategoryDto result = context.getApi().getConfigApi().getCategory(categoryId);
return wrap(context, Category.class, result);
}
}

View File

@ -20,18 +20,19 @@
package org.jclouds.abiquo.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.event.Event;
import org.jclouds.abiquo.domain.event.options.EventOptions;
import org.jclouds.abiquo.features.services.EventService;
import org.jclouds.abiquo.strategy.event.ListEvents;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.event.EventsDto;
import com.google.common.annotations.VisibleForTesting;
/**
@ -45,22 +46,20 @@ public class BaseEventService implements EventService {
@VisibleForTesting
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
@VisibleForTesting
protected final ListEvents listEvents;
@Inject
protected BaseEventService(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final ListEvents listEvents) {
protected BaseEventService(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = checkNotNull(context, "context");
this.listEvents = checkNotNull(listEvents, "listEvents");
}
@Override
public Iterable<Event> listEvents() {
return listEvents.execute();
EventsDto result = context.getApi().getEventApi().listEvents();
return wrap(context, Event.class, result.getCollection());
}
@Override
public Iterable<Event> listEvents(final EventOptions options) {
return listEvents.execute(options);
EventsDto result = context.getApi().getEventApi().listEvents(options);
return wrap(context, Event.class, result.getCollection());
}
}

View File

@ -20,6 +20,8 @@
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;
@ -36,14 +38,17 @@ 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.abiquo.strategy.config.ListCostCodes;
import org.jclouds.abiquo.strategy.config.ListCurrencies;
import org.jclouds.abiquo.strategy.config.ListPricingTemplates;
import org.jclouds.rest.RestContext;
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;
@ -51,7 +56,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Provides high level Abiquo administration operations.
* Provides access to Abiquo pricing features.
*
* @author Ignasi Barrera
* @author Susana Acedo
@ -61,52 +66,46 @@ public class BasePricingService implements PricingService {
@VisibleForTesting
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
@VisibleForTesting
protected final ListCurrencies listCurrencies;
@VisibleForTesting
protected final ListCostCodes listCostCodes;
@VisibleForTesting
protected final ListPricingTemplates listPricingTemplates;
@Inject
protected BasePricingService(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
final ListCurrencies listCurrencies, final ListCostCodes listCostCodes,
final ListPricingTemplates listPricingTemplates) {
protected BasePricingService(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = checkNotNull(context, "context");
this.listCurrencies = checkNotNull(listCurrencies, "listCurrencies");
this.listCostCodes = checkNotNull(listCostCodes, "listCostCodes");
this.listPricingTemplates = checkNotNull(listPricingTemplates, "listPricingTemplates");
}
/*********************** Currency ********************** */
@Override
public Iterable<Currency> listCurrencies() {
return listCurrencies.execute();
CurrenciesDto result = context.getApi().getPricingApi().listCurrencies();
return wrap(context, Currency.class, result.getCollection());
}
@Override
public Iterable<Currency> listCurrencies(final Predicate<Currency> filter) {
return listCurrencies.execute(filter);
return filter(listCurrencies(), filter);
}
@Override
public Currency findCurrency(final Predicate<Currency> filter) {
return Iterables.getFirst(listCurrencies(filter), null);
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<CostCode> listCostCodes() {
return listCostCodes.execute();
CostCodesDto result = context.getApi().getPricingApi().listCostCodes();
return wrap(context, CostCode.class, result.getCollection());
}
@Override
public Iterable<CostCode> listCostCodes(final Predicate<CostCode> filter) {
return listCostCodes.execute(filter);
return filter(listCostCodes(), filter);
}
@Override
@ -114,21 +113,34 @@ public class BasePricingService implements PricingService {
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<PricingTemplate> listPricingTemplates() {
return listPricingTemplates.execute();
PricingTemplatesDto result = context.getApi().getPricingApi().listPricingTemplates();
return wrap(context, PricingTemplate.class, result.getCollection());
}
@Override
public Iterable<PricingTemplate> listPricingTemplates(final Predicate<PricingTemplate> filter) {
return listPricingTemplates.execute(filter);
return filter(listPricingTemplates(), filter);
}
@Override
public PricingTemplate findPricingTemplate(final Predicate<PricingTemplate> filter) {
return Iterables.getFirst(listPricingTemplates(filter), null);
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 ********************** */

View File

@ -1,36 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.admin;
import org.jclouds.abiquo.domain.enterprise.Role;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.admin.internal.ListRolesImpl;
import com.google.inject.ImplementedBy;
/**
* List roles.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListRolesImpl.class)
public interface ListRoles extends ListRootEntities<Role> {
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.admin.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.enterprise.Role;
import org.jclouds.abiquo.strategy.admin.ListRoles;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.enterprise.RolesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List enterprises.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListRolesImpl implements ListRoles {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListRolesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<Role> execute() {
RolesDto result = context.getApi().getAdminApi().listRoles();
return wrap(context, Role.class, result.getCollection());
}
@Override
public Iterable<Role> execute(final Predicate<Role> selector) {
return filter(execute(), selector);
}
}

View File

@ -19,19 +19,96 @@
package org.jclouds.abiquo.strategy.cloud;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.strategy.ListEntities;
import org.jclouds.abiquo.strategy.cloud.internal.ListAttachedNicsImpl;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import com.google.inject.ImplementedBy;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.network.ExternalIp;
import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.domain.network.PrivateIp;
import org.jclouds.abiquo.domain.network.PublicIp;
import org.jclouds.abiquo.domain.network.UnmanagedIp;
import org.jclouds.abiquo.domain.util.LinkUtils;
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
import org.jclouds.abiquo.strategy.ListEntities;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.rest.RestContext;
import com.abiquo.model.rest.RESTLink;
import com.abiquo.server.core.infrastructure.network.ExternalIpDto;
import com.abiquo.server.core.infrastructure.network.PrivateIpDto;
import com.abiquo.server.core.infrastructure.network.PublicIpDto;
import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
/**
* List all NICs attached to a given virtual machine.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListAttachedNicsImpl.class)
public interface ListAttachedNics extends ListEntities<Ip<?, ?>, VirtualMachine> {
@Singleton
public class ListAttachedNics implements ListEntities<Ip<?, ?>, VirtualMachine> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExtendedUtils extendedUtils;
@Inject
public ListAttachedNics(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final ExtendedUtils extendedUtils) {
this.context = checkNotNull(context, "context");
this.extendedUtils = checkNotNull(extendedUtils, "extendedUtils");
}
@Override
public Iterable<Ip<?, ?>> execute(final VirtualMachine parent) {
parent.refresh();
Iterable<RESTLink> nicLinks = LinkUtils.filterNicLinks(parent.unwrap().getLinks());
return listIps(nicLinks);
}
@Override
public Iterable<Ip<?, ?>> execute(final VirtualMachine parent, final Predicate<Ip<?, ?>> selector) {
return filter(execute(parent), selector);
}
private Iterable<Ip<?, ?>> listIps(final Iterable<RESTLink> nicLinks) {
return transform(nicLinks, new Function<RESTLink, Ip<?, ?>>() {
@Override
public Ip<?, ?> apply(final RESTLink input) {
HttpResponse response = extendedUtils.getAbiquoHttpClient().get(input);
if (input.getType().equals(PrivateIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<PrivateIpDto> parser = new ParseXMLWithJAXB<PrivateIpDto>(extendedUtils.getXml(),
TypeLiteral.get(PrivateIpDto.class));
return wrap(context, PrivateIp.class, parser.apply(response));
} else if (input.getType().equals(PublicIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<PublicIpDto> parser = new ParseXMLWithJAXB<PublicIpDto>(extendedUtils.getXml(),
TypeLiteral.get(PublicIpDto.class));
return wrap(context, PublicIp.class, parser.apply(response));
} else if (input.getType().equals(ExternalIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<ExternalIpDto> parser = new ParseXMLWithJAXB<ExternalIpDto>(extendedUtils.getXml(),
TypeLiteral.get(ExternalIpDto.class));
return wrap(context, ExternalIp.class, parser.apply(response));
} else if (input.getType().equals(UnmanagedIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<UnmanagedIpDto> parser = new ParseXMLWithJAXB<UnmanagedIpDto>(extendedUtils.getXml(),
TypeLiteral.get(UnmanagedIpDto.class));
return wrap(context, UnmanagedIp.class, parser.apply(response));
} else {
throw new IllegalArgumentException("Unsupported media type: " + input.getType());
}
}
});
}
}

View File

@ -19,18 +19,86 @@
package org.jclouds.abiquo.strategy.cloud;
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualAppliancesImpl;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import com.google.inject.ImplementedBy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.cloud.VirtualApplianceDto;
import com.abiquo.server.core.cloud.VirtualAppliancesDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* List virtual appliances in each virtual datacenter.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListVirtualAppliancesImpl.class)
public interface ListVirtualAppliances extends ListRootEntities<VirtualAppliance> {
@Singleton
public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ListVirtualDatacenters listVirtualDatacenters;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualAppliances(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor,
final ListVirtualDatacenters listVirtualDatacenters) {
this.context = checkNotNull(context, "context");
this.listVirtualDatacenters = checkNotNull(listVirtualDatacenters, "listVirtualDatacenters");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualAppliance> execute() {
// Find virtual appliances in concurrent requests
Iterable<VirtualDatacenter> vdcs = listVirtualDatacenters.execute();
Iterable<VirtualApplianceDto> vapps = listConcurrentVirtualAppliances(vdcs);
return wrap(context, VirtualAppliance.class, vapps);
}
@Override
public Iterable<VirtualAppliance> execute(final Predicate<VirtualAppliance> selector) {
return filter(execute(), selector);
}
private Iterable<VirtualApplianceDto> listConcurrentVirtualAppliances(final Iterable<VirtualDatacenter> vdcs) {
Iterable<VirtualAppliancesDto> vapps = transformParallel(vdcs,
new Function<VirtualDatacenter, Future<? extends VirtualAppliancesDto>>() {
@Override
public Future<VirtualAppliancesDto> apply(final VirtualDatacenter input) {
return context.getAsyncApi().getCloudApi().listVirtualAppliances(input.unwrap());
}
}, userExecutor, maxTime, logger, "getting virtual appliances");
return DomainWrapper.join(vapps);
}
}

View File

@ -19,28 +19,98 @@
package org.jclouds.abiquo.strategy.cloud;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualDatacentersImpl;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
import com.abiquo.server.core.cloud.VirtualDatacentersDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.ImplementedBy;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* List virtual datacenters.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListVirtualDatacentersImpl.class)
public interface ListVirtualDatacenters extends ListRootEntities<VirtualDatacenter> {
Iterable<VirtualDatacenter> execute(VirtualDatacenterOptions virtualDatacenterOptions);
@Singleton
public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacenter> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
Iterable<VirtualDatacenter> execute(List<Integer> virtualDatacenterIds);
protected final ExecutorService userExecutor;
Iterable<VirtualDatacenter> execute(Predicate<VirtualDatacenter> selector,
VirtualDatacenterOptions virtualDatacenterOptions);
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualDatacenters(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualDatacenter> execute() {
VirtualDatacenterOptions virtualDatacenterOptions = VirtualDatacenterOptions.builder().build();
return execute(virtualDatacenterOptions);
}
@Override
public Iterable<VirtualDatacenter> execute(final Predicate<VirtualDatacenter> selector) {
return filter(execute(), selector);
}
public Iterable<VirtualDatacenter> execute(final VirtualDatacenterOptions virtualDatacenterOptions) {
VirtualDatacentersDto result = context.getApi().getCloudApi().listVirtualDatacenters(virtualDatacenterOptions);
return wrap(context, VirtualDatacenter.class, result.getCollection());
}
public Iterable<VirtualDatacenter> execute(final Predicate<VirtualDatacenter> selector,
final VirtualDatacenterOptions virtualDatacenterOptions) {
return filter(execute(virtualDatacenterOptions), selector);
}
public Iterable<VirtualDatacenter> execute(final List<Integer> virtualDatacenterIds) {
// Find virtual datacenters in concurrent requests
return listConcurrentVirtualDatacenters(virtualDatacenterIds);
}
private Iterable<VirtualDatacenter> listConcurrentVirtualDatacenters(final List<Integer> ids) {
Iterable<VirtualDatacenterDto> vdcs = transformParallel(ids,
new Function<Integer, Future<? extends VirtualDatacenterDto>>() {
@Override
public Future<VirtualDatacenterDto> apply(final Integer input) {
return context.getAsyncApi().getCloudApi().getVirtualDatacenter(input);
}
}, userExecutor, maxTime, logger, "getting virtual datacenters");
return DomainWrapper.wrap(context, VirtualDatacenter.class, Lists.newArrayList(vdcs));
}
}

View File

@ -19,19 +19,93 @@
package org.jclouds.abiquo.strategy.cloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualMachinesImpl;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.google.inject.ImplementedBy;
import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* List virtual machines in each virtual datacenter and each virtual appliance.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListVirtualMachinesImpl.class)
public interface ListVirtualMachines extends ListRootEntities<VirtualMachine> {
Iterable<VirtualMachine> execute(VirtualMachineOptions options);
@Singleton
public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
protected final ListVirtualAppliances listVirtualAppliances;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor,
final ListVirtualAppliances listVirtualAppliances) {
super();
this.context = checkNotNull(context, "context");
this.listVirtualAppliances = checkNotNull(listVirtualAppliances, "listVirtualAppliances");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualMachine> execute() {
return execute(VirtualMachineOptions.builder().disablePagination().build());
}
public Iterable<VirtualMachine> execute(final VirtualMachineOptions options) {
// Find virtual machines in concurrent requests
Iterable<VirtualAppliance> vapps = listVirtualAppliances.execute();
Iterable<VirtualMachineWithNodeExtendedDto> vms = listConcurrentVirtualMachines(vapps, options);
return wrap(context, VirtualMachine.class, vms);
}
@Override
public Iterable<VirtualMachine> execute(final Predicate<VirtualMachine> selector) {
return filter(execute(), selector);
}
private Iterable<VirtualMachineWithNodeExtendedDto> listConcurrentVirtualMachines(
final Iterable<VirtualAppliance> vapps, final VirtualMachineOptions options) {
Iterable<VirtualMachinesWithNodeExtendedDto> vms = transformParallel(vapps,
new Function<VirtualAppliance, Future<? extends VirtualMachinesWithNodeExtendedDto>>() {
@Override
public Future<VirtualMachinesWithNodeExtendedDto> apply(final VirtualAppliance input) {
return context.getAsyncApi().getCloudApi().listVirtualMachines(input.unwrap(), options);
}
}, userExecutor, maxTime, logger, "getting virtual machines");
return DomainWrapper.join(vms);
}
}

View File

@ -1,116 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.network.ExternalIp;
import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.domain.network.PrivateIp;
import org.jclouds.abiquo.domain.network.PublicIp;
import org.jclouds.abiquo.domain.network.UnmanagedIp;
import org.jclouds.abiquo.domain.util.LinkUtils;
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
import org.jclouds.abiquo.strategy.cloud.ListAttachedNics;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.rest.RestContext;
import com.abiquo.model.rest.RESTLink;
import com.abiquo.server.core.infrastructure.network.ExternalIpDto;
import com.abiquo.server.core.infrastructure.network.PrivateIpDto;
import com.abiquo.server.core.infrastructure.network.PublicIpDto;
import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.google.inject.TypeLiteral;
/**
* List all NICs attached to a given virtual machine.
*
* @author Ignasi Barrera
*/
@Singleton
public class ListAttachedNicsImpl implements ListAttachedNics {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExtendedUtils extendedUtils;
@Inject
public ListAttachedNicsImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final ExtendedUtils extendedUtils) {
this.context = checkNotNull(context, "context");
this.extendedUtils = checkNotNull(extendedUtils, "extendedUtils");
}
@Override
public Iterable<Ip<?, ?>> execute(final VirtualMachine parent) {
parent.refresh();
Iterable<RESTLink> nicLinks = LinkUtils.filterNicLinks(parent.unwrap().getLinks());
return listIps(nicLinks);
}
@Override
public Iterable<Ip<?, ?>> execute(final VirtualMachine parent, final Predicate<Ip<?, ?>> selector) {
return filter(execute(parent), selector);
}
private Iterable<Ip<?, ?>> listIps(final Iterable<RESTLink> nicLinks) {
return transform(nicLinks, new Function<RESTLink, Ip<?, ?>>() {
@Override
public Ip<?, ?> apply(final RESTLink input) {
HttpResponse response = extendedUtils.getAbiquoHttpClient().get(input);
if (input.getType().equals(PrivateIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<PrivateIpDto> parser = new ParseXMLWithJAXB<PrivateIpDto>(extendedUtils.getXml(),
TypeLiteral.get(PrivateIpDto.class));
return wrap(context, PrivateIp.class, parser.apply(response));
} else if (input.getType().equals(PublicIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<PublicIpDto> parser = new ParseXMLWithJAXB<PublicIpDto>(extendedUtils.getXml(),
TypeLiteral.get(PublicIpDto.class));
return wrap(context, PublicIp.class, parser.apply(response));
} else if (input.getType().equals(ExternalIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<ExternalIpDto> parser = new ParseXMLWithJAXB<ExternalIpDto>(extendedUtils.getXml(),
TypeLiteral.get(ExternalIpDto.class));
return wrap(context, ExternalIp.class, parser.apply(response));
} else if (input.getType().equals(UnmanagedIpDto.BASE_MEDIA_TYPE)) {
ParseXMLWithJAXB<UnmanagedIpDto> parser = new ParseXMLWithJAXB<UnmanagedIpDto>(extendedUtils.getXml(),
TypeLiteral.get(UnmanagedIpDto.class));
return wrap(context, UnmanagedIp.class, parser.apply(response));
} else {
throw new IllegalArgumentException("Unsupported media type: " + input.getType());
}
}
});
}
}

View File

@ -1,106 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.strategy.cloud.ListVirtualAppliances;
import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.cloud.VirtualApplianceDto;
import com.abiquo.server.core.cloud.VirtualAppliancesDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List virtual appliance in each virtual datacenter.
*
* @author Ignasi Barrera
*/
@Singleton
public class ListVirtualAppliancesImpl implements ListVirtualAppliances {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ListVirtualDatacenters listVirtualDatacenters;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualAppliancesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor,
final ListVirtualDatacenters listVirtualDatacenters) {
this.context = checkNotNull(context, "context");
this.listVirtualDatacenters = checkNotNull(listVirtualDatacenters, "listVirtualDatacenters");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualAppliance> execute() {
// Find virtual appliances in concurrent requests
Iterable<VirtualDatacenter> vdcs = listVirtualDatacenters.execute();
Iterable<VirtualApplianceDto> vapps = listConcurrentVirtualAppliances(vdcs);
return wrap(context, VirtualAppliance.class, vapps);
}
@Override
public Iterable<VirtualAppliance> execute(final Predicate<VirtualAppliance> selector) {
return filter(execute(), selector);
}
private Iterable<VirtualApplianceDto> listConcurrentVirtualAppliances(final Iterable<VirtualDatacenter> vdcs) {
Iterable<VirtualAppliancesDto> vapps = transformParallel(vdcs,
new Function<VirtualDatacenter, Future<? extends VirtualAppliancesDto>>() {
@Override
public Future<VirtualAppliancesDto> apply(final VirtualDatacenter input) {
return context.getAsyncApi().getCloudApi().listVirtualAppliances(input.unwrap());
}
}, userExecutor, maxTime, logger, "getting virtual appliances");
return DomainWrapper.join(vapps);
}
}

View File

@ -1,119 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions;
import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
import com.abiquo.server.core.cloud.VirtualDatacentersDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
/**
* List virtual datacenters.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListVirtualDatacentersImpl implements ListVirtualDatacenters {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualDatacentersImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualDatacenter> execute() {
VirtualDatacenterOptions virtualDatacenterOptions = VirtualDatacenterOptions.builder().build();
return execute(virtualDatacenterOptions);
}
@Override
public Iterable<VirtualDatacenter> execute(final Predicate<VirtualDatacenter> selector) {
return filter(execute(), selector);
}
@Override
public Iterable<VirtualDatacenter> execute(final VirtualDatacenterOptions virtualDatacenterOptions) {
VirtualDatacentersDto result = context.getApi().getCloudApi().listVirtualDatacenters(virtualDatacenterOptions);
return wrap(context, VirtualDatacenter.class, result.getCollection());
}
@Override
public Iterable<VirtualDatacenter> execute(final Predicate<VirtualDatacenter> selector,
final VirtualDatacenterOptions virtualDatacenterOptions) {
return filter(execute(virtualDatacenterOptions), selector);
}
@Override
public Iterable<VirtualDatacenter> execute(final List<Integer> virtualDatacenterIds) {
// Find virtual datacenters in concurrent requests
return listConcurrentVirtualDatacenters(virtualDatacenterIds);
}
private Iterable<VirtualDatacenter> listConcurrentVirtualDatacenters(final List<Integer> ids) {
Iterable<VirtualDatacenterDto> vdcs = transformParallel(ids,
new Function<Integer, Future<? extends VirtualDatacenterDto>>() {
@Override
public Future<VirtualDatacenterDto> apply(final Integer input) {
return context.getAsyncApi().getCloudApi().getVirtualDatacenter(input);
}
}, userExecutor, maxTime, logger, "getting virtual datacenters");
return DomainWrapper.wrap(context, VirtualDatacenter.class, Lists.newArrayList(vdcs));
}
}

View File

@ -1,114 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions;
import org.jclouds.abiquo.strategy.cloud.ListVirtualAppliances;
import org.jclouds.abiquo.strategy.cloud.ListVirtualMachines;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List virtual machines in each virtual datacenter and each virtual appliance.
*
* @author Ignasi Barrera
*/
@Singleton
public class ListVirtualMachinesImpl implements ListVirtualMachines {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
protected final ListVirtualAppliances listVirtualAppliances;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualMachinesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor,
final ListVirtualAppliances listVirtualAppliances) {
super();
this.context = checkNotNull(context, "context");
this.listVirtualAppliances = checkNotNull(listVirtualAppliances, "listVirtualAppliances");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualMachine> execute() {
return execute(VirtualMachineOptions.builder().disablePagination().build());
}
@Override
public Iterable<VirtualMachine> execute(final VirtualMachineOptions options) {
// Find virtual machines in concurrent requests
Iterable<VirtualAppliance> vapps = listVirtualAppliances.execute();
Iterable<VirtualMachineWithNodeExtendedDto> vms = listConcurrentVirtualMachines(vapps, options);
return wrap(context, VirtualMachine.class, vms);
}
@Override
public Iterable<VirtualMachine> execute(final Predicate<VirtualMachine> selector) {
return filter(execute(), selector);
}
private Iterable<VirtualMachineWithNodeExtendedDto> listConcurrentVirtualMachines(
final Iterable<VirtualAppliance> vapps, final VirtualMachineOptions options) {
Iterable<VirtualMachinesWithNodeExtendedDto> vms = transformParallel(vapps,
new Function<VirtualAppliance, Future<? extends VirtualMachinesWithNodeExtendedDto>>() {
@Override
public Future<VirtualMachinesWithNodeExtendedDto> apply(final VirtualAppliance input) {
return context.getAsyncApi().getCloudApi().listVirtualMachines(input.unwrap(), options);
}
}, userExecutor, maxTime, logger, "getting virtual machines");
return DomainWrapper.join(vms);
}
}

View File

@ -1,35 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.Category;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListCategoriesImpl;
import com.google.inject.ImplementedBy;
/**
* List privileges.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListCategoriesImpl.class)
public interface ListCategories extends ListRootEntities<Category> {
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.CostCode;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListCostCodesImpl;
import com.google.inject.ImplementedBy;
/**
* List cost codes
*
* @author Susana Acedo
*/
@ImplementedBy(ListCostCodesImpl.class)
public interface ListCostCodes extends ListRootEntities<CostCode> {
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.Currency;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListCurrenciesImpl;
import com.google.inject.ImplementedBy;
/**
* List currencies
*
* @author Susana Acedo
*/
@ImplementedBy(ListCurrenciesImpl.class)
public interface ListCurrencies extends ListRootEntities<Currency> {
}

View File

@ -1,37 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.License;
import org.jclouds.abiquo.domain.config.options.LicenseOptions;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListLicensesImpl;
import com.google.inject.ImplementedBy;
/**
* List licenses.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListLicensesImpl.class)
public interface ListLicenses extends ListRootEntities<License> {
public Iterable<License> execute(LicenseOptions options);
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.PricingTemplate;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListPricingTemplatesImpl;
import com.google.inject.ImplementedBy;
/**
* List pricing templates
*
* @author Susana Acedo
*/
@ImplementedBy(ListPricingTemplatesImpl.class)
public interface ListPricingTemplates extends ListRootEntities<PricingTemplate> {
}

View File

@ -1,35 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.Privilege;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListPrivilegesImpl;
import com.google.inject.ImplementedBy;
/**
* List privileges.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListPrivilegesImpl.class)
public interface ListPrivileges extends ListRootEntities<Privilege> {
}

View File

@ -1,37 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config;
import org.jclouds.abiquo.domain.config.SystemProperty;
import org.jclouds.abiquo.domain.config.options.PropertyOptions;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.config.internal.ListPropertiesImpl;
import com.google.inject.ImplementedBy;
/**
* List system properties.
*
* @author Francesc Montserrat
*/
@ImplementedBy(ListPropertiesImpl.class)
public interface ListProperties extends ListRootEntities<SystemProperty> {
public Iterable<SystemProperty> execute(PropertyOptions options);
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.config.Category;
import org.jclouds.abiquo.strategy.config.ListCategories;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.appslibrary.CategoriesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List categories.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListCategoriesImpl implements ListCategories {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListCategoriesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<Category> execute() {
CategoriesDto result = context.getApi().getConfigApi().listCategories();
return wrap(context, Category.class, result.getCollection());
}
@Override
public Iterable<Category> execute(final Predicate<Category> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.config.CostCode;
import org.jclouds.abiquo.strategy.config.ListCostCodes;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.pricing.CostCodesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List cost codes
*
* @author Ignasi Barrera
* @author Susana Acedo
*/
@Singleton
public class ListCostCodesImpl implements ListCostCodes {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListCostCodesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<CostCode> execute() {
CostCodesDto result = context.getApi().getPricingApi().listCostCodes();
return wrap(context, CostCode.class, result.getCollection());
}
@Override
public Iterable<CostCode> execute(final Predicate<CostCode> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.config.Currency;
import org.jclouds.abiquo.strategy.config.ListCurrencies;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.pricing.CurrenciesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List currencies
*
* @author Ignasi Barrera
* @author Susana Acedo
*/
@Singleton
public class ListCurrenciesImpl implements ListCurrencies {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListCurrenciesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<Currency> execute() {
CurrenciesDto result = context.getApi().getPricingApi().listCurrencies();
return wrap(context, Currency.class, result.getCollection());
}
@Override
public Iterable<Currency> execute(final Predicate<Currency> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,74 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.config.License;
import org.jclouds.abiquo.domain.config.options.LicenseOptions;
import org.jclouds.abiquo.strategy.config.ListLicenses;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.config.LicensesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List licenses.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListLicensesImpl implements ListLicenses {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListLicensesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<License> execute() {
LicensesDto result = context.getApi().getConfigApi().listLicenses();
return wrap(context, License.class, result.getCollection());
}
@Override
public Iterable<License> execute(final LicenseOptions options) {
LicensesDto result = context.getApi().getConfigApi().listLicenses(options);
return wrap(context, License.class, result.getCollection());
}
@Override
public Iterable<License> execute(final Predicate<License> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.config.PricingTemplate;
import org.jclouds.abiquo.strategy.config.ListPricingTemplates;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.pricing.PricingTemplatesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List pricing templates
*
* @author Ignasi Barrera
* @author Susana Acedo
*/
@Singleton
public class ListPricingTemplatesImpl implements ListPricingTemplates {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListPricingTemplatesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<PricingTemplate> execute() {
PricingTemplatesDto result = context.getApi().getPricingApi().listPricingTemplates();
return wrap(context, PricingTemplate.class, result.getCollection());
}
@Override
public Iterable<PricingTemplate> execute(final Predicate<PricingTemplate> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.config.Privilege;
import org.jclouds.abiquo.strategy.config.ListPrivileges;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.enterprise.PrivilegesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List licenses.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListPrivilegesImpl implements ListPrivileges {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListPrivilegesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<Privilege> execute() {
PrivilegesDto result = context.getApi().getConfigApi().listPrivileges();
return wrap(context, Privilege.class, result.getCollection());
}
@Override
public Iterable<Privilege> execute(final Predicate<Privilege> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,73 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.config.SystemProperty;
import org.jclouds.abiquo.domain.config.options.PropertyOptions;
import org.jclouds.abiquo.strategy.config.ListProperties;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.config.SystemPropertiesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List properties.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListPropertiesImpl implements ListProperties {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListPropertiesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<SystemProperty> execute() {
SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties();
return wrap(context, SystemProperty.class, result.getCollection());
}
@Override
public Iterable<SystemProperty> execute(final Predicate<SystemProperty> selector) {
return filter(execute(), selector);
}
@Override
public Iterable<SystemProperty> execute(final PropertyOptions options) {
SystemPropertiesDto result = context.getApi().getConfigApi().listSystemProperties(options);
return wrap(context, SystemProperty.class, result.getCollection());
}
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.enterprise;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.enterprise.internal.ListEnterprisesImpl;
import com.google.inject.ImplementedBy;
/**
* List enterprises.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListEnterprisesImpl.class)
public interface ListEnterprises extends ListRootEntities<Enterprise> {
}

View File

@ -19,19 +19,87 @@
package org.jclouds.abiquo.strategy.enterprise;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.strategy.ListEntities;
import org.jclouds.abiquo.strategy.enterprise.internal.ListVirtualMachineTemplatesImpl;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.google.inject.ImplementedBy;
import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* List all virtual machine templates available to an enterprise.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListVirtualMachineTemplatesImpl.class)
public interface ListVirtualMachineTemplates extends ListEntities<VirtualMachineTemplate, Enterprise> {
@Singleton
public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineTemplate, Enterprise> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualMachineTemplates(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
super();
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualMachineTemplate> execute(final Enterprise parent) {
// Find virtual machine templates in concurrent requests
Iterable<Datacenter> dcs = parent.listAllowedDatacenters();
Iterable<VirtualMachineTemplateDto> templates = listConcurrentTemplates(parent, dcs);
return wrap(context, VirtualMachineTemplate.class, templates);
}
@Override
public Iterable<VirtualMachineTemplate> execute(final Enterprise parent,
final Predicate<VirtualMachineTemplate> selector) {
return filter(execute(parent), selector);
}
private Iterable<VirtualMachineTemplateDto> listConcurrentTemplates(final Enterprise parent,
final Iterable<Datacenter> dcs) {
Iterable<VirtualMachineTemplatesDto> templates = transformParallel(dcs,
new Function<Datacenter, Future<? extends VirtualMachineTemplatesDto>>() {
@Override
public Future<VirtualMachineTemplatesDto> apply(final Datacenter input) {
return context.getAsyncApi().getVirtualMachineTemplateApi()
.listVirtualMachineTemplates(parent.getId(), input.getId());
}
}, userExecutor, maxTime, logger, "getting virtual machine templates");
return DomainWrapper.join(templates);
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.enterprise.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import javax.inject.Singleton;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.strategy.enterprise.ListEnterprises;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.enterprise.EnterprisesDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List enterprises.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListEnterprisesImpl implements ListEnterprises {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListEnterprisesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<Enterprise> execute() {
EnterprisesDto result = context.getApi().getEnterpriseApi().listEnterprises();
return wrap(context, Enterprise.class, result.getCollection());
}
@Override
public Iterable<Enterprise> execute(final Predicate<Enterprise> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,106 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.enterprise.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.strategy.enterprise.ListVirtualMachineTemplates;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List all virtual machine templates available to an enterprise.
*
* @author Ignasi Barrera
*/
@Singleton
public class ListVirtualMachineTemplatesImpl implements ListVirtualMachineTemplates {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListVirtualMachineTemplatesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
super();
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<VirtualMachineTemplate> execute(final Enterprise parent) {
// Find virtual machine templates in concurrent requests
Iterable<Datacenter> dcs = parent.listAllowedDatacenters();
Iterable<VirtualMachineTemplateDto> templates = listConcurrentTemplates(parent, dcs);
return wrap(context, VirtualMachineTemplate.class, templates);
}
@Override
public Iterable<VirtualMachineTemplate> execute(final Enterprise parent,
final Predicate<VirtualMachineTemplate> selector) {
return filter(execute(parent), selector);
}
private Iterable<VirtualMachineTemplateDto> listConcurrentTemplates(final Enterprise parent,
final Iterable<Datacenter> dcs) {
Iterable<VirtualMachineTemplatesDto> templates = transformParallel(dcs,
new Function<Datacenter, Future<? extends VirtualMachineTemplatesDto>>() {
@Override
public Future<VirtualMachineTemplatesDto> apply(final Datacenter input) {
return context.getAsyncApi().getVirtualMachineTemplateApi()
.listVirtualMachineTemplates(parent.getId(), input.getId());
}
}, userExecutor, maxTime, logger, "getting virtual machine templates");
return DomainWrapper.join(templates);
}
}

View File

@ -1,37 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.event;
import org.jclouds.abiquo.domain.event.Event;
import org.jclouds.abiquo.domain.event.options.EventOptions;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.event.internal.ListEventsImpl;
import com.google.inject.ImplementedBy;
/**
* List events.
*
* @author Vivien Mahé
*/
@ImplementedBy(ListEventsImpl.class)
public interface ListEvents extends ListRootEntities<Event> {
Iterable<Event> execute(EventOptions options);
}

View File

@ -1,65 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.event.internal;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.event.Event;
import org.jclouds.abiquo.domain.event.options.EventOptions;
import org.jclouds.abiquo.strategy.event.ListEvents;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.event.EventsDto;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
public class ListEventsImpl implements ListEvents {
// This strategy does not have still an Executor instance because the current
// methods call
// single api methods
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
@Inject
ListEventsImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
this.context = context;
}
@Override
public Iterable<Event> execute() {
EventsDto result = context.getApi().getEventApi().listEvents();
return wrap(context, Event.class, result.getCollection());
}
@Override
public Iterable<Event> execute(final EventOptions options) {
EventsDto result = context.getApi().getEventApi().listEvents(options);
return wrap(context, Event.class, result.getCollection());
}
@Override
public Iterable<Event> execute(final Predicate<Event> selector) {
return filter(execute(), selector);
}
}

View File

@ -1,38 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.infrastructure;
import java.util.List;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.infrastructure.internal.ListDatacentersImpl;
import com.google.inject.ImplementedBy;
/**
* List datacenters.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListDatacentersImpl.class)
public interface ListDatacenters extends ListRootEntities<Datacenter> {
Iterable<Datacenter> execute(List<Integer> datacenterIds);
}

View File

@ -19,18 +19,98 @@
package org.jclouds.abiquo.strategy.infrastructure;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.domain.infrastructure.Machine;
import org.jclouds.abiquo.strategy.ListRootEntities;
import org.jclouds.abiquo.strategy.infrastructure.internal.ListMachinesImpl;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.google.inject.ImplementedBy;
import com.abiquo.server.core.infrastructure.DatacentersDto;
import com.abiquo.server.core.infrastructure.MachineDto;
import com.abiquo.server.core.infrastructure.MachinesDto;
import com.abiquo.server.core.infrastructure.RackDto;
import com.abiquo.server.core.infrastructure.RacksDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* List machines in each datacenter and rack.
*
* @author Ignasi Barrera
*/
@ImplementedBy(ListMachinesImpl.class)
public interface ListMachines extends ListRootEntities<Machine> {
@Singleton
public class ListMachines implements ListRootEntities<Machine> {
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
super();
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<Machine> execute() {
// Find machines in concurrent requests
DatacentersDto result = context.getApi().getInfrastructureApi().listDatacenters();
Iterable<Datacenter> datacenters = wrap(context, Datacenter.class, result.getCollection());
Iterable<RackDto> racks = listConcurrentRacks(datacenters);
Iterable<MachineDto> machines = listConcurrentMachines(racks);
return wrap(context, Machine.class, machines);
}
@Override
public Iterable<Machine> execute(final Predicate<Machine> selector) {
return filter(execute(), selector);
}
private Iterable<RackDto> listConcurrentRacks(final Iterable<Datacenter> datacenters) {
Iterable<RacksDto> racks = transformParallel(datacenters, new Function<Datacenter, Future<? extends RacksDto>>() {
@Override
public Future<RacksDto> apply(final Datacenter input) {
return context.getAsyncApi().getInfrastructureApi().listRacks(input.unwrap());
}
}, userExecutor, maxTime, logger, "getting racks");
return DomainWrapper.join(racks);
}
private Iterable<MachineDto> listConcurrentMachines(final Iterable<RackDto> racks) {
Iterable<MachinesDto> machines = transformParallel(racks, new Function<RackDto, Future<? extends MachinesDto>>() {
@Override
public Future<MachinesDto> apply(final RackDto input) {
return context.getAsyncApi().getInfrastructureApi().listMachines(input);
}
}, userExecutor, maxTime, logger, "getting machines");
return DomainWrapper.join(machines);
}
}

View File

@ -1,106 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.infrastructure.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.strategy.infrastructure.ListDatacenters;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.infrastructure.DatacenterDto;
import com.abiquo.server.core.infrastructure.DatacentersDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
/**
* List datacenters.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Singleton
public class ListDatacentersImpl implements ListDatacenters {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListDatacentersImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
this.context = context;
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<Datacenter> execute() {
DatacentersDto result = context.getApi().getInfrastructureApi().listDatacenters();
return wrap(context, Datacenter.class, result.getCollection());
}
@Override
public Iterable<Datacenter> execute(final Predicate<Datacenter> selector) {
return filter(execute(), selector);
}
@Override
public Iterable<Datacenter> execute(final List<Integer> datacenterIds) {
// Find virtual datacenters in concurrent requests
return listConcurrentDatacenters(datacenterIds);
}
private Iterable<Datacenter> listConcurrentDatacenters(final List<Integer> ids) {
Iterable<DatacenterDto> dcs = transformParallel(ids, new Function<Integer, Future<? extends DatacenterDto>>() {
@Override
public Future<DatacenterDto> apply(final Integer input) {
return context.getAsyncApi().getInfrastructureApi().getDatacenter(input);
}
}, userExecutor, maxTime, logger, "getting datacenters");
return DomainWrapper.wrap(context, Datacenter.class, Lists.newArrayList(dcs));
}
}

View File

@ -1,120 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.infrastructure.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWrapper;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.domain.infrastructure.Machine;
import org.jclouds.abiquo.strategy.infrastructure.ListDatacenters;
import org.jclouds.abiquo.strategy.infrastructure.ListMachines;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
import com.abiquo.server.core.infrastructure.MachineDto;
import com.abiquo.server.core.infrastructure.MachinesDto;
import com.abiquo.server.core.infrastructure.RackDto;
import com.abiquo.server.core.infrastructure.RacksDto;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* List machines in each datacenter and rack.
*
* @author Ignasi Barrera
*/
@Singleton
public class ListMachinesImpl implements ListMachines {
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected ListDatacenters listDatacenters;
protected final ExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
@Inject
ListMachinesImpl(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor,
final ListDatacenters listDatacenters) {
super();
this.context = checkNotNull(context, "context");
this.listDatacenters = checkNotNull(listDatacenters, "listDatacenters");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<Machine> execute() {
// Find machines in concurrent requests
Iterable<Datacenter> datacenters = listDatacenters.execute();
Iterable<RackDto> racks = listConcurrentRacks(datacenters);
Iterable<MachineDto> machines = listConcurrentMachines(racks);
return wrap(context, Machine.class, machines);
}
@Override
public Iterable<Machine> execute(final Predicate<Machine> selector) {
return filter(execute(), selector);
}
private Iterable<RackDto> listConcurrentRacks(final Iterable<Datacenter> datacenters) {
Iterable<RacksDto> racks = transformParallel(datacenters, new Function<Datacenter, Future<? extends RacksDto>>() {
@Override
public Future<RacksDto> apply(final Datacenter input) {
return context.getAsyncApi().getInfrastructureApi().listRacks(input.unwrap());
}
}, userExecutor, maxTime, logger, "getting racks");
return DomainWrapper.join(racks);
}
private Iterable<MachineDto> listConcurrentMachines(final Iterable<RackDto> racks) {
Iterable<MachinesDto> machines = transformParallel(racks, new Function<RackDto, Future<? extends MachinesDto>>() {
@Override
public Future<MachinesDto> apply(final RackDto input) {
return context.getAsyncApi().getInfrastructureApi().listMachines(input);
}
}, userExecutor, maxTime, logger, "getting machines");
return DomainWrapper.join(machines);
}
}

View File

@ -36,12 +36,7 @@ public class BaseAdministrationServiceTest extends BaseInjectionTest {
BaseAdministrationService service = (BaseAdministrationService) injector.getInstance(AdministrationService.class);
assertNotNull(service.context);
assertNotNull(service.listDatacenters);
assertNotNull(service.listMachines);
assertNotNull(service.listEnterprises);
assertNotNull(service.listLicenses);
assertNotNull(service.listPrivileges);
assertNotNull(service.listRoles);
assertNotNull(service.currentUser);
assertNotNull(service.currentEnterprise);
}

View File

@ -35,6 +35,5 @@ public class BaseEventServiceTest extends BaseInjectionTest {
BaseEventService service = (BaseEventService) injector.getInstance(EventService.class);
assertNotNull(service.context);
assertNotNull(service.listEvents);
}
}

View File

@ -1,65 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.admin.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.enterprise.Role;
import org.jclouds.abiquo.predicates.enterprise.RolePredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListRolesImpl} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListRolesImplLiveApiTest")
public class ListRolesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListRolesImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListRolesImpl.class);
}
public void testExecute() {
Iterable<Role> roles = strategy.execute();
assertNotNull(roles);
assertTrue(size(roles) > 0);
}
public void testExecutePredicateWithoutResults() {
Iterable<Role> roles = strategy.execute(RolePredicates.name("UNEXISTING"));
assertNotNull(roles);
assertEquals(size(roles), 0);
}
public void testExecutePredicateWithResults() {
Iterable<Role> roles = strategy.execute(RolePredicates.name(env.role.getName()));
assertNotNull(roles);
assertEquals(size(roles), 1);
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
package org.jclouds.abiquo.strategy.cloud;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@ -32,6 +32,7 @@ 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.jclouds.abiquo.strategy.cloud.ListAttachedNics;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -39,13 +40,13 @@ import org.testng.annotations.Test;
import com.google.common.collect.Lists;
/**
* Live tests for the {@link ListAttachedNicsImpl} strategy.
* Live tests for the {@link ListAttachedNics} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListAttachedNicsImplLiveApiTest")
public class ListAttachedNicsImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListAttachedNicsImpl strategy;
@Test(groups = "api", testName = "ListAttachedNicsLiveApiTest")
public class ListAttachedNicsLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListAttachedNics strategy;
private PrivateIp privateIp;
@ -56,7 +57,7 @@ public class ListAttachedNicsImplLiveApiTest extends BaseAbiquoStrategyLiveApiTe
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListAttachedNicsImpl.class);
this.strategy = env.context.getUtils().getInjector().getInstance(ListAttachedNics.class);
privateIp = env.privateNetwork.listUnusedIps().get(0);
assertNotNull(privateIp);

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
package org.jclouds.abiquo.strategy.cloud;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@ -27,22 +27,23 @@ 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.jclouds.abiquo.strategy.cloud.ListVirtualAppliances;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListVirtualAppliancesImpl} strategy.
* Live tests for the {@link ListVirtualAppliances} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListVirtualAppliancesImplLiveApiTest")
public class ListVirtualAppliancesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualAppliancesImpl strategy;
@Test(groups = "api", testName = "ListVirtualAppliancesLiveApiTest")
public class ListVirtualAppliancesLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualAppliances strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualAppliancesImpl.class);
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualAppliances.class);
}
public void testExecute() {

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
package org.jclouds.abiquo.strategy.cloud;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@ -28,22 +28,23 @@ 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.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListVirtualDatacentersImpl} strategy.
* Live tests for the {@link ListVirtualDatacenters} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListVirtualDatacentersImplLiveApiTest")
public class ListVirtualDatacentersImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualDatacentersImpl strategy;
@Test(groups = "api", testName = "ListVirtualDatacentersLiveApiTest")
public class ListVirtualDatacentersLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualDatacenters strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualDatacentersImpl.class);
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualDatacenters.class);
}
public void testExecute() {

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.abiquo.strategy.cloud.internal;
package org.jclouds.abiquo.strategy.cloud;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@ -30,22 +30,23 @@ 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.jclouds.abiquo.strategy.cloud.ListVirtualMachines;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListVirtualMachinesImpl} strategy.
* Live tests for the {@link ListVirtualMachines} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListVirtualMachinesImplLiveApiTest")
public class ListVirtualMachinesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualMachinesImpl strategy;
@Test(groups = "api", testName = "ListVirtualMachinesLiveApiTest")
public class ListVirtualMachinesLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualMachines strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualMachinesImpl.class);
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualMachines.class);
}
public void testExecute() {

View File

@ -1,78 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.config.Category;
import org.jclouds.abiquo.predicates.config.CategoryPredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
/**
* Live tests for the {@link ListPropertiesImpl} strategy.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Test(groups = "api", testName = "ListCategoriesImplLiveApiTest")
public class ListCategoriesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListCategoriesImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListCategoriesImpl.class);
}
public void testExecute() {
Iterable<Category> categories = strategy.execute();
assertNotNull(categories);
assertTrue(size(categories) > 0);
}
public void testExecutePredicateWithoutResults() {
Iterable<Category> categories = strategy.execute(CategoryPredicates.name("Unexisting category"));
assertNotNull(categories);
assertEquals(size(categories), 0);
}
public void testExecutePredicateWithResults() {
Iterable<Category> categories = strategy.execute(CategoryPredicates.name("Applications servers"));
assertNotNull(categories);
assertEquals(size(categories), 1);
}
public void testExecuteNotPredicateWithResults() {
Iterable<Category> categories = strategy.execute(Predicates.not(CategoryPredicates.name("Applications servers")));
Iterable<Category> allProperties = strategy.execute();
assertNotNull(categories);
assertNotNull(allProperties);
assertEquals(size(categories), size(allProperties) - 1);
}
}

View File

@ -1,82 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.config.License;
import org.jclouds.abiquo.domain.config.options.LicenseOptions;
import org.jclouds.abiquo.predicates.config.LicensePredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListLicenseImpl} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListLicensesImplLiveApiTest")
public class ListLicensesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListLicensesImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListLicensesImpl.class);
}
public void testExecute() {
Iterable<License> licenses = strategy.execute();
assertNotNull(licenses);
assertTrue(size(licenses) > 0);
}
public void testExecuteInactive() {
LicenseOptions options = LicenseOptions.builder().inactive(true).build();
Iterable<License> licenses = strategy.execute(options);
assertNotNull(licenses);
assertTrue(size(licenses) == 1);
}
public void testExecuteActive() {
LicenseOptions options = LicenseOptions.builder().active(true).build();
Iterable<License> licenses = strategy.execute(options);
assertNotNull(licenses);
assertTrue(size(licenses) >= 1);
}
public void testExecutePredicateWithoutResults() {
Iterable<License> licenses = strategy.execute(LicensePredicates.customer("FAIL"));
assertNotNull(licenses);
assertEquals(size(licenses), 0);
}
public void testExecutePredicateWithResults() {
Iterable<License> licenses = strategy.execute(LicensePredicates.code(env.license.getCode()));
assertNotNull(licenses);
assertEquals(size(licenses), 1);
}
}

View File

@ -1,77 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.config.Privilege;
import org.jclouds.abiquo.predicates.config.PrivilegePredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
/**
* Live tests for the {@link ListPrivilegesImpl} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListPrivilegesImplLiveApiTest")
public class ListPrivilegesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListPrivilegesImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListPrivilegesImpl.class);
}
public void testExecute() {
Iterable<Privilege> privileges = strategy.execute();
assertNotNull(privileges);
assertTrue(size(privileges) > 0);
}
public void testExecutePredicateWithoutResults() {
Iterable<Privilege> privileges = strategy.execute(PrivilegePredicates.name("Destroy the universe"));
assertNotNull(privileges);
assertEquals(size(privileges), 0);
}
public void testExecutePredicateWithResults() {
Iterable<Privilege> privileges = strategy.execute(PrivilegePredicates.name("USERS_MANAGE_USERS"));
assertNotNull(privileges);
assertEquals(size(privileges), 1);
}
public void testExecuteNotPredicateWithResults() {
Iterable<Privilege> privileges = strategy.execute(Predicates.not(PrivilegePredicates.name("USERS_MANAGE_USERS")));
Iterable<Privilege> allPrivileges = strategy.execute();
assertNotNull(privileges);
assertNotNull(allPrivileges);
assertEquals(size(privileges), size(allPrivileges) - 1);
}
}

View File

@ -1,89 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.config.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.config.SystemProperty;
import org.jclouds.abiquo.domain.config.options.PropertyOptions;
import org.jclouds.abiquo.predicates.config.SystemPropertyPredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
/**
* Live tests for the {@link ListPropertiesImpl} strategy.
*
* @author Ignasi Barrera
* @author Francesc Montserrat
*/
@Test(groups = "api", testName = "ListPropertiesImplLiveApiTest")
public class ListPropertiesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListPropertiesImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListPropertiesImpl.class);
}
public void testExecute() {
Iterable<SystemProperty> properties = strategy.execute();
assertNotNull(properties);
assertTrue(size(properties) > 0);
}
public void testExecuteWithOptions() {
PropertyOptions options = PropertyOptions.builder().component("client").build();
Iterable<SystemProperty> properties = strategy.execute(options);
assertNotNull(properties);
assertTrue(size(properties) > 0);
}
public void testExecutePredicateWithoutResults() {
Iterable<SystemProperty> properties = strategy.execute(SystemPropertyPredicates.name("Cloud color"));
assertNotNull(properties);
assertEquals(size(properties), 0);
}
public void testExecutePredicateWithResults() {
Iterable<SystemProperty> properties = strategy.execute(SystemPropertyPredicates
.name("client.applibrary.ovfpackagesDownloadingProgressUpdateInterval"));
assertNotNull(properties);
assertEquals(size(properties), 1);
}
public void testExecuteNotPredicateWithResults() {
Iterable<SystemProperty> properties = strategy.execute(Predicates.not(SystemPropertyPredicates
.name("client.applibrary.ovfpackagesDownloadingProgressUpdateInterval")));
Iterable<SystemProperty> allProperties = strategy.execute();
assertNotNull(properties);
assertNotNull(allProperties);
assertEquals(size(properties), size(allProperties) - 1);
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.abiquo.strategy.enterprise.internal;
package org.jclouds.abiquo.strategy.enterprise;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@ -27,23 +27,24 @@ import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.predicates.cloud.VirtualMachineTemplatePredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.jclouds.abiquo.strategy.cloud.internal.ListVirtualAppliancesImpl;
import org.jclouds.abiquo.strategy.cloud.ListVirtualAppliances;
import org.jclouds.abiquo.strategy.enterprise.ListVirtualMachineTemplates;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListVirtualAppliancesImpl} strategy.
* Live tests for the {@link ListVirtualAppliances} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListVirtualMachineTemplatesImplLiveApiTest")
public class ListVirtualMachineTemplatesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualMachineTemplatesImpl strategy;
@Test(groups = "api", testName = "ListVirtualMachineTemplatesLiveApiTest")
public class ListVirtualMachineTemplatesLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListVirtualMachineTemplates strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualMachineTemplatesImpl.class);
this.strategy = env.context.getUtils().getInjector().getInstance(ListVirtualMachineTemplates.class);
}
public void testExecute() {

View File

@ -1,65 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.enterprise.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.predicates.enterprise.EnterprisePredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListEnterprisesImpl} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListEnterprisesImplLiveApiTest")
public class ListEnterprisesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListEnterprisesImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListEnterprisesImpl.class);
}
public void testExecute() {
Iterable<Enterprise> enterprises = strategy.execute();
assertNotNull(enterprises);
assertTrue(size(enterprises) > 0);
}
public void testExecutePredicateWithoutResults() {
Iterable<Enterprise> enterprises = strategy.execute(EnterprisePredicates.name("UNEXISTING"));
assertNotNull(enterprises);
assertEquals(size(enterprises), 0);
}
public void testExecutePredicateWithResults() {
Iterable<Enterprise> enterprises = strategy.execute(EnterprisePredicates.name(env.enterprise.getName()));
assertNotNull(enterprises);
assertEquals(size(enterprises), 1);
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.abiquo.strategy.infrastructure.internal;
package org.jclouds.abiquo.strategy.infrastructure;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@ -27,22 +27,23 @@ 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.jclouds.abiquo.strategy.infrastructure.ListMachines;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListMachinesImpl} strategy.
* Live tests for the {@link ListMachines} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListMachinesImplLiveApiTest")
public class ListMachinesImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListMachinesImpl strategy;
@Test(groups = "api", testName = "ListMachinesLiveApiTest")
public class ListMachinesLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListMachines strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListMachinesImpl.class);
this.strategy = env.context.getUtils().getInjector().getInstance(ListMachines.class);
}
public void testExecute() {

View File

@ -1,65 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.abiquo.strategy.infrastructure.internal;
import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.predicates.infrastructure.DatacenterPredicates;
import org.jclouds.abiquo.strategy.BaseAbiquoStrategyLiveApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Live tests for the {@link ListDatacentersImpl} strategy.
*
* @author Ignasi Barrera
*/
@Test(groups = "api", testName = "ListDatacentersImplLiveApiTest")
public class ListDatacentersImplLiveApiTest extends BaseAbiquoStrategyLiveApiTest {
private ListDatacentersImpl strategy;
@Override
@BeforeClass(groups = "api")
protected void setupStrategy() {
this.strategy = env.context.getUtils().getInjector().getInstance(ListDatacentersImpl.class);
}
public void testExecute() {
Iterable<Datacenter> datacenters = strategy.execute();
assertNotNull(datacenters);
assertTrue(size(datacenters) > 0);
}
public void testExecutePredicateWithoutResults() {
Iterable<Datacenter> datacenters = strategy.execute(DatacenterPredicates.name("UNEXISTING"));
assertNotNull(datacenters);
assertEquals(size(datacenters), 0);
}
public void testExecutePredicateWithResults() {
Iterable<Datacenter> datacenters = strategy.execute(DatacenterPredicates.name(env.datacenter.getName()));
assertNotNull(datacenters);
assertEquals(size(datacenters), 1);
}
}