Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions api/src/main/java/brooklyn/location/MachineManagementMixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,28 @@

import java.util.Map;

import com.google.common.annotations.Beta;

/**
* Defines mixins for interesting locations.
*/
public class MachineManagementMixins {

public interface RichMachineProvisioningLocation<T extends MachineLocation> extends MachineProvisioningLocation<T>, ListsMachines, GivesMachineMetadata, KillsMachines {}

public interface RichMachineProvisioningLocation<T extends MachineLocation> extends
MachineProvisioningLocation<T>, ListsMachines, GivesMachineMetadata, KillsMachines {}

public interface ListsMachines {
/** returns map of machine ID to metadata record for all machines known in a given cloud location */
/**
* @return A map of machine ID to metadata record for all machines known in a given cloud location.
*/
Map<String,MachineMetadata> listMachines();
}

public interface GivesMachineMetadata {
/** returns the MachineMetadata for a given (brooklyn) machine location instance,
* or null if not matched */
/**
* @return the {@link MachineMetadata} for a given (brooklyn) machine location instance,
* or null if not matched.
*/
MachineMetadata getMachineMetadata(MachineLocation location);
}

Expand All @@ -55,5 +65,28 @@ public interface MachineMetadata {
/** original metadata object, if available; e.g. ComputeMetadata when using jclouds */
Object getOriginalMetadata();
}


/**
* Implement to indicate that a location can suspend and resume machines.
*/
@Beta
public interface SuspendResumeLocation extends SuspendsMachines, ResumesMachines {};


@Beta
public interface SuspendsMachines {
/**
* Suspend the indicated machine.
*/
void suspendMachine(MachineLocation location);
}

@Beta
public interface ResumesMachines {
/**
* Resume the indicated machine.
*/
void resumeMachine(MachineLocation location);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import brooklyn.location.MachineLocationCustomizer;
import brooklyn.location.MachineManagementMixins.MachineMetadata;
import brooklyn.location.MachineManagementMixins.RichMachineProvisioningLocation;
import brooklyn.location.MachineManagementMixins.SuspendsMachines;
import brooklyn.location.NoMachinesAvailableException;
import brooklyn.location.access.PortForwardManager;
import brooklyn.location.access.PortMapping;
Expand Down Expand Up @@ -187,7 +188,9 @@
* Configuration flags are defined in {@link JcloudsLocationConfig}.
*/
@SuppressWarnings("serial")
public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation implements JcloudsLocationConfig, RichMachineProvisioningLocation<MachineLocation>, LocationWithObjectStore {
public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation implements
JcloudsLocationConfig, RichMachineProvisioningLocation<MachineLocation>,
LocationWithObjectStore, SuspendsMachines {

// TODO After converting from Groovy to Java, this is now very bad code! It relies entirely on putting
// things into and taking them out of maps; it's not type-safe, and it's thus very error-prone.
Expand Down Expand Up @@ -1023,6 +1026,35 @@ protected MachineLocation obtainOnce(ConfigBag setup) throws NoMachinesAvailable
}
}

// ------------- suspend and resume ------------------------------------

/**
* Suspends the given location.
* <p>
* Note that this method does <b>not</b> call the lifecycle methods of any
* {@link #getCustomizers(ConfigBag) customizers} attached to this location.
*/
@Override
public void suspendMachine(MachineLocation rawLocation) {
String instanceId = vmInstanceIds.remove(rawLocation);
if (instanceId == null) {
LOG.info("Attempt to suspend unknown machine " + rawLocation + " in " + this);
throw new IllegalArgumentException("Unknown machine " + rawLocation);
}
LOG.info("Suspending machine {} in {}, instance id {}", new Object[]{rawLocation, this, instanceId});
Exception toThrow = null;
try {
getComputeService().suspendNode(instanceId);
} catch (Exception e) {
toThrow = e;
LOG.error("Problem suspending machine " + rawLocation + " in " + this + ", instance id " + instanceId, e);
}
removeChild(rawLocation);
if (toThrow != null) {
throw Exceptions.propagate(toThrow);
}
}

// ------------- constructing the template, etc ------------------------

private static interface CustomizeTemplateBuilder {
Expand Down Expand Up @@ -2159,7 +2191,7 @@ public void release(MachineLocation rawMachine) {
throw new IllegalArgumentException("Unknown machine "+rawMachine);
}
JcloudsMachineLocation machine = (JcloudsMachineLocation) rawMachine;

LOG.info("Releasing machine {} in {}, instance id {}", new Object[] {machine, this, instanceId});

Exception tothrow = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected Collection<Integer> getRequiredOpenPorts(Entity entity) {
value = maybeValue.isPresent() ? maybeValue.get() : null;
}

Maybe<PortRange> maybePortRange = TypeCoercions.tryCoerce(value, new TypeToken<PortRange>() {});
Maybe<PortRange> maybePortRange = TypeCoercions.tryCoerce(value, TypeToken.of(PortRange.class));

if (maybePortRange.isPresentAndNonNull()) {
PortRange p = maybePortRange.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,30 @@ public void restart(ConfigBag parameters) {
return;
}

DynamicTasks.queue("pre-restart", new Runnable() { public void run() {
preRestartCustom();
}});
DynamicTasks.queue("pre-restart", new PreRestartTask());

log.debug("restart of "+entity()+" appears to have driver and hostname - doing driver-level restart");
entity().getDriver().restart();

restartChildren(parameters);

DynamicTasks.queue("post-restart", new Runnable() { public void run() {
DynamicTasks.queue("post-restart", new PostRestartTask());
}

private class PreRestartTask implements Runnable {
@Override
public void run() {
preRestartCustom();
}
}

private class PostRestartTask implements Runnable {
@Override
public void run() {
postStartCustom();
postRestartCustom();
ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
}});
}
}

@Override
Expand Down Expand Up @@ -233,7 +243,7 @@ protected String stopProcessesAtMachine() {

if (childException!=null)
throw new IllegalStateException(result+"; but error stopping child: "+childException, childException);

return result;
}

Expand Down
Loading