-
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.
More GoogleCloud operations (related to #215)
- Loading branch information
1 parent
fd6b7cf
commit b8c3df7
Showing
11 changed files
with
424 additions
and
13 deletions.
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
perspective-google-cloud/src/main/java/org/meridor/perspective/googlecloud/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,45 @@ | ||
package org.meridor.perspective.googlecloud; | ||
|
||
import com.google.cloud.compute.MachineType; | ||
import com.google.cloud.compute.Network; | ||
import com.google.cloud.compute.Region; | ||
import org.meridor.perspective.beans.Keypair; | ||
|
||
import java.util.List; | ||
|
||
public interface Api { | ||
|
||
// Project operations | ||
|
||
List<MachineType> listFlavors(); | ||
|
||
List<Network> listNetworks(); | ||
|
||
List<Region> listRegions(); | ||
|
||
List<Keypair> listKeypairs(); | ||
|
||
// Instance operations | ||
|
||
boolean deleteInstance(String instanceId); | ||
|
||
boolean startInstance(String instanceId); | ||
|
||
boolean shutdownInstance(String instanceId); | ||
|
||
boolean rebootInstance(String instanceId); | ||
|
||
boolean hardRebootInstance(String instanceId); | ||
|
||
boolean resizeInstance(String instanceId, String flavorId); | ||
|
||
List<com.google.cloud.compute.Instance> listInstances(); | ||
|
||
// Image operations | ||
|
||
boolean deleteImage(String imageId); | ||
|
||
List<com.google.cloud.compute.Image> listImages(); | ||
|
||
List<com.google.cloud.compute.Snapshot> listSnapshots(); | ||
} |
2 changes: 1 addition & 1 deletion
2
perspective-google-cloud/src/main/java/org/meridor/perspective/googlecloud/ApiProvider.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
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
20 changes: 20 additions & 0 deletions
20
...google-cloud/src/main/java/org/meridor/perspective/googlecloud/BaseInstanceOperation.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,20 @@ | ||
package org.meridor.perspective.googlecloud; | ||
|
||
import org.meridor.perspective.beans.Instance; | ||
import org.meridor.perspective.config.Cloud; | ||
import org.meridor.perspective.worker.operation.AbstractInstanceOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public abstract class BaseInstanceOperation extends AbstractInstanceOperation<Api> { | ||
|
||
@Autowired | ||
private ApiProvider apiProvider; | ||
|
||
@Override | ||
protected Api getApi(Cloud cloud, Instance instance) { | ||
return apiProvider.getApi(cloud); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ogle-cloud/src/main/java/org/meridor/perspective/googlecloud/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,31 @@ | ||
package org.meridor.perspective.googlecloud; | ||
|
||
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) -> api.deleteInstance(instance.getRealId()); | ||
} | ||
|
||
@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}; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-cloud/src/main/java/org/meridor/perspective/googlecloud/HardRebootInstanceOperation.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,34 @@ | ||
package org.meridor.perspective.googlecloud; | ||
|
||
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.HARD_REBOOT_INSTANCE; | ||
|
||
@Component | ||
public class HardRebootInstanceOperation extends BaseInstanceOperation { | ||
|
||
@Override | ||
protected BiFunction<Api, Instance, Boolean> getAction() { | ||
return (api, instance) -> api.hardRebootInstance(instance.getRealId()); | ||
} | ||
|
||
@Override | ||
protected String getSuccessMessage(Instance instance) { | ||
return String.format("Hard rebooted instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
protected String getErrorMessage(Instance instance) { | ||
return String.format("Failed to hard reboot instance %s (%s)", instance.getName(), instance.getId()); | ||
} | ||
|
||
@Override | ||
public OperationType[] getTypes() { | ||
return new OperationType[]{HARD_REBOOT_INSTANCE}; | ||
} | ||
|
||
} |
Oops, something went wrong.