Skip to content

Commit

Permalink
Merge pull request #37 from indigo-dc/spring-boot
Browse files Browse the repository at this point in the history
include new cdmi-spi version
  • Loading branch information
bertl4398 authored Jul 1, 2016
2 parents d3a1982 + ae5776f commit 3b20430
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 43 deletions.
65 changes: 38 additions & 27 deletions src/main/java/edu/kit/scc/CdmiRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.kit.scc.http.HttpResponse;

import org.apache.commons.codec.binary.Base64;
import org.indigo.cdmi.BackEndException;
import org.indigo.cdmi.CdmiObjectStatus;
import org.indigo.cdmi.ConfigurableStorageBackend;
import org.indigo.cdmi.spi.StorageBackend;
Expand Down Expand Up @@ -48,6 +49,7 @@

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

Expand Down Expand Up @@ -102,7 +104,8 @@ public class CdmiRestController {
void init() {
log.debug("Create RestController with storage-backend {}", backendType);
try {
storageBackend = ConfigurableStorageBackend.createStorageBackend(backendType, null);
storageBackend = ConfigurableStorageBackend.createStorageBackend(backendType,
new HashMap<String, String>());
} catch (IllegalArgumentException ex) {
log.warn("ERROR: {}", ex.getMessage());
}
Expand Down Expand Up @@ -443,8 +446,7 @@ private CdmiObject updateOrCreate(CdmiObject cdmiObject, String path, String bod
if (updateJson.has("capabilitiesURI")) {
// Change of QoS
try {
storageBackend.updateCdmiObject(path, existingContainer.getCapabilitiesUri(),
updateJson.getString("capabilitiesURI"));
storageBackend.updateCdmiObject(path, updateJson.getString("capabilitiesURI"));
existingContainer.setCapabilitiesUri(updateJson.getString("capabilitiesURI"));
} catch (Exception ex) {
ex.printStackTrace();
Expand Down Expand Up @@ -474,8 +476,7 @@ private CdmiObject updateOrCreate(CdmiObject cdmiObject, String path, String bod
if (updateJson.has("capabilitiesURI")) {
// Change of QoS
try {
storageBackend.updateCdmiObject(path, existingDataObject.getCapabilitiesUri(),
updateJson.getString("capabilitiesURI"));
storageBackend.updateCdmiObject(path, updateJson.getString("capabilitiesURI"));
existingDataObject.setCapabilitiesUri(updateJson.getString("capabilitiesURI"));
} catch (Exception ex) {
ex.printStackTrace();
Expand All @@ -502,35 +503,45 @@ private CdmiObject updateOrCreate(CdmiObject cdmiObject, String path, String bod

private void getCurrentStatusFromStorageBackend(DataObject dataObject) {
// add information from storage back-end
if (storageBackend != null) {
String path = Paths.get(dataObject.getParentUri(), dataObject.getObjectName()).toString();
CdmiObjectStatus status = storageBackend.getCurrentStatus(path);
// update monitored attributes
for (Entry<String, String> entry : status.getMonitoredAttributes().entrySet()) {
dataObject.getMetadata().put(entry.getKey(), entry.getValue());
}
// update QoS transition information
if (status.getStatus().equals(org.indigo.cdmi.Status.TRANSITION)) {
dataObject.getMetadata().put("cdmi_capabilities_target", status.getTargetCapabilitiesUri());
dataObject.setCapabilitiesUri(status.getCurrentCapabilitiesUri());
try {
if (storageBackend != null) {
String path = Paths.get(dataObject.getParentUri(), dataObject.getObjectName()).toString();
CdmiObjectStatus status = storageBackend.getCurrentStatus(path);
// update monitored attributes
for (Entry<String, String> entry : status.getMonitoredAttributes().entrySet()) {
dataObject.getMetadata().put(entry.getKey(), entry.getValue());
}
// update QoS transition information
if (status.getStatus().equals(org.indigo.cdmi.Status.TRANSITION)) {
dataObject.getMetadata().put("cdmi_capabilities_target",
status.getTargetCapabilitiesUri());
dataObject.setCapabilitiesUri(status.getCurrentCapabilitiesUri());
}
}
} catch (BackEndException ex) {
log.warn("ERROR: {}", ex.getMessage());
}
}

private void getCurrentStatusFromStorageBackend(Container container) {
// add information from storage back-end
if (storageBackend != null) {
String path = Paths.get(container.getParentUri(), container.getObjectName()).toString();
CdmiObjectStatus status = storageBackend.getCurrentStatus(path);
// update monitored attributes
for (Entry<String, String> entry : status.getMonitoredAttributes().entrySet()) {
container.getMetadata().put(entry.getKey(), entry.getValue());
}
// update QoS transition information
if (status.getStatus().equals(org.indigo.cdmi.Status.TRANSITION)) {
container.getMetadata().put("cdmi_capabilities_target", status.getTargetCapabilitiesUri());
container.setCapabilitiesUri(status.getCurrentCapabilitiesUri());
try {
if (storageBackend != null) {
String path = Paths.get(container.getParentUri(), container.getObjectName()).toString();
CdmiObjectStatus status = storageBackend.getCurrentStatus(path);
// update monitored attributes
for (Entry<String, String> entry : status.getMonitoredAttributes().entrySet()) {
container.getMetadata().put(entry.getKey(), entry.getValue());
}
// update QoS transition information
if (status.getStatus().equals(org.indigo.cdmi.Status.TRANSITION)) {
container.getMetadata().put("cdmi_capabilities_target",
status.getTargetCapabilitiesUri());
container.setCapabilitiesUri(status.getCurrentCapabilitiesUri());
}
}
} catch (BackEndException ex) {
log.warn("ERROR: {}", ex.getMessage());
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/edu/kit/scc/FilesystemConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package edu.kit.scc;

import org.indigo.cdmi.BackEndException;
import org.indigo.cdmi.BackendCapability;
import org.indigo.cdmi.BackendCapability.CapabilityType;
import org.indigo.cdmi.ConfigurableStorageBackend;
Expand All @@ -30,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -116,8 +118,8 @@ public void init() throws IOException {
//
// Creates the provided for this specific storage back-end capabilities.
try {
StorageBackend storageBackend =
ConfigurableStorageBackend.createStorageBackend(backendType, null);
StorageBackend storageBackend = ConfigurableStorageBackend.createStorageBackend(backendType,
new HashMap<String, String>());

List<BackendCapability> capabilities = storageBackend.getCapabilities();
for (BackendCapability capability : capabilities) {
Expand All @@ -142,7 +144,7 @@ public void init() throws IOException {
providedCapability);
}
}
} catch (IllegalArgumentException ex) {
} catch (IllegalArgumentException | BackEndException ex) {
log.warn("ERROR: {}", ex.getMessage());
}
}
Expand Down
31 changes: 18 additions & 13 deletions src/main/java/edu/kit/scc/cdmi/FilesystemBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class FilesystemBackend implements StorageBackend {
private HashMap<String, String> monitoredAttributes = new HashMap<>();

// simulates transitions of QoS
private HashMap<String, String[]> transitionMap = new HashMap<>();
private HashMap<String, CdmiObjectStatus> transitionMap = new HashMap<>();

// simulates storage back-end capabilities
private HashMap<String, String> capabilities = new HashMap<>();
Expand All @@ -42,12 +42,13 @@ public class FilesystemBackend implements StorageBackend {
* Constructs a dummy file-system module with dummy values.
*/
public FilesystemBackend() {

capabilities.put("cdmi_capabilities_templates", "true");
capabilities.put("cdmi_capabilities_exact_inherit", "true");
capabilities.put("cdmi_data_redundancy", "true");
capabilities.put("cdmi_geographic_placement", "true");
capabilities.put("cdmi_latency", "true");
capabilities.put("cdmi_capabilities_allowed", "");
capabilities.put("cdmi_capabilities_allowed", "profile1 profile2");

metadata.put("cdmi_data_redundancy", "4");
metadata.put("cdmi_geographic_placement", "[DE, FR]");
Expand All @@ -56,6 +57,7 @@ public FilesystemBackend() {
monitoredAttributes.put("cdmi_data_redundancy_provided", "4");
monitoredAttributes.put("cdmi_geographic_placement_provided", "[DE, FR]");
monitoredAttributes.put("cdmi_latency_provided", "100");

}

@Override
Expand All @@ -74,35 +76,38 @@ public List<BackendCapability> getCapabilities() {
}

@Override
public void updateCdmiObject(String path, String currentCapabilitiesUri,
String targetCapabilitiesUri) throws BackEndException {
public void updateCdmiObject(String path, String targetCapabilitiesUri) throws BackEndException {
if (!transitionMap.containsKey(path)) {
transitionMap.put(path,
new CdmiObjectStatus(Status.OK, monitoredAttributes, "profile1", null));
}

String currentCapabilitiesUri = transitionMap.get(path).getCurrentCapabilitiesUri();

log.debug("Simulate QoS transition for {} from {} to {}", path, currentCapabilitiesUri,
targetCapabilitiesUri);
transitionMap.put(path, new String[] {currentCapabilitiesUri, targetCapabilitiesUri});
transitionMap.put(path, new CdmiObjectStatus(Status.TRANSITION, monitoredAttributes,
currentCapabilitiesUri, targetCapabilitiesUri));

// simulates a 10 sec transition
long delay = 10 * 1000;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
transitionMap.remove(path);
log.debug("Simulated QoS transition for {} from {} to {} finished", path,
currentCapabilitiesUri, targetCapabilitiesUri);
transitionMap.put(path,
new CdmiObjectStatus(Status.OK, monitoredAttributes, targetCapabilitiesUri, null));
}
}, delay);
}

@Override
public CdmiObjectStatus getCurrentStatus(String path) {
if (transitionMap.containsKey(path)) {
// object still in transition;
String[] transitionUris = transitionMap.get(path);
String currentUri = transitionUris[0];
String transitionUri = transitionUris[1];
return new CdmiObjectStatus(Status.TRANSITION, monitoredAttributes, currentUri,
transitionUri);
return transitionMap.get(path);
}
return new CdmiObjectStatus(Status.OK, monitoredAttributes, null, null);
return new CdmiObjectStatus(Status.OK, monitoredAttributes, "profile1", null);
}
}

0 comments on commit 3b20430

Please sign in to comment.