removed unused code in vcloud-director copy/pasted from vcloud

This commit is contained in:
Adrian Cole 2013-01-04 11:29:25 -08:00
parent eb825841d6
commit 9c64e723d6
19 changed files with 0 additions and 1292 deletions

View File

@ -1,81 +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.vcloud.director.v1_5.functions;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* @author danikov
*/
@Singleton
public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? extends CatalogItem>> {
@Resource
public Logger logger = Logger.NULL;
private final VCloudDirectorAsyncApi aapi;
private final ExecutorService executor;
@Inject
AllCatalogItemsInCatalog(VCloudDirectorAsyncApi aapi, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aapi = aapi;
this.executor = executor;
}
@Override
public Iterable<? extends CatalogItem> apply(Catalog from) {
Iterable<? extends CatalogItem> catalogItems = transformParallel(filter(from.getCatalogItems(), new Predicate<Reference>() {
@Override
public boolean apply(Reference input) {
return input.getType().equals(VCloudDirectorMediaType.CATALOG_ITEM);
}
}), new Function<Reference, Future<? extends CatalogItem>>() {
@Override
public Future<CatalogItem> apply(Reference from) {
return aapi.getCatalogApi().getItem(from.getHref());
}
}, executor, null, logger, "catalogItems in " + from.getHref());
return catalogItems;
}
}

View File

@ -1,59 +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.vcloud.director.v1_5.functions;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author danikov
*/
@Singleton
public class AllCatalogItemsInOrg implements Function<Org, Iterable<CatalogItem>> {
private final Function<Org, Iterable<Catalog>> allCatalogsInOrg;
private final Function<Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog;
@Inject
AllCatalogItemsInOrg(Function<Org, Iterable<Catalog>> allCatalogsInOrg,
Function<Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog) {
this.allCatalogsInOrg = allCatalogsInOrg;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Iterable<CatalogItem> apply(Org from) {
return Iterables.concat(Iterables.transform(allCatalogsInOrg.apply(from),
new Function<Catalog, Iterable<CatalogItem>>() {
@Override
public Iterable<CatalogItem> apply(Catalog from) {
return allCatalogItemsInCatalog.apply(from);
}
}));
}
}

View File

@ -1,68 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.functions;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.concurrent.FutureIterables;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import com.google.common.base.Function;
/**
* @author danikov
*/
@Singleton
public class AllCatalogsInOrg implements Function<AdminOrg, Iterable<? extends Catalog>> {
@Resource
public Logger logger = Logger.NULL;
private final VCloudDirectorAsyncApi aapi;
private final ExecutorService executor;
@Inject
AllCatalogsInOrg(VCloudDirectorAsyncApi aapi, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aapi = aapi;
this.executor = executor;
}
@Override
public Iterable<? extends Catalog> apply(final AdminOrg org) {
Iterable<? extends Catalog> catalogs = FutureIterables.<Reference, Catalog>transformParallel(org.getCatalogs(),
new Function<Reference, Future<? extends Catalog>>() {
@Override
public Future<? extends Catalog> apply(Reference from) {
return aapi.getCatalogApi().get(from.getHref());
}
}, executor, null, logger, "catalogs in " + org.getName());
return catalogs;
}
}

View File

@ -1,71 +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.vcloud.director.v1_5.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import com.google.common.base.Function;
/**
* @author danikov
*/
@Singleton
public class AllVdcsInOrg implements Function<AdminOrg, Iterable<? extends Vdc>> {
@Resource
public Logger logger = Logger.NULL;
private final VCloudDirectorAsyncApi aapi;
private final ExecutorService executor;
@Inject
AllVdcsInOrg(VCloudDirectorAsyncApi aapi, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aapi = aapi;
this.executor = executor;
}
@Override
public Iterable<? extends Vdc> apply(final AdminOrg org) {
Iterable<? extends Vdc> catalogItems = transformParallel(org.getVdcs(),
new Function<Reference, Future<? extends Vdc>>() {
@Override
public Future<? extends Vdc> apply(Reference from) {
return aapi.getVdcApi().get(from.getHref());
}
}, executor, null, logger, "vdcs in org " + org.getName());
return catalogItems;
}
}

View File

@ -1,54 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Iterables.get;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.dmtf.ovf.Network;
import org.jclouds.dmtf.ovf.NetworkSection;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import com.google.common.base.Function;
@Singleton
public class DefaultNetworkNameInTemplate implements Function<VAppTemplate, String> {
@Resource
protected Logger logger = Logger.NULL;
private SectionForVAppTemplate<NetworkSection> networkSelector =
new SectionForVAppTemplate<NetworkSection>(NetworkSection.class);
@Override
public String apply(VAppTemplate vAppTemplate) {
checkArgument(vAppTemplate != null, "vAppTemplate was null!");
vAppTemplate.getSections();
Set<Network> networks = networkSelector.apply(vAppTemplate).getNetworks();
checkArgument(networks.size() > 0, "no networks found in vAppTemplate %s", vAppTemplate);
if (networks.size() > 1)
logger.warn("multiple networks found for %s, choosing first from: %s", vAppTemplate.getName(), networks);
return get(networks, 0).getName();
}
}

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.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.nameEquals;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
import org.jclouds.vcloud.director.v1_5.endpoints.Catalog;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, AdminOrg>> orgMap;
private final Supplier<Reference> defaultOrg;
private final Supplier<Reference> defaultCatalog;
@Inject
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, AdminOrg>> orgMap,
@org.jclouds.vcloud.director.v1_5.endpoints.Org Supplier<Reference> defaultOrg,
@Catalog Supplier<Reference> defaultCatalog) {
this.orgMap = orgMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
if (org == null && catalog == null)
return defaultCatalog.get().getHref();
else if (org == null)
org = defaultOrg.get().getName();
try {
Set<Reference> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
return catalog == null ? Iterables.getLast(catalogs).getHref() :
Iterables.find(catalogs, nameEquals((String)catalog)).getHref();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
}
}
}

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.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.nameEquals;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
import org.jclouds.vcloud.director.v1_5.endpoints.Vdc;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameAndVdcNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, AdminOrg>> orgNameToVdcEndpoint;
private final Supplier<Reference> defaultOrg;
private final Supplier<Reference> defaultVdc;
@Inject
public OrgNameAndVdcNameToEndpoint(Supplier<Map<String, AdminOrg>> orgNameToVDCEndpoint,
@org.jclouds.vcloud.director.v1_5.endpoints.Org Supplier<Reference> defaultOrg, @Vdc Supplier<Reference> defaultVdc) {
this.orgNameToVdcEndpoint = orgNameToVDCEndpoint;
this.defaultOrg = defaultOrg;
this.defaultVdc = defaultVdc;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgVdc = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgVdc, 0);
Object vdc = Iterables.get(orgVdc, 1);
if (org == null && vdc == null)
return defaultVdc.get().getHref();
else if (org == null)
org = defaultOrg.get().getName();
try {
Set<Reference> vdcs = checkNotNull(orgNameToVdcEndpoint.get().get(org)).getVdcs();
return vdc == null ? Iterables.getLast(vdcs).getHref() :
Iterables.find(vdcs, nameEquals((String)vdc)).getHref();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVdcEndpoint.get());
}
}
}

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.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.nameEquals;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Catalog;
import org.jclouds.vcloud.director.v1_5.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, Catalog>>> orgCatalogMap;
private final Supplier<Reference> defaultOrg;
private final Supplier<Reference> defaultCatalog;
@Inject
public OrgNameCatalogNameItemNameToEndpoint(
Supplier<Map<String, Map<String, Catalog>>> orgCatalogMap,
@Org Supplier<Reference> defaultOrg,
@org.jclouds.vcloud.director.v1_5.endpoints.Catalog Supplier<Reference> defaultCatalog) {
this.orgCatalogMap = orgCatalogMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null)
org = defaultOrg.get().getName();
if (catalog == null)
catalog = defaultCatalog.get().getName();
try {
Map<String, Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
return Iterables.find(catalogs.get(catalog).getCatalogItems(), nameEquals((String)catalogItem)).getHref();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in "
+ orgCatalogMap.get());
}
}
}

View File

@ -1,87 +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.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.endpoints.Catalog;
import org.jclouds.vcloud.director.v1_5.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> orgCatalogItemMap;
private final Supplier<Reference> defaultOrg;
private final Supplier<Reference> defaultCatalog;
@Inject
public OrgNameCatalogNameVAppTemplateNameToEndpoint(
Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> orgCatalogItemMap,
@Org Supplier<Reference> defaultOrg, @Catalog Supplier<Reference> defaultCatalog) {
this.orgCatalogItemMap = orgCatalogItemMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null)
org = defaultOrg.get().getName();
if (catalog == null)
catalog = defaultCatalog.get().getName();
Map<String, Map<String, Map<String, CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();
if (!orgCatalogItemMap.containsKey(org))
throw new NoSuchElementException("org: " + org + " not found in " + orgCatalogItemMap.keySet());
Map<String, Map<String, CatalogItem>> catalogs = orgCatalogItemMap.get(org);
if (!catalogs.containsKey(catalog))
throw new NoSuchElementException("catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet());
Map<String, CatalogItem> catalogMap = catalogs.get(catalog);
if (!catalogMap.containsKey(catalogItem))
throw new NoSuchElementException("item: " + org + "/" + catalog + "/" + catalogItem + " not found in "
+ catalogMap.keySet());
CatalogItem item = catalogMap.get(catalogItem);
return checkNotNull(item.getEntity(), "item: " + org + "/" + catalog + "/" + catalogItem + " has no entity")
.getHref();
}
}

View File

@ -1,59 +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.vcloud.director.v1_5.functions;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Reference>> orgNameToEndpointSupplier;
private final Supplier<Reference> defaultOrg;
@Inject
public OrgNameToEndpoint(@Org Supplier<Map<String, Reference>> orgNameToEndpointSupplier,
@Org Supplier<Reference> defaultOrg) {
this.orgNameToEndpointSupplier = orgNameToEndpointSupplier;
this.defaultOrg = defaultOrg;
}
public URI apply(Object from) {
try {
Map<String, Reference> orgNameToEndpoint = orgNameToEndpointSupplier.get();
return from == null ? defaultOrg.get().getHref() : orgNameToEndpoint.get(from).getHref();
} catch (NullPointerException e) {
throw new NoSuchElementException("org " + from + " not found in " + orgNameToEndpointSupplier.get().keySet());
}
}
}

View File

@ -1,64 +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.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.endpoints.TasksList;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameToTasksListEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Org>> orgMap;
private final Supplier<Reference> defaultTasksList;
@Inject
public OrgNameToTasksListEndpoint(Supplier<Map<String, Org>> orgMap,
@TasksList Supplier<Reference> defaultTasksList) {
this.orgMap = orgMap;
this.defaultTasksList = defaultTasksList;
}
public URI apply(Object from) {
Object org = from;
if (org == null)
return defaultTasksList.get().getHref();
try {
return checkNotNull(orgMap.get().get(org)).getHref();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + " not found in " + orgMap.get());
}
}
}

View File

@ -1,59 +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.vcloud.director.v1_5.functions;
import static org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.nameEquals;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.endpoints.Org;
import org.jclouds.vcloud.director.v1_5.endpoints.Vdc;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameVdcNameNetworkNameToEndpoint extends OrgNameVdcNameResourceNameToEndpoint {
@Inject
public OrgNameVdcNameNetworkNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc>>> orgVdcMap,
@Org Supplier<Reference> defaultOrg, @Vdc Supplier<Reference> defaultVdc) {
super(orgVdcMap, defaultOrg, defaultVdc);
}
protected URI getEndpointOfResourceInVdc(Object org, Object Vdc, Object resource,
org.jclouds.vcloud.director.v1_5.domain.Vdc VdcObject) {
Reference resourceEntity = Iterables.find(VdcObject.getAvailableNetworks(), nameEquals((String)Vdc));
if (resourceEntity == null)
throw new NoSuchElementException("network " + resource + " in Vdc " + Vdc + ", org " + org + " not found in "
+ VdcObject.getAvailableNetworks());
return resourceEntity.getHref();
}
}

View File

@ -1,59 +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.vcloud.director.v1_5.functions;
import static org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.nameEquals;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.endpoints.Org;
import org.jclouds.vcloud.director.v1_5.endpoints.Vdc;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
@Singleton
public class OrgNameVdcNameResourceEntityNameToEndpoint extends OrgNameVdcNameResourceNameToEndpoint {
@Inject
public OrgNameVdcNameResourceEntityNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc>>> orgVdcMap,
@Org Supplier<Reference> defaultOrg, @Vdc Supplier<Reference> defaultVdc) {
super(orgVdcMap, defaultOrg, defaultVdc);
}
protected URI getEndpointOfResourceInVdc(Object org, Object Vdc, Object resource,
org.jclouds.vcloud.director.v1_5.domain.Vdc VdcObject) {
Reference resourceEntity = Iterables.find(VdcObject.getResourceEntities(), nameEquals((String)resource));
if (resourceEntity == null)
throw new NoSuchElementException("entity " + resource + " in Vdc " + Vdc + ", org " + org + " not found in "
+ VdcObject.getResourceEntities());
return resourceEntity.getHref();
}
}

View File

@ -1,79 +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.vcloud.director.v1_5.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author danikov
*/
public abstract class OrgNameVdcNameResourceNameToEndpoint implements Function<Object, URI>{
protected final Supplier<Map<String, Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc>>> orgVdcMap;
protected final Supplier<Reference> defaultOrg;
protected final Supplier<Reference> defaultVdc;
@Inject
public OrgNameVdcNameResourceNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc>>> orgVdcMap,
@Org Supplier<Reference> defaultOrg, @org.jclouds.vcloud.director.v1_5.endpoints.Vdc Supplier<Reference> defaultVdc) {
this.orgVdcMap = orgVdcMap;
this.defaultOrg = defaultOrg;
this.defaultVdc = defaultVdc;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgVdc = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgVdc, 0);
Object Vdc = Iterables.get(orgVdc, 1);
Object resource = Iterables.get(orgVdc, 2);
if (org == null)
org = defaultOrg.get().getName();
if (Vdc == null)
Vdc = defaultVdc.get().getName();
Map<String, Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc>> orgToVdcs = orgVdcMap.get();
checkState(orgToVdcs != null, "could not get map of org name to Vdcs!");
Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc> Vdcs = orgToVdcs.get(org);
if (Vdcs == null)
throw new NoSuchElementException("org " + org + " not found in " + orgToVdcs.keySet());
org.jclouds.vcloud.director.v1_5.domain.Vdc VdcObject = Vdcs.get(Vdc);
if (VdcObject == null)
throw new NoSuchElementException("Vdc " + Vdc + " in org " + org + " not found in " + Vdcs.keySet());
return getEndpointOfResourceInVdc(org, Vdc, resource, VdcObject);
}
protected abstract URI getEndpointOfResourceInVdc(Object org, Object Vdc, Object resource, Vdc VdcObject);
}

View File

@ -1,70 +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.vcloud.director.v1_5.functions;
import static com.google.common.collect.FluentIterable.from;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.location.predicates.LocationPredicates;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import com.google.common.base.Function;
/**
* @author danikov, Adrian Cole
*/
@Singleton
public class OrgsForLocations implements Function<Iterable<Location>, Iterable<? extends Org>> {
private final VCloudDirectorApi api;
@Inject
OrgsForLocations(VCloudDirectorApi api) {
this.api = api;
}
/**
* Zones are assignable, but we want regions. so we look for zones, whose parent is region. then,
* we use a set to extract the unique set.
*/
@Override
public Iterable<? extends Org> apply(Iterable<Location> from) {
return from(from)
.filter(LocationPredicates.isZone())
.transform(new Function<Location, String>() {
@Override
public String apply(Location from) {
return from.getParent().getId();
}
})
.transform(new Function<String, Org>() {
@Override
public Org apply(String from) {
return api.getOrgApi().get(from);
}
});
}
}

View File

@ -1,63 +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.vcloud.director.v1_5.functions;
import static com.google.common.collect.FluentIterable.from;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* @author danikov
*/
@Singleton
public class OrgsForNames implements Function<Iterable<String>, Iterable<? extends Org>> {
private final VCloudDirectorApi api;
@Inject
OrgsForNames(VCloudDirectorApi api) {
this.api = api;
}
@Override
public Iterable<? extends Org> apply(final Iterable<String> from) {
return from(api.getOrgApi().list()).filter(new Predicate<Reference>() {
@Override
public boolean apply(Reference in) {
return Iterables.contains(from, in.getName());
}
}).transform(new Function<Reference, Org>() {
@Override
public Org apply(Reference in) {
return api.getOrgApi().get(in.getHref());
}
});
}
}

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.vcloud.director.v1_5.functions;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import com.google.common.base.Function;
/**
* @author danikov
*/
@Singleton
public class ReferenceToName implements Function<Reference, String> {
@Override
public String apply(Reference from) {
return from.getName();
}
}

View File

@ -1,79 +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.vcloud.director.v1_5.functions;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* @author danikov
*/
@Singleton
public class VAppTemplatesForCatalogItems implements Function<Iterable<CatalogItem>, Iterable<? extends VAppTemplate>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
private Logger logger = Logger.NULL;
private final VCloudDirectorAsyncApi aapi;
private final ExecutorService executor;
@Inject
VAppTemplatesForCatalogItems(VCloudDirectorAsyncApi aapi, @Named(PROPERTY_USER_THREADS) ExecutorService executor) {
this.aapi = aapi;
this.executor = executor;
}
@Override
public Iterable<? extends VAppTemplate> apply(Iterable<CatalogItem> from) {
return transformParallel(filter(from, new Predicate<CatalogItem>() {
@Override
public boolean apply(CatalogItem input) {
return input.getEntity().getType().equals(VCloudDirectorMediaType.VAPP_TEMPLATE);
}
}), new Function<CatalogItem, Future<? extends VAppTemplate>>() {
@Override
public Future<? extends VAppTemplate> apply(CatalogItem from) {
return aapi.getVAppTemplateApi().get(from.getEntity().getHref());
}
}, executor, null, logger, "vappTemplates in");
}
}

View File

@ -1,70 +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.vcloud.director.v1_5.functions;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
* @author danikov
*/
@Singleton
public class VAppTemplatesInOrg implements Function<Org, Iterable<VAppTemplate>> {
private final Function<Org, Iterable<CatalogItem>> allCatalogItemsInOrg;
private final Function<Iterable<CatalogItem>, Iterable<VAppTemplate>> vAppTemplatesForCatalogItems;
@Inject
VAppTemplatesInOrg(Function<Org, Iterable<CatalogItem>> allCatalogItemsInOrg,
Function<Iterable<CatalogItem>, Iterable<VAppTemplate>> vAppTemplatesForCatalogItems) {
this.allCatalogItemsInOrg = allCatalogItemsInOrg;
this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems;
}
@Override
public Iterable<VAppTemplate> apply(Org from) {
Iterable<CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
Iterable<VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
return filter(vAppTemplates, and(notNull(), new Predicate<VAppTemplate>(){
//TODO: test this
@Override
public boolean apply(VAppTemplate input) {
if (input == null)
return false;
return ImmutableSet.of(Status.RESOLVED, Status.POWERED_OFF).contains(input.getStatus());
}
}));
}
}