mirror of https://github.com/apache/jclouds.git
separated runtime metadata from normal domain objects in elasticstack api
This commit is contained in:
parent
73c27dce6d
commit
bf325b1126
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BindDriveToPlainTextString implements Binder {
|
||||
private final Function<Drive, Map<String, String>> createDriveRequestToMap;
|
||||
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
|
||||
@Inject
|
||||
public BindDriveToPlainTextString(Function<Drive, Map<String, String>> createDriveRequestToMap,
|
||||
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
|
||||
this.createDriveRequestToMap = createDriveRequestToMap;
|
||||
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
checkArgument(payload instanceof Drive, "this binder is only valid for Drive!");
|
||||
Drive create = Drive.class.cast(payload);
|
||||
Map<String, String> map = createDriveRequestToMap.apply(create);
|
||||
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map)));
|
||||
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,219 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Drive extends Item {
|
||||
public static class Builder extends Item.Builder {
|
||||
protected long size;
|
||||
protected ClaimType claimType = ClaimType.EXCLUSIVE;
|
||||
protected Set<String> readers = ImmutableSet.of();
|
||||
|
||||
public Builder claimType(ClaimType claimType) {
|
||||
this.claimType = claimType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder readers(Iterable<String> readers) {
|
||||
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(long size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder uuid(String uuid) {
|
||||
return Builder.class.cast(super.uuid(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder tags(Iterable<String> tags) {
|
||||
return Builder.class.cast(super.tags(tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder userMetadata(Map<String, String> userMetadata) {
|
||||
return Builder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
public Drive build() {
|
||||
return new Drive(uuid, name, size, claimType, readers, tags, userMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
|
||||
result = prime * result + ((readers == null) ? 0 : readers.hashCode());
|
||||
result = prime * result + (int) (size ^ (size >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Builder other = (Builder) obj;
|
||||
if (claimType != other.claimType)
|
||||
return false;
|
||||
if (readers == null) {
|
||||
if (other.readers != null)
|
||||
return false;
|
||||
} else if (!readers.equals(other.readers))
|
||||
return false;
|
||||
if (size != other.size)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected final long size;
|
||||
protected final ClaimType claimType;
|
||||
protected final Set<String> readers;
|
||||
|
||||
public Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType,
|
||||
Iterable<String> readers, Iterable<String> tags, Map<String, String> userMetadata) {
|
||||
super(uuid, name, tags, userMetadata);
|
||||
this.size = size;
|
||||
this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
|
||||
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return either 'exclusive' (the default) or 'shared' to allow multiple servers to access a
|
||||
* drive simultaneously
|
||||
*/
|
||||
@Nullable
|
||||
public ClaimType getClaimType() {
|
||||
return claimType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return list of users allowed to read from a drive or 'ffffffff-ffff-ffff-ffff-ffffffffffff'
|
||||
* for all users
|
||||
*/
|
||||
public Set<String> getReaders() {
|
||||
return readers;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return size of drive in bytes
|
||||
*/
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((readers == null) ? 0 : readers.hashCode());
|
||||
result = prime * result + (int) (size ^ (size >>> 32));
|
||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||
result = prime * result + ((userMetadata == null) ? 0 : userMetadata.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Drive other = (Drive) obj;
|
||||
if (claimType != other.claimType)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (readers == null) {
|
||||
if (other.readers != null)
|
||||
return false;
|
||||
} else if (!readers.equals(other.readers))
|
||||
return false;
|
||||
if (size != other.size)
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
return false;
|
||||
} else if (!tags.equals(other.tags))
|
||||
return false;
|
||||
if (userMetadata == null) {
|
||||
if (other.userMetadata != null)
|
||||
return false;
|
||||
} else if (!userMetadata.equals(other.userMetadata))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", size="
|
||||
+ size + ", claimType=" + claimType + ", readers=" + readers + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.domain;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DriveMetrics {
|
||||
public static class Builder {
|
||||
protected long readBytes;
|
||||
protected long readRequests;
|
||||
protected long writeBytes;
|
||||
protected long writeRequests;
|
||||
|
||||
public Builder readBytes(long readBytes) {
|
||||
this.readBytes = readBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder readRequests(long readRequests) {
|
||||
this.readRequests = readRequests;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder writeBytes(long writeBytes) {
|
||||
this.writeBytes = writeBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder writeRequests(long writeRequests) {
|
||||
this.writeRequests = writeRequests;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DriveMetrics build() {
|
||||
return new DriveMetrics(readBytes, readRequests, writeBytes, writeRequests);
|
||||
}
|
||||
}
|
||||
|
||||
protected final long readBytes;
|
||||
protected final long readRequests;
|
||||
protected final long writeBytes;
|
||||
protected final long writeRequests;
|
||||
|
||||
public DriveMetrics(long readBytes, long readRequests, long writeBytes, long writeRequests) {
|
||||
this.readBytes = readBytes;
|
||||
this.readRequests = readRequests;
|
||||
this.writeBytes = writeBytes;
|
||||
this.writeRequests = writeRequests;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Cumulative i/o byte/request count for each drive
|
||||
*/
|
||||
public long getReadBytes() {
|
||||
return readBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Cumulative i/o byte/request count for each drive
|
||||
*/
|
||||
public long getReadRequests() {
|
||||
return readRequests;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Cumulative i/o byte/request count for each drive
|
||||
*/
|
||||
public long getWriteBytes() {
|
||||
return writeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Cumulative i/o byte/request count for each drive
|
||||
*/
|
||||
public long getWriteRequests() {
|
||||
return writeRequests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (readBytes ^ (readBytes >>> 32));
|
||||
result = prime * result + (int) (readRequests ^ (readRequests >>> 32));
|
||||
result = prime * result + (int) (writeBytes ^ (writeBytes >>> 32));
|
||||
result = prime * result + (int) (writeRequests ^ (writeRequests >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DriveMetrics other = (DriveMetrics) obj;
|
||||
if (readBytes != other.readBytes)
|
||||
return false;
|
||||
if (readRequests != other.readRequests)
|
||||
return false;
|
||||
if (writeBytes != other.writeBytes)
|
||||
return false;
|
||||
if (writeRequests != other.writeRequests)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[readBytes=" + readBytes + ", readRequests=" + readRequests + ", writeBytes=" + writeBytes
|
||||
+ ", writeRequests=" + writeRequests + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,297 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Server extends Item {
|
||||
|
||||
public static class Builder extends Item.Builder {
|
||||
protected int cpu;
|
||||
protected Integer smp;
|
||||
protected int mem;
|
||||
protected boolean persistent;
|
||||
protected Map<String, ? extends Device> devices = ImmutableMap.of();
|
||||
protected Set<String> bootDeviceIds = ImmutableSet.of();
|
||||
protected List<NIC> nics = ImmutableList.of();
|
||||
protected VNC vnc;
|
||||
// TODO undocumented
|
||||
protected String description;
|
||||
|
||||
public Builder cpu(int cpu) {
|
||||
this.cpu = cpu;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder smp(Integer smp) {
|
||||
this.smp = smp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mem(int mem) {
|
||||
this.mem = mem;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder persistent(boolean persistent) {
|
||||
this.persistent = persistent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder devices(Map<String, ? extends Device> devices) {
|
||||
this.devices = ImmutableMap.copyOf(checkNotNull(devices, "devices"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootDeviceIds(Iterable<String> bootDeviceIds) {
|
||||
this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nics(Iterable<NIC> nics) {
|
||||
this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vnc(VNC vnc) {
|
||||
this.vnc = vnc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder uuid(String uuid) {
|
||||
return Builder.class.cast(super.uuid(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder tags(Iterable<String> tags) {
|
||||
return Builder.class.cast(super.tags(tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder userMetadata(Map<String, String> userMetadata) {
|
||||
return Builder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
public Server build() {
|
||||
return new Server(uuid, name, cpu, smp, mem, persistent, devices, tags, bootDeviceIds, userMetadata, nics,
|
||||
vnc, description);
|
||||
}
|
||||
}
|
||||
|
||||
protected final int cpu;
|
||||
protected final Integer smp;
|
||||
protected final int mem;
|
||||
protected final boolean persistent;
|
||||
@Nullable
|
||||
protected final Map<String, ? extends Device> devices;
|
||||
protected final Set<String> bootDeviceIds;
|
||||
protected final List<NIC> nics;
|
||||
protected final VNC vnc;
|
||||
@Nullable
|
||||
private final String description;
|
||||
|
||||
public Server(@Nullable String uuid, String name, int cpu, @Nullable Integer smp, int mem, boolean persistent,
|
||||
Map<String, ? extends Device> devices, Iterable<String> bootDeviceIds, Iterable<String> tags,
|
||||
Map<String, String> userMetadata, Iterable<NIC> nics, VNC vnc, String description) {
|
||||
super(uuid, name, tags, userMetadata);
|
||||
this.cpu = cpu;
|
||||
this.smp = smp;
|
||||
this.mem = mem;
|
||||
this.persistent = persistent;
|
||||
this.devices = ImmutableMap.copyOf(checkNotNull(devices, "devices"));
|
||||
this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds"));
|
||||
this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics"));
|
||||
this.vnc = checkNotNull(vnc, "vnc");
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return CPU quota in core MHz.
|
||||
*/
|
||||
public int getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return number of virtual processors or null if calculated based on cpu.
|
||||
*/
|
||||
public Integer getSmp() {
|
||||
return smp;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return virtual memory size in MB.
|
||||
*/
|
||||
public int getMem() {
|
||||
return mem;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return 'true' means that server will revert to a 'stopped' status on server stop or shutdown,
|
||||
* rather than being destroyed automatically.
|
||||
*/
|
||||
public boolean isPersistent() {
|
||||
return persistent;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return devices present, mapped by id
|
||||
*/
|
||||
public Map<String, ? extends Device> getDevices() {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ids of the devices to boot, e.g. ide:0:0 or ide:1:0
|
||||
* @see Device#getId()
|
||||
*/
|
||||
public Set<String> getBootDeviceIds() {
|
||||
return bootDeviceIds;
|
||||
}
|
||||
|
||||
public List<NIC> getNics() {
|
||||
return nics;
|
||||
}
|
||||
|
||||
public VNC getVnc() {
|
||||
return vnc;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((bootDeviceIds == null) ? 0 : bootDeviceIds.hashCode());
|
||||
result = prime * result + cpu;
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((devices == null) ? 0 : devices.hashCode());
|
||||
result = prime * result + mem;
|
||||
result = prime * result + ((nics == null) ? 0 : nics.hashCode());
|
||||
result = prime * result + (persistent ? 1231 : 1237);
|
||||
result = prime * result + ((smp == null) ? 0 : smp.hashCode());
|
||||
result = prime * result + ((vnc == null) ? 0 : vnc.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Server other = (Server) obj;
|
||||
if (bootDeviceIds == null) {
|
||||
if (other.bootDeviceIds != null)
|
||||
return false;
|
||||
} else if (!bootDeviceIds.equals(other.bootDeviceIds))
|
||||
return false;
|
||||
if (cpu != other.cpu)
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (devices == null) {
|
||||
if (other.devices != null)
|
||||
return false;
|
||||
} else if (!devices.equals(other.devices))
|
||||
return false;
|
||||
if (mem != other.mem)
|
||||
return false;
|
||||
if (nics == null) {
|
||||
if (other.nics != null)
|
||||
return false;
|
||||
} else if (!nics.equals(other.nics))
|
||||
return false;
|
||||
if (persistent != other.persistent)
|
||||
return false;
|
||||
if (smp == null) {
|
||||
if (other.smp != null)
|
||||
return false;
|
||||
} else if (!smp.equals(other.smp))
|
||||
return false;
|
||||
if (vnc == null) {
|
||||
if (other.vnc != null)
|
||||
return false;
|
||||
} else if (!vnc.equals(other.vnc))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", cpu=" + cpu
|
||||
+ ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices
|
||||
+ ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", description=" + description
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ServerMetrics {
|
||||
|
||||
public static class Builder {
|
||||
protected long txPackets;
|
||||
protected long tx;
|
||||
protected long rxPackets;
|
||||
protected long rx;
|
||||
protected Map<String, DriveMetrics> driveMetrics = ImmutableMap.<String, DriveMetrics> of();
|
||||
|
||||
public Builder txPackets(long txPackets) {
|
||||
this.txPackets = txPackets;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tx(long tx) {
|
||||
this.tx = tx;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder rxPackets(long rxPackets) {
|
||||
this.rxPackets = rxPackets;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder rx(long rx) {
|
||||
this.rx = rx;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder driveMetrics(Map<String, ? extends DriveMetrics> driveMetrics) {
|
||||
this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerMetrics build() {
|
||||
return new ServerMetrics(tx, txPackets, rx, rxPackets, driveMetrics);
|
||||
}
|
||||
}
|
||||
|
||||
protected final long txPackets;
|
||||
protected final long tx;
|
||||
protected final long rxPackets;
|
||||
protected final long rx;
|
||||
protected final Map<String, DriveMetrics> driveMetrics;
|
||||
|
||||
public ServerMetrics(long tx, long txPackets, long rx, long rxPackets, Map<String, DriveMetrics> driveMetrics) {
|
||||
this.txPackets = txPackets;
|
||||
this.tx = tx;
|
||||
this.rxPackets = rxPackets;
|
||||
this.rx = rx;
|
||||
this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics"));
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public long getTxPackets() {
|
||||
return txPackets;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public long getTx() {
|
||||
return tx;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public long getRxPackets() {
|
||||
return rxPackets;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public long getRx() {
|
||||
return rx;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return metrics keyed on device id ex. {@code ide:0:0}
|
||||
*/
|
||||
public Map<String, DriveMetrics> getDriveMetrics() {
|
||||
return driveMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((driveMetrics == null) ? 0 : driveMetrics.hashCode());
|
||||
result = prime * result + (int) (rx ^ (rx >>> 32));
|
||||
result = prime * result + (int) (rxPackets ^ (rxPackets >>> 32));
|
||||
result = prime * result + (int) (tx ^ (tx >>> 32));
|
||||
result = prime * result + (int) (txPackets ^ (txPackets >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ServerMetrics other = (ServerMetrics) obj;
|
||||
if (driveMetrics == null) {
|
||||
if (other.driveMetrics != null)
|
||||
return false;
|
||||
} else if (!driveMetrics.equals(other.driveMetrics))
|
||||
return false;
|
||||
if (rx != other.rx)
|
||||
return false;
|
||||
if (rxPackets != other.rxPackets)
|
||||
return false;
|
||||
if (tx != other.tx)
|
||||
return false;
|
||||
if (txPackets != other.txPackets)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ txPackets=" + txPackets + ", tx=" + tx + ", rxPackets=" + rxPackets + ", rx=" + rx + ", driveMetrics="
|
||||
+ driveMetrics + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.DriveMetrics;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToDriveMetrics implements Function<Map<String, String>, Map<String, ? extends DriveMetrics>> {
|
||||
|
||||
public Map<String, ? extends DriveMetrics> apply(Map<String, String> from) {
|
||||
Builder<String, DriveMetrics> builder = ImmutableMap.<String, DriveMetrics> builder();
|
||||
addIDEDevices(from, builder);
|
||||
addSCSIDevices(from, builder);
|
||||
addBlockDevices(from, builder);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected void addBlockDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
|
||||
BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
|
||||
String key = String.format("block:0:%d", index);
|
||||
if (!from.containsKey(key))
|
||||
break BLOCK;
|
||||
devices.put(key, buildMetrics(key, from));
|
||||
}
|
||||
}
|
||||
|
||||
protected void addSCSIDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
|
||||
SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
|
||||
String key = String.format("scsi:0:%d", unit);
|
||||
if (!from.containsKey(key))
|
||||
break SCSI;
|
||||
devices.put(key, buildMetrics(key, from));
|
||||
}
|
||||
}
|
||||
|
||||
protected void addIDEDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
|
||||
IDE: for (int bus : new int[] { 0, 1 })
|
||||
for (int unit : new int[] { 0, 1 }) {
|
||||
String key = String.format("ide:%d:%d", bus, unit);
|
||||
if (!from.containsKey(key))
|
||||
break IDE;
|
||||
devices.put(key, buildMetrics(key, from));
|
||||
}
|
||||
}
|
||||
|
||||
protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
|
||||
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
||||
if (from.containsKey(key + ":read:bytes"))
|
||||
builder.readBytes(new Long(from.get(key + ":read:bytes")));
|
||||
if (from.containsKey(key + ":read:requests"))
|
||||
builder.readRequests(new Long(from.get(key + ":read:requests")));
|
||||
if (from.containsKey(key + ":write:bytes"))
|
||||
builder.writeBytes(new Long(from.get(key + ":write:bytes")));
|
||||
if (from.containsKey(key + ":write:requests"))
|
||||
builder.writeRequests(new Long(from.get(key + ":write:requests")));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.DriveMetrics;
|
||||
import org.jclouds.elasticstack.domain.ServerMetrics;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToServerMetrics implements Function<Map<String, String>, ServerMetrics> {
|
||||
private final Function<Map<String, String>, Map<String, ? extends DriveMetrics>> mapToDriveMetrics;
|
||||
|
||||
@Inject
|
||||
public MapToServerMetrics(Function<Map<String, String>, Map<String, ? extends DriveMetrics>> mapToDriveMetrics) {
|
||||
this.mapToDriveMetrics = mapToDriveMetrics;
|
||||
}
|
||||
|
||||
public ServerMetrics apply(Map<String, String> from) {
|
||||
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
||||
if (from.containsKey("tx:packets"))
|
||||
metricsBuilder.txPackets(new Long(from.get("tx:packets")));
|
||||
if (from.containsKey("tx"))
|
||||
metricsBuilder.tx(new Long(from.get("tx")));
|
||||
if (from.containsKey("rx:packets"))
|
||||
metricsBuilder.rxPackets(new Long(from.get("rx:packets")));
|
||||
if (from.containsKey("rx"))
|
||||
metricsBuilder.rx(new Long(from.get("rx")));
|
||||
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
||||
|
||||
ServerMetrics metrics = metricsBuilder.build();
|
||||
return metrics;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elasticstack.binders;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.elasticstack.domain.ClaimType;
|
||||
import org.jclouds.elasticstack.domain.CreateDriveRequest;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.functions.CreateDriveRequestToMap;
|
||||
import org.jclouds.elasticstack.functions.DriveDataToMap;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class BindDriveToPlainTextStringTest {
|
||||
|
||||
private static final BindDriveToPlainTextString FN = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
|
||||
}).to(CreateDriveRequestToMap.class);
|
||||
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
|
||||
}).to(DriveDataToMap.class);
|
||||
}
|
||||
|
||||
}).getInstance(BindDriveToPlainTextString.class);
|
||||
|
||||
public void testSimple() {
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, new CreateDriveRequest.Builder().name("foo").size(100l).build());
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||
assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
|
||||
}
|
||||
|
||||
public void testComplete() throws IOException {
|
||||
CreateDriveRequest input = new CreateDriveRequest.Builder()
|
||||
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
|
||||
.encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build();
|
||||
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, input);
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||
assertEquals(request.getPayload().getRawContent(),
|
||||
Utils.toStringAndClose(BindDriveToPlainTextStringTest.class
|
||||
.getResourceAsStream("/create_drive.txt")));
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue