mirror of https://github.com/apache/jclouds.git
Merge pull request #1276 from jclouds/issue1263
stop joyent nodes before deleting them
This commit is contained in:
commit
bdc2fb3a1e
|
@ -35,6 +35,7 @@ import com.google.common.cache.CacheBuilder;
|
|||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ForwardingObject;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
|
||||
/**
|
||||
* This will retry the supplier if it encounters a timeout exception, but not if it encounters an
|
||||
|
@ -120,6 +121,8 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> ext
|
|||
public T get() {
|
||||
try {
|
||||
return cache.get("FOO").orNull();
|
||||
} catch (UncheckedExecutionException e) {
|
||||
throw propagate(e.getCause());
|
||||
} catch (ExecutionException e) {
|
||||
throw propagate(e.getCause());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExc
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -73,6 +74,20 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenInUncheckedExecutionException() {
|
||||
AtomicReference<AuthorizationException> authException = newReference();
|
||||
try {
|
||||
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
|
||||
public String get() {
|
||||
throw new UncheckedExecutionException(new AuthorizationException());
|
||||
}
|
||||
}, authException).load("KEY");
|
||||
} finally {
|
||||
assertEquals(authException.get().getClass(), AuthorizationException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() {
|
||||
AtomicReference<AuthorizationException> authException = newReference();
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
package org.jclouds.joyent.cloudapi.v6_5.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.compute.reference.ComputeServiceConstants.COMPUTE_LOGGER;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue;
|
||||
import static org.jclouds.util.Predicates2.retry;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -30,12 +34,13 @@ import javax.inject.Named;
|
|||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.JoyentCloudApi;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.Dataset;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.Machine;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.Machine.State;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatacenterAndId;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatasetInDatacenter;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.MachineInDatacenter;
|
||||
|
@ -45,6 +50,7 @@ import org.jclouds.location.Zone;
|
|||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
@ -59,16 +65,19 @@ public class JoyentCloudComputeServiceAdapter implements
|
|||
ComputeServiceAdapter<MachineInDatacenter, PackageInDatacenter, DatasetInDatacenter, Location> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
@Named(COMPUTE_LOGGER)
|
||||
private Logger logger = Logger.NULL;
|
||||
|
||||
protected final JoyentCloudApi cloudApiApi;
|
||||
protected final Supplier<Set<String>> datacenterIds;
|
||||
private final JoyentCloudApi cloudApiApi;
|
||||
private final Supplier<Set<String>> datacenterIds;
|
||||
private final Timeouts timeouts;
|
||||
|
||||
@Inject
|
||||
public JoyentCloudComputeServiceAdapter(JoyentCloudApi cloudApiApi, @Zone Supplier<Set<String>> datacenterIds) {
|
||||
public JoyentCloudComputeServiceAdapter(JoyentCloudApi cloudApiApi, @Zone Supplier<Set<String>> datacenterIds,
|
||||
Timeouts timeouts) {
|
||||
this.cloudApiApi = checkNotNull(cloudApiApi, "cloudApiApi");
|
||||
this.datacenterIds = checkNotNull(datacenterIds, "datacenterIds");
|
||||
this.timeouts = checkNotNull(timeouts, "timeouts");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,12 +116,9 @@ public class JoyentCloudComputeServiceAdapter implements
|
|||
for (final String datacenterId : datacenterIds.get()) {
|
||||
builder.addAll(transform(cloudApiApi.getPackageApiForDatacenter(datacenterId).list(),
|
||||
new Function<org.jclouds.joyent.cloudapi.v6_5.domain.Package, PackageInDatacenter>() {
|
||||
|
||||
@Override
|
||||
public PackageInDatacenter apply(org.jclouds.joyent.cloudapi.v6_5.domain.Package arg0) {
|
||||
return new PackageInDatacenter(arg0, datacenterId);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
return builder.build();
|
||||
|
@ -124,12 +130,9 @@ public class JoyentCloudComputeServiceAdapter implements
|
|||
for (final String datacenterId : datacenterIds.get()) {
|
||||
builder.addAll(transform(cloudApiApi.getDatasetApiForDatacenter(datacenterId).list(),
|
||||
new Function<Dataset, DatasetInDatacenter>() {
|
||||
|
||||
@Override
|
||||
public DatasetInDatacenter apply(Dataset arg0) {
|
||||
return new DatasetInDatacenter(arg0, datacenterId);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
return builder.build();
|
||||
|
@ -141,12 +144,9 @@ public class JoyentCloudComputeServiceAdapter implements
|
|||
for (final String datacenterId : datacenterIds.get()) {
|
||||
builder.addAll(transform(cloudApiApi.getMachineApiForDatacenter(datacenterId).list(),
|
||||
new Function<Machine, MachineInDatacenter>() {
|
||||
|
||||
@Override
|
||||
public MachineInDatacenter apply(Machine arg0) {
|
||||
return new MachineInDatacenter(arg0, datacenterId);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
return builder.build();
|
||||
|
@ -176,8 +176,25 @@ public class JoyentCloudComputeServiceAdapter implements
|
|||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
|
||||
cloudApiApi.getMachineApiForDatacenter(datacenterAndId.getDatacenter()).delete(datacenterAndId.getId());
|
||||
final AtomicReference<MachineInDatacenter> machine = new AtomicReference<MachineInDatacenter>(getNode(id));
|
||||
if (machine.get() == null)
|
||||
return;
|
||||
if (machine.get().get().getState() == State.RUNNING) {
|
||||
logger.debug(">> stopping machine(%s) current state(%s)", machine.get().getId(), machine.get().get()
|
||||
.getState());
|
||||
cloudApiApi.getMachineApiForDatacenter(machine.get().getDatacenter()).stop(machine.get().getId());
|
||||
}
|
||||
|
||||
checkState(retry(new Predicate<String>() {
|
||||
public boolean apply(String id) {
|
||||
machine.set(getNode(id));
|
||||
return machine == null || machine.get().get().getState() != State.RUNNING;
|
||||
}
|
||||
}, timeouts.nodeSuspended).apply(id), "<< unable to stop machine(%s) current state(%s)", machine.get().getId(),
|
||||
machine.get().get().getState());
|
||||
|
||||
logger.debug(">> deleting machine(%s) current state(%s)", machine.get().getId(), machine.get().get().getState());
|
||||
cloudApiApi.getMachineApiForDatacenter(machine.get().getDatacenter()).delete(machine.get().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -189,15 +206,12 @@ public class JoyentCloudComputeServiceAdapter implements
|
|||
@Override
|
||||
public void resumeNode(String id) {
|
||||
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
|
||||
cloudApiApi.getMachineApiForDatacenter(datacenterAndId.getDatacenter()).stop(datacenterAndId.getId());
|
||||
|
||||
cloudApiApi.getMachineApiForDatacenter(datacenterAndId.getDatacenter()).start(datacenterAndId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suspendNode(String id) {
|
||||
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
|
||||
cloudApiApi.getMachineApiForDatacenter(datacenterAndId.getDatacenter()).start(datacenterAndId.getId());
|
||||
|
||||
cloudApiApi.getMachineApiForDatacenter(datacenterAndId.getDatacenter()).stop(datacenterAndId.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.joyent.cloudapi.v6_5.compute;
|
||||
|
||||
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
|
||||
|
|
Loading…
Reference in New Issue