-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first draft of basic instance operations (related to #191)
- Loading branch information
1 parent
1fe1240
commit 640db12
Showing
6 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
perspective-aws/src/main/java/org/meridor/perspective/aws/Api.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
package org.meridor.perspective.aws; | ||
|
||
public interface Api { | ||
|
||
boolean rebootInstance(String instanceId); | ||
|
||
boolean hardRebootInstance(String instanceId); | ||
|
||
boolean startInstance(String instanceId); | ||
|
||
boolean shutdownInstance(String instanceId); | ||
|
||
boolean deleteInstance(String instanceId); | ||
|
||
void close(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
perspective-aws/src/main/java/org/meridor/perspective/aws/DeleteInstanceOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.meridor.perspective.aws; | ||
|
||
import org.meridor.perspective.beans.Instance; | ||
import org.meridor.perspective.config.OperationType; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
@Component | ||
public class DeleteInstanceOperation extends BaseInstanceOperation { | ||
|
||
@Override | ||
protected BiFunction<Api, Instance, Boolean> getAction() { | ||
return (api, instance) -> { | ||
try { | ||
return api.deleteInstance(instance.getRealId()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected String getSuccessMessage(Instance instance) { | ||
return String.format("Deleted instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
protected String getErrorMessage(Instance instance) { | ||
return String.format("Failed to delete instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
public OperationType[] getTypes() { | ||
return new OperationType[]{OperationType.DELETE_INSTANCE}; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
perspective-aws/src/main/java/org/meridor/perspective/aws/RebootInstanceOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.meridor.perspective.aws; | ||
|
||
import org.meridor.perspective.beans.Instance; | ||
import org.meridor.perspective.config.OperationType; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import static org.meridor.perspective.config.OperationType.REBOOT_INSTANCE; | ||
|
||
@Component | ||
public class RebootInstanceOperation extends BaseInstanceOperation { | ||
|
||
@Override | ||
protected BiFunction<Api, Instance, Boolean> getAction() { | ||
return (api, instance) -> { | ||
try { | ||
return api.rebootInstance(instance.getRealId()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected String getSuccessMessage(Instance instance) { | ||
return String.format("Rebooted instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
protected String getErrorMessage(Instance instance) { | ||
return String.format("Failed to reboot instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
public OperationType[] getTypes() { | ||
return new OperationType[]{REBOOT_INSTANCE}; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
perspective-aws/src/main/java/org/meridor/perspective/aws/ShutdownInstanceOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.meridor.perspective.aws; | ||
|
||
import org.meridor.perspective.beans.Instance; | ||
import org.meridor.perspective.config.OperationType; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import static org.meridor.perspective.config.OperationType.SHUTDOWN_INSTANCE; | ||
|
||
@Component | ||
public class ShutdownInstanceOperation extends BaseInstanceOperation { | ||
|
||
@Override | ||
protected BiFunction<Api, Instance, Boolean> getAction() { | ||
return (api, instance) -> { | ||
try { | ||
return api.shutdownInstance(instance.getRealId()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected String getSuccessMessage(Instance instance) { | ||
return String.format("Shut down instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
protected String getErrorMessage(Instance instance) { | ||
return String.format("Failed to shut down instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
public OperationType[] getTypes() { | ||
return new OperationType[]{SHUTDOWN_INSTANCE}; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
perspective-aws/src/main/java/org/meridor/perspective/aws/StartInstanceOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.meridor.perspective.aws; | ||
|
||
import org.meridor.perspective.beans.Instance; | ||
import org.meridor.perspective.config.OperationType; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import static org.meridor.perspective.config.OperationType.START_INSTANCE; | ||
|
||
@Component | ||
public class StartInstanceOperation extends BaseInstanceOperation { | ||
|
||
@Override | ||
protected BiFunction<Api, Instance, Boolean> getAction() { | ||
return (api, instance) -> { | ||
try { | ||
return api.startInstance(instance.getRealId()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected String getSuccessMessage(Instance instance) { | ||
return String.format("Started instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
protected String getErrorMessage(Instance instance) { | ||
return String.format("Failed to start instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
public OperationType[] getTypes() { | ||
return new OperationType[]{START_INSTANCE}; | ||
} | ||
|
||
} |