org.jclouds.vcloud.terremark.compute.strategy.CleanupOrphanKeys Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jclouds-terremark Show documentation
Show all versions of jclouds-terremark Show documentation
jclouds Core components to access terremark
The newest version!
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC.
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.compute.strategy;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.all;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.parentLocationId;
import static org.jclouds.compute.predicates.NodePredicates.withTag;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.terremark.compute.domain.OrgAndName;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class CleanupOrphanKeys {
final Function nodeToOrgAndName;
final DeleteKeyPair deleteKeyPair;
final ListNodesStrategy listNodes;
final Map credentialStore;
@Inject
CleanupOrphanKeys(Function nodeToOrgAndName, DeleteKeyPair deleteKeyPair,
Map credentialStore, ListNodesStrategy listNodes) {
this.nodeToOrgAndName = nodeToOrgAndName;
this.deleteKeyPair = deleteKeyPair;
this.listNodes = listNodes;
this.credentialStore = credentialStore;
}
public void execute(Iterable extends NodeMetadata> deadOnes) {
// TODO refactor so that admin passwords are cached properly, probably as a list value in the
// credentialStore
for (NodeMetadata node : deadOnes){
credentialStore.remove("node#" + node.getId());
credentialStore.remove("node#" + node.getId() + "#adminPassword");
}
Iterable orgTags = filter(transform(deadOnes, nodeToOrgAndName), notNull());
for (OrgAndName orgTag : orgTags) {
Iterable extends NodeMetadata> nodesInOrg = listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag
.getOrg().toASCIIString()));
Iterable extends NodeMetadata> nodesWithTag = filter(nodesInOrg, withTag(orgTag.getName()));
if (size(nodesWithTag) == 0 || all(nodesWithTag, TERMINATED))
deleteKeyPair.execute(orgTag);
}
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy