From 9e9fface2559ced2795b0a6ffc3d4bd44fda9bc9 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 10 Nov 2011 10:42:18 +0000 Subject: [PATCH 1/4] Issue 695: Added licence header --- .../trmk/enterprisecloud/domain/Action.java | 18 ++++++++++++++++++ .../trmk/enterprisecloud/domain/Link.java | 18 ++++++++++++++++++ .../enterprisecloud/domain/NamedResource.java | 18 ++++++++++++++++++ .../trmk/enterprisecloud/domain/Task.java | 18 ++++++++++++++++++ .../domain/internal/BaseNamedResource.java | 18 ++++++++++++++++++ .../domain/internal/BaseResource.java | 18 ++++++++++++++++++ 6 files changed, 108 insertions(+) diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java index d37d6acc1f..b04db750c8 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain; import static com.google.common.base.CaseFormat.LOWER_CAMEL; diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java index c261ffe724..d0e45608e5 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java index 5952e58268..3a5b50c9fe 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain; import java.net.URI; diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java index 281436dd9e..ec36e30269 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain; import static com.google.common.base.CaseFormat.UPPER_CAMEL; diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java index f0ed4477d6..8910c2e692 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain.internal; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java index 0bd85cb087..c99d26b287 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java @@ -1,3 +1,21 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain.internal; import static com.google.common.base.Preconditions.checkNotNull; From 508973b7abe1d55e366c88fa9fa6df4bd8cbb15f Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 10 Nov 2011 15:19:41 +0000 Subject: [PATCH 2/4] Issue 695: Override methods in builders, equals, hashcode and toString methods. Fix test --- .../trmk/enterprisecloud/domain/Action.java | 57 ++++ .../trmk/enterprisecloud/domain/Link.java | 57 ++++ .../enterprisecloud/domain/NamedResource.java | 21 +- .../trmk/enterprisecloud/domain/Task.java | 49 ++- .../domain/VirtualMachine.java | 309 ++++++++++++++++++ .../domain/internal/BaseNamedResource.java | 79 ++--- .../domain/internal/BaseResource.java | 6 +- .../features/TaskAsyncClientTest.java | 6 +- 8 files changed, 520 insertions(+), 64 deletions(-) create mode 100644 sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java index b04db750c8..817ea55e1c 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Action.java @@ -27,6 +27,7 @@ import java.util.Map; import org.jclouds.javax.annotation.Nullable; import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource; /** * @@ -108,6 +109,14 @@ public class Action extends BaseNamedResource { return fromNamedResource(in).actionDisabled(in.getActionDisabled()); } + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); + } + /** * {@inheritDoc} */ @@ -116,6 +125,30 @@ public class Action extends BaseNamedResource { return Builder.class.cast(super.fromNamedResource(in)); } + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + /** * {@inheritDoc} */ @@ -147,4 +180,28 @@ public class Action extends BaseNamedResource { return actionDisabled; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + Action action = (Action) o; + + if (actionDisabled != action.actionDisabled) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (actionDisabled != null ? actionDisabled.hashCode() : 0); + return result; + } + + @Override + public String string() { + return super.string()+", actionDisabled="+actionDisabled; + } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java index d0e45608e5..1c74cba6f7 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Link.java @@ -24,6 +24,7 @@ import java.net.URI; import java.util.Map; import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource; /** * @@ -118,6 +119,14 @@ public class Link extends BaseNamedResource { return fromNamedResource(in).rel(in.getRelationship()); } + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); + } + /** * {@inheritDoc} */ @@ -126,6 +135,30 @@ public class Link extends BaseNamedResource { return Builder.class.cast(super.fromNamedResource(in)); } + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + /** * {@inheritDoc} */ @@ -153,4 +186,28 @@ public class Link extends BaseNamedResource { return rel; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + Link link = (Link) o; + + if (rel != link.rel) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + rel.hashCode(); + return result; + } + + @Override + public String string() { + return super.string()+", rel="+rel; + } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java index 3a5b50c9fe..4fb56cc452 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/NamedResource.java @@ -22,6 +22,7 @@ import java.net.URI; import java.util.Map; import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource; /** * @@ -57,22 +58,30 @@ public class NamedResource extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); } /** * {@inheritDoc} */ @Override - public Builder type(String type) { - return Builder.class.cast(super.type(type)); + public Builder fromNamedResource(BaseNamedResource in) { + return Builder.class.cast(super.fromNamedResource(in)); } /** * {@inheritDoc} */ @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override public Builder href(URI href) { return Builder.class.cast(super.href(href)); } @@ -81,8 +90,8 @@ public class NamedResource extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder fromNamedResource(BaseNamedResource in) { - return Builder.class.cast(super.fromNamedResource(in)); + public Builder type(String type) { + return Builder.class.cast(super.type(type)); } /** diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java index ec36e30269..3ddf490d26 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Task.java @@ -299,11 +299,48 @@ public class Task extends BaseResource { return initiatedBy; } - @Override - public String toString() { - return "[type=" + type + ", href=" + href + ", operation=" + operation + ", status=" + status + ", impactedItem=" - + impactedItem + ", startTime=" + startTime + ", completedTime=" + completedTime + ", notes=" + notes - + ", errorMessage=" + errorMessage + ", initiatedBy=" + initiatedBy + "]"; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + Task task = (Task) o; + + if (completedTime != null ? !completedTime.equals(task.completedTime) : task.completedTime != null) + return false; + if (errorMessage != null ? !errorMessage.equals(task.errorMessage) : task.errorMessage != null) + return false; + if (!impactedItem.equals(task.impactedItem)) return false; + if (!initiatedBy.equals(task.initiatedBy)) return false; + if (notes != null ? !notes.equals(task.notes) : task.notes != null) + return false; + if (!operation.equals(task.operation)) return false; + if (!startTime.equals(task.startTime)) return false; + if (status != task.status) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + operation.hashCode(); + result = 31 * result + status.hashCode(); + result = 31 * result + impactedItem.hashCode(); + result = 31 * result + startTime.hashCode(); + result = 31 * result + (completedTime != null ? completedTime.hashCode() : 0); + result = 31 * result + (notes != null ? notes.hashCode() : 0); + result = 31 * result + (errorMessage != null ? errorMessage.hashCode() : 0); + result = 31 * result + initiatedBy.hashCode(); + return result; + } + + @Override + public String string() { + return super.string()+", operation="+operation+", status="+status+ + ", impactedItem="+impactedItem+", startTime="+startTime+", completedTime="+completedTime+ + ", notes="+notes+", errorMessage="+errorMessage+", initiatedBy="+initiatedBy; + } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java new file mode 100644 index 0000000000..342e07cad6 --- /dev/null +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java @@ -0,0 +1,309 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.trmk.enterprisecloud.domain; + +import static com.google.common.base.CaseFormat.UPPER_CAMEL; +import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Date; +import java.util.Map; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource; + +/** + * + * @author Adrian Cole + * + */ +public class VirtualMachine extends BaseResource { + public static enum Status { + /** + * the task is queued for execution. + */ + QUEUED, + /** + * the task is running. + */ + RUNNING, + /** + * the task failed. + */ + FAILED, + /** + * the task completed successfully. + */ + SUCCESS, + /** + * the task failed with an error. + */ + ERROR, + /** + * Status was not parsed by jclouds. + */ + UNRECOGNIZED; + + public String value() { + return UPPER_UNDERSCORE.to(UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static Status fromValue(String status) { + try { + return valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromTask(this); + } + + public static class Builder extends BaseResource.Builder { + protected String operation; + protected Status status; + protected NamedResource impactedItem; + protected Date startTime; + protected Date completedTime; + protected String notes; + protected String errorMessage; + protected NamedResource initiatedBy; + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getOperation + */ + public Builder operation(String operation) { + this.operation = operation; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getStatus + */ + public Builder status(Status status) { + this.status = status; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getImpactedItem + */ + public Builder impactedItem(NamedResource impactedItem) { + this.impactedItem = impactedItem; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getStartTime + */ + public Builder startTime(Date startTime) { + this.startTime = startTime; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getCompletedTime + */ + public Builder completedTime(Date completedTime) { + this.completedTime = completedTime; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getNotes + */ + public Builder notes(String notes) { + this.notes = notes; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getErrorMessage + */ + public Builder errorMessage(String errorMessage) { + this.errorMessage = errorMessage; + return this; + } + + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getInitiatedBy + */ + public Builder initiatedBy(NamedResource initiatedBy) { + this.initiatedBy = initiatedBy; + return this; + } + + @Override + public VirtualMachine build() { + return new VirtualMachine(href, type, operation, status, impactedItem, startTime, completedTime, notes, errorMessage, + initiatedBy); + } + + public Builder fromTask(VirtualMachine in) { + return fromResource(in).operation(in.getOperation()).status(in.getStatus()).impactedItem(in.getImpactedItem()) + .startTime(in.getStartTime()).completedTime(in.getCompletedTime()).notes(in.getNotes()) + .errorMessage(in.getErrorMessage()).initiatedBy(in.getInitiatedBy()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + + } + + protected final String operation; + protected final Status status; + protected final NamedResource impactedItem; + protected final Date startTime; + protected final Date completedTime; + protected final String notes; + protected final String errorMessage; + protected final NamedResource initiatedBy; + + public VirtualMachine(URI href, String type, String operation, Status status, NamedResource impactedItem, Date startTime, + @Nullable Date completedTime, @Nullable String notes, @Nullable String errorMessage, NamedResource initiatedBy) { + super(href, type); + this.operation = checkNotNull(operation, "operation"); + this.status = checkNotNull(status, "status"); + this.impactedItem = checkNotNull(impactedItem, "impactedItem"); + this.startTime = checkNotNull(startTime, "startTime"); + this.completedTime = completedTime;// null if Queued or Running + this.notes = notes; + this.errorMessage = errorMessage; + this.initiatedBy = checkNotNull(initiatedBy, "initiatedBy"); + } + + /** + * + * + * @return name of action performed + */ + public String getOperation() { + return operation; + } + + /** + * + * + * @return the status of the task + */ + public Status getStatus() { + return status; + } + + /** + * + * @return the item acted upon + */ + public NamedResource getImpactedItem() { + return impactedItem; + } + + /** + * + * @return time action started + */ + public Date getStartTime() { + return startTime; + } + + /** + * + * @return time action completed, or null if Queued or Running + */ + @Nullable + public Date getCompletedTime() { + return completedTime; + } + + /** + * @return notes on action + */ + public String getNotes() { + return notes; + } + + /** + * @return error message + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * + * @return the item acted upon + */ + public NamedResource getInitiatedBy() { + return initiatedBy; + } + + @Override + public String toString() { + return "[type=" + type + ", href=" + href + ", operation=" + operation + ", status=" + status + ", impactedItem=" + + impactedItem + ", startTime=" + startTime + ", completedTime=" + completedTime + ", notes=" + notes + + ", errorMessage=" + errorMessage + ", initiatedBy=" + initiatedBy + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java index 8910c2e692..bd84c0fbe5 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseNamedResource.java @@ -55,6 +55,15 @@ public class BaseNamedResource> extends BaseResou return new BaseNamedResource(href, type, name); } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); + } + public Builder fromNamedResource(BaseNamedResource in) { return fromResource(in).name(in.getName()); } @@ -66,15 +75,6 @@ public class BaseNamedResource> extends BaseResou public Builder fromAttributes(Map attributes) { return Builder.class.cast(super.fromAttributes(attributes)).name(attributes.get("name")); } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - @Override - public Builder fromResource(BaseResource in) { - return Builder.class.cast(super.fromResource(in)); - } } protected final String name; @@ -88,45 +88,28 @@ public class BaseNamedResource> extends BaseResou return name; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((href == null) ? 0 : href.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - BaseNamedResource other = (BaseNamedResource) obj; - if (href == null) { - if (other.href != null) - return false; - } else if (!href.equals(other.href)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; - } + BaseNamedResource that = (BaseNamedResource) o; - @Override - public String toString() { - return "[href=" + href + ", name=" + name + ", type=" + type + "]"; - } + if (!name.equals(that.name)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + name.hashCode(); + return result; + } + + @Override + public String string() { + return super.string()+", name="+name; + } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java index c99d26b287..2e8e1b841b 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/internal/BaseResource.java @@ -131,6 +131,10 @@ public class BaseResource> { @Override public String toString() { - return "[href=" + href + ", type=" + type + "]"; + return String.format("[%s]",string()); + } + + protected String string() { + return "href="+href+", type="+type; } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/features/TaskAsyncClientTest.java b/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/features/TaskAsyncClientTest.java index 660a7f8b52..b3779ace15 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/features/TaskAsyncClientTest.java +++ b/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/features/TaskAsyncClientTest.java @@ -45,7 +45,7 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment", long.class); HttpRequest httpRequest = processor.createRequest(method, 1l); - assertRequestLineEquals(httpRequest, "GET http://209.251.187.125/livespec/tasks/environments/1 HTTP/1.1"); + assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/tasks/environments/1 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task; type=collection\nx-trmk-version: 2011-07-01\n"); assertPayloadEquals(httpRequest, null, null, false); @@ -60,9 +60,9 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = TaskAsyncClient.class.getMethod("getTask", URI.class); - HttpRequest httpRequest = processor.createRequest(method, URI.create("http://209.251.187.125/livespec/tasks/1")); + HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/tasks/1")); - assertRequestLineEquals(httpRequest, "GET http://209.251.187.125/livespec/tasks/1 HTTP/1.1"); + assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/tasks/1 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-trmk-version: 2011-07-01\n"); assertPayloadEquals(httpRequest, null, null, false); From d0f77def4fc3282e26af47d47f5a8b1866e3beb4 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 10 Nov 2011 17:04:02 +0000 Subject: [PATCH 3/4] Issue 695: Added VirtualMachine domain class and example xml. Tweaked TaskedHandler --- .../domain/VirtualMachine.java | 306 +++++++----------- .../enterprisecloud/xml/TasksHandler.java | 3 +- .../src/test/resources/virtualMachine.xml | 143 ++++++++ 3 files changed, 252 insertions(+), 200 deletions(-) create mode 100644 sandbox-providers/trmk-enterprisecloud/src/test/resources/virtualMachine.xml diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java index 342e07cad6..836e857e45 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java @@ -18,66 +18,21 @@ */ package org.jclouds.trmk.enterprisecloud.domain; -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static com.google.common.base.Preconditions.checkNotNull; +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource; import java.net.URI; -import java.util.Date; +import java.util.List; import java.util.Map; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource; +import static com.google.common.base.Preconditions.checkNotNull; /** * - * @author Adrian Cole + * @author Jason King * */ -public class VirtualMachine extends BaseResource { - public static enum Status { - /** - * the task is queued for execution. - */ - QUEUED, - /** - * the task is running. - */ - RUNNING, - /** - * the task failed. - */ - FAILED, - /** - * the task completed successfully. - */ - SUCCESS, - /** - * the task failed with an error. - */ - ERROR, - /** - * Status was not parsed by jclouds. - */ - UNRECOGNIZED; - - public String value() { - return UPPER_UNDERSCORE.to(UPPER_CAMEL, name()); - } - - @Override - public String toString() { - return value(); - } - - public static Status fromValue(String status) { - try { - return valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } - } +public class VirtualMachine extends BaseNamedResource { @SuppressWarnings("unchecked") public static Builder builder() { @@ -89,93 +44,59 @@ public class VirtualMachine extends BaseResource { */ @Override public Builder toBuilder() { - return new Builder().fromTask(this); + return new Builder().fromVirtualMachine(this); } - public static class Builder extends BaseResource.Builder { - protected String operation; - protected Status status; - protected NamedResource impactedItem; - protected Date startTime; - protected Date completedTime; - protected String notes; - protected String errorMessage; - protected NamedResource initiatedBy; + public static class Builder extends BaseNamedResource.Builder { + private List links; + private List actions; + private List tasks; + private String description; /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getOperation + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getLinks */ - public Builder operation(String operation) { - this.operation = operation; + public Builder links(List links) { + this.links = links; return this; } - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getStatus - */ - public Builder status(Status status) { - this.status = status; - return this; - } + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getActions + */ + public Builder actions(List actions) { + this.actions = actions; + return this; + } - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getImpactedItem - */ - public Builder impactedItem(NamedResource impactedItem) { - this.impactedItem = impactedItem; - return this; - } + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getTasks + */ + public Builder tasks(List tasks) { + this.tasks = tasks; + return this; + } - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getStartTime - */ - public Builder startTime(Date startTime) { - this.startTime = startTime; - return this; - } - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getCompletedTime - */ - public Builder completedTime(Date completedTime) { - this.completedTime = completedTime; - return this; - } - - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getNotes - */ - public Builder notes(String notes) { - this.notes = notes; - return this; - } - - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getErrorMessage - */ - public Builder errorMessage(String errorMessage) { - this.errorMessage = errorMessage; - return this; - } - - /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getInitiatedBy - */ - public Builder initiatedBy(NamedResource initiatedBy) { - this.initiatedBy = initiatedBy; - return this; - } + /** + * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getDescription + */ + public Builder description(String description) { + this.description = description; + return this; + } @Override public VirtualMachine build() { - return new VirtualMachine(href, type, operation, status, impactedItem, startTime, completedTime, notes, errorMessage, - initiatedBy); + return new VirtualMachine(href, type, name, tasks, actions, links, description); } - public Builder fromTask(VirtualMachine in) { - return fromResource(in).operation(in.getOperation()).status(in.getStatus()).impactedItem(in.getImpactedItem()) - .startTime(in.getStartTime()).completedTime(in.getCompletedTime()).notes(in.getNotes()) - .errorMessage(in.getErrorMessage()).initiatedBy(in.getInitiatedBy()); + public Builder fromVirtualMachine(VirtualMachine in) { + return fromNamedResource(in) + .links(in.getLinks()) + .tasks(in.getTasks()) + .actions(in.getActions()) + .description(in.getDescription()); } /** @@ -186,6 +107,14 @@ public class VirtualMachine extends BaseResource { return Builder.class.cast(super.fromResource(in)); } + /** + * {@inheritDoc} + */ + @Override + public Builder fromNamedResource(BaseNamedResource in) { + return Builder.class.cast(super.fromNamedResource(in)); + } + /** * {@inheritDoc} */ @@ -202,108 +131,89 @@ public class VirtualMachine extends BaseResource { return Builder.class.cast(super.href(href)); } + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + /** * {@inheritDoc} */ @Override public Builder fromAttributes(Map attributes) { return Builder.class.cast(super.fromAttributes(attributes)); + // TODO Other fields? } } - protected final String operation; - protected final Status status; - protected final NamedResource impactedItem; - protected final Date startTime; - protected final Date completedTime; - protected final String notes; - protected final String errorMessage; - protected final NamedResource initiatedBy; + private final List links; + private final List tasks; + private final List actions; + private final String description; - public VirtualMachine(URI href, String type, String operation, Status status, NamedResource impactedItem, Date startTime, - @Nullable Date completedTime, @Nullable String notes, @Nullable String errorMessage, NamedResource initiatedBy) { - super(href, type); - this.operation = checkNotNull(operation, "operation"); - this.status = checkNotNull(status, "status"); - this.impactedItem = checkNotNull(impactedItem, "impactedItem"); - this.startTime = checkNotNull(startTime, "startTime"); - this.completedTime = completedTime;// null if Queued or Running - this.notes = notes; - this.errorMessage = errorMessage; - this.initiatedBy = checkNotNull(initiatedBy, "initiatedBy"); + public VirtualMachine(URI href, String type, String name, List tasks, List actions, List links, String description) { + super(href, type, name); + this.description = checkNotNull(description, "description"); + this.links = checkNotNull(links, "links"); + this.tasks = checkNotNull(tasks, "tasks"); + this.actions = checkNotNull(actions, "actions"); } - /** - * - * - * @return name of action performed - */ - public String getOperation() { - return operation; + public List getLinks() { + return links; } - /** - * - * - * @return the status of the task - */ - public Status getStatus() { - return status; + /** + * refers to tasks regarding the virtual machine. + * Only the most recent tasks, up to twenty, are returned. + * Use the href to retrieve the complete list of tasks. + * @return most recent tasks + */ + public List getTasks() { + return tasks; } - /** - * - * @return the item acted upon - */ - public NamedResource getImpactedItem() { - return impactedItem; + public List getActions() { + return actions; } - /** - * - * @return time action started - */ - public Date getStartTime() { - return startTime; + public String getDescription() { + return description; } - /** - * - * @return time action completed, or null if Queued or Running - */ - @Nullable - public Date getCompletedTime() { - return completedTime; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; - /** - * @return notes on action - */ - public String getNotes() { - return notes; - } + VirtualMachine that = (VirtualMachine) o; - /** - * @return error message - */ - public String getErrorMessage() { - return errorMessage; - } + if (!actions.equals(that.actions)) return false; + if (!description.equals(that.description)) return false; + if (!links.equals(that.links)) return false; + if (!tasks.equals(that.tasks)) return false; - /** - * - * @return the item acted upon - */ - public NamedResource getInitiatedBy() { - return initiatedBy; - } + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + links.hashCode(); + result = 31 * result + tasks.hashCode(); + result = 31 * result + actions.hashCode(); + result = 31 * result + description.hashCode(); + return result; + } @Override - public String toString() { - return "[type=" + type + ", href=" + href + ", operation=" + operation + ", status=" + status + ", impactedItem=" - + impactedItem + ", startTime=" + startTime + ", completedTime=" + completedTime + ", notes=" + notes - + ", errorMessage=" + errorMessage + ", initiatedBy=" + initiatedBy + "]"; + public String string() { + return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description; } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/xml/TasksHandler.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/xml/TasksHandler.java index c2e8325795..b2b028af99 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/xml/TasksHandler.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/xml/TasksHandler.java @@ -30,7 +30,6 @@ import org.xml.sax.Attributes; import org.xml.sax.SAXException; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; /** * @author Adrian Cole @@ -46,7 +45,7 @@ public class TasksHandler extends ParseSax.HandlerWithResult> { protected final TaskHandler taskHandler; - protected Builder builder = ImmutableSet. builder(); + protected ImmutableSet.Builder builder = ImmutableSet. builder(); @Inject public TasksHandler(TaskHandler taskHandler) { diff --git a/sandbox-providers/trmk-enterprisecloud/src/test/resources/virtualMachine.xml b/sandbox-providers/trmk-enterprisecloud/src/test/resources/virtualMachine.xml new file mode 100644 index 0000000000..cee037e899 --- /dev/null +++ b/sandbox-providers/trmk-enterprisecloud/src/test/resources/virtualMachine.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create Server + Complete + + 2011-11-09T21:46:11.787Z + 2011-11-09T21:50:32.933Z + + + 1 + + My first terremark server + + + + + Deployed + false + + + + + 1 + + MB + 384 + + + + 0 + + GB + 10 + + Hard Disk 1 + + + + + 7 + Network adapter 1 + 00:50:56:b8:00:58 + + Internal + + + + + + + + + + + + + 10.146.204.67 + + + + + + + NotRunning + Unmounted + false + \ No newline at end of file From 5c815715b6fbac46de8d475186e6bcbcebd10511 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 10 Nov 2011 17:18:59 +0000 Subject: [PATCH 4/4] Issue 695: Added some metadata --- .../TerremarkEnterpriseCloudProviderMetadata.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/TerremarkEnterpriseCloudProviderMetadata.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/TerremarkEnterpriseCloudProviderMetadata.java index 30dec708f6..8f4975f716 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/TerremarkEnterpriseCloudProviderMetadata.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/TerremarkEnterpriseCloudProviderMetadata.java @@ -79,7 +79,7 @@ public class TerremarkEnterpriseCloudProviderMetadata extends BaseProviderMetada */ @Override public URI getHomepage() { - return URI.create("TODO"); + return URI.create("http://www.terremark.com/services/cloudcomputing/theenterprisecloud.aspx"); } /** @@ -87,7 +87,7 @@ public class TerremarkEnterpriseCloudProviderMetadata extends BaseProviderMetada */ @Override public URI getConsole() { - return URI.create("TODO"); + return URI.create("https://my-beta.enterprisecloud.terremark.com/"); } /**