Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.openstack4j.api.storage;

import static org.testng.Assert.assertEquals;

import java.util.List;

import org.openstack4j.api.AbstractTest;
import org.openstack4j.model.storage.block.ext.Service.State;
import org.openstack4j.model.storage.block.ext.Service.Status;
import org.testng.annotations.Test;

/**
* Test cases for Block Storage Services function
*
* @author Taemin
*/
@Test(suiteName = "BlockStroageServices")
public class ServiceTests extends AbstractTest {

private static final String JSON_SERVICES = "/storage/ext/services.json";

public void serviceListingTest() throws Exception {
respondWith(JSON_SERVICES);

List<? extends org.openstack4j.model.storage.block.ext.Service> services = osv3().blockStorage().services().list();
assertEquals(2, services.size());
org.openstack4j.model.storage.block.ext.Service s = services.get(0);
assertEquals("cinder-scheduler", s.getBinary());
assertEquals("host1", s.getHost());
assertEquals(Status.ENABLED, s.getStatus());
assertEquals(State.UP, s.getState());
}

@Override
protected Service service() {
return Service.BLOCK_STORAGE;
}

}
20 changes: 20 additions & 0 deletions core-test/src/main/resources/storage/ext/services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"services": [
{
"binary": "cinder-scheduler",
"host": "host1",
"state": "UP",
"status": "ENABLED",
"updated_at": "2012-10-29T13:42:02.000000",
"zone": "nova"
},
{
"binary": "cinder-volume",
"host": "host1",
"state": "UP",
"status": "ENABLED",
"updated_at": "2012-10-29T13:42:05.000000",
"zone": "nova"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public interface ServerService {
*
* @param serverId the server identifier
* @param options evaucate options
* @return ActionResponse
* @return an administrative password to access the evacuated or rebuilt instance.
*/
ServerPassword evacuate(String serverId, EvacuateOptions options);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openstack4j.api.storage;

import org.openstack4j.api.storage.ext.BlockStroageServicesService;
import org.openstack4j.common.RestService;
import org.openstack4j.model.storage.block.BlockLimits;

Expand Down Expand Up @@ -47,4 +48,11 @@ public interface BlockStorageService extends RestService {
* @return the Volume Service API
*/
BlockVolumeBackupService backups();

/**
* The block storage services service
*
* @return ServicesService
*/
BlockStroageServicesService services();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openstack4j.api.storage.ext;

import java.util.List;

import org.openstack4j.model.storage.block.ext.Service;



/**
* API which supports the "os-services" extension.
*
* @author Taemin
*/
public interface BlockStroageServicesService {

/**
* List services info
*
* NOTE: This is an extension and not all deployments support os-services
*
* @return a list of block storage services
*/
List<? extends Service> list();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.openstack4j.model.storage.block.ext;

import java.util.Date;

import org.openstack4j.model.ModelEntity;

import com.fasterxml.jackson.annotation.JsonCreator;

/**
* A Service represents a Nova compute service
*
* @author Stephan Latour
*/
public interface Service extends ModelEntity {
/**
* The status of a Nova service entity
*/
public enum Status {
DISABLED, ENABLED, UNRECOGNIZED;

@JsonCreator
public static Status forValue(String value) {
if (value != null) {
for (Status s : Status.values()) {
if (s.name().equalsIgnoreCase(value)) {
return s;
}
}
}
return Status.UNRECOGNIZED;
}
}

/**
* The state of a Nova service entity
*/
public enum State {
DOWN, UNRECOGNIZED, UP;

@JsonCreator
public static State forValue(String value) {
if (value != null) {
for (State s : State.values()) {
if (s.name().equalsIgnoreCase(value)) {
return s;
}
}
}
return State.UNRECOGNIZED;
}
}

/**
* @return the binary for this service
*/
String getBinary();

/**
* @return the reason for disabled status of this service
*/
String getDisabledReason();

/**
* @return the host for this service
*/
String getHost();

/**
* @return the id for this service
*/
String getId();

/**
* @return the status of the service
*/
State getState();

/**
* @return the status of the service
*/
Status getStatus();

/**
*
* @return last updated time
*/
Date getUpdatedAt();

/**
* @return the zone for this service
*/
String getZone();

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import org.openstack4j.api.storage.ObjectStorageObjectService;
import org.openstack4j.api.storage.ObjectStorageService;
import org.openstack4j.api.storage.SchedulerStatsGetPoolService;
import org.openstack4j.api.storage.ext.BlockStroageServicesService;
import org.openstack4j.api.tacker.TackerService;
import org.openstack4j.api.tacker.TackerServiceImpl;
import org.openstack4j.api.tacker.VimService;
Expand Down Expand Up @@ -271,6 +272,7 @@
import org.openstack4j.openstack.senlin.internal.SenlinWebHookServiceImpl;
import org.openstack4j.openstack.storage.block.internal.BlockQuotaSetServiceImpl;
import org.openstack4j.openstack.storage.block.internal.BlockStorageServiceImpl;
import org.openstack4j.openstack.storage.block.internal.BlockStorageServicesServiceImpl;
import org.openstack4j.openstack.storage.block.internal.BlockVolumeBackupServiceImpl;
import org.openstack4j.openstack.storage.block.internal.BlockVolumeServiceImpl;
import org.openstack4j.openstack.storage.block.internal.BlockVolumeSnapshotServiceImpl;
Expand Down Expand Up @@ -470,6 +472,8 @@ public void initialize() {
bind(TelemetryAodhService.class,TelemetryAodhServiceImpl.class);
bind(AlarmAodhService.class, AlarmAodhServiceImpl.class);
bind(ServicesService.class, ServicesServiceImpl.class);
bind(BlockStroageServicesService.class, BlockStorageServicesServiceImpl.class);

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.openstack4j.openstack.storage.block.domain.ext;

import java.util.Date;
import java.util.List;

import org.openstack4j.model.storage.block.ext.Service;
import org.openstack4j.openstack.common.ListResult;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.common.base.Objects;

@JsonRootName("service")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ExtService implements Service {

private static final long serialVersionUID = 1L;

private String binary;

@JsonProperty("disabled_reason")
private String disabledReason;

private String host;

private String id;

private State state;

private Status status;

@JsonProperty("updated_at")
private Date updatedAt;

private String zone;

@Override
public String getBinary() {
return binary;
}

@Override
public String getDisabledReason() {
return disabledReason;
}

@Override
public String getHost() {
return host;
}

@Override
public String getId() {
return id;
}

@Override
public State getState() {
return state;
}

@Override
public Status getStatus() {
return status;
}

@Override
public Date getUpdatedAt() {
return updatedAt;
}

@Override
public String getZone() {
return zone;
}

@Override
public String toString() {
return Objects.toStringHelper(this).omitNullValues().add("id", id).add("binary", binary).add("host", host)
.add("zone", zone).add("status", status).add("state", state).add("updated_at", updatedAt)
.add("disabled_reason", disabledReason).toString();
}

public static class Services extends ListResult<ExtService> {

private static final long serialVersionUID = 1L;

@JsonProperty("services")
private List<ExtService> services;

public List<ExtService> value() {
return services;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.openstack4j.model.storage.block.BlockLimits;
import org.openstack4j.openstack.storage.block.domain.CinderBlockLimits;
import org.openstack4j.api.storage.SchedulerStatsGetPoolService;
import org.openstack4j.api.storage.ext.BlockStroageServicesService;

/**
* Block Storage (Cinder) Service Operation implementation
Expand Down Expand Up @@ -70,4 +71,13 @@ public BlockVolumeBackupService backups() {
return Apis.get(BlockVolumeBackupService.class);
}

/**
* {@inheritDoc}
*/
@Override
public BlockStroageServicesService services() {
return Apis.get(BlockStroageServicesService.class);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openstack4j.openstack.storage.block.internal;

import java.util.List;

import org.openstack4j.api.storage.ext.BlockStroageServicesService;
import org.openstack4j.model.storage.block.ext.Service;
import org.openstack4j.openstack.storage.block.domain.ext.ExtService.Services;


/**
* Block Storage Services service provides CRUD capabilities for Cinder service(s).
*
* @author Taemin
*/
public class BlockStorageServicesServiceImpl extends BaseBlockStorageServices implements BlockStroageServicesService {

/**
* {@inheritDoc}
*/
@Override
public List<? extends Service> list() {
return get(Services.class, uri("/os-services")).execute().getList();
}

}