Skip to content

Commit

Permalink
Merge pull request #885 from HubSpot/artifact_extensions
Browse files Browse the repository at this point in the history
Allow destination targets to be specified
  • Loading branch information
ssalinas committed Mar 17, 2016
2 parents bb1aa87 + 773e28c commit 9f2d4a0
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 147 deletions.
58 changes: 21 additions & 37 deletions SingularityBase/src/main/java/com/hubspot/deploy/Artifact.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hubspot.deploy;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.base.Optional;

Expand All @@ -9,11 +11,13 @@ public abstract class Artifact {
private final String name;
private final String filename;
private final Optional<String> md5sum;
private final Optional<String> targetFolderRelativeToTask;

public Artifact(String name, String filename, Optional<String> md5sum) {
public Artifact(String name, String filename, Optional<String> md5sum, Optional<String> targetFolderRelativeToTask) {
this.name = name;
this.filename = filename;
this.md5sum = md5sum;
this.targetFolderRelativeToTask = targetFolderRelativeToTask;
}

public String getName() {
Expand All @@ -28,55 +32,35 @@ public Optional<String> getMd5sum() {
return md5sum;
}

public Optional<String> getTargetFolderRelativeToTask() {
return targetFolderRelativeToTask;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((filename == null) ? 0 : filename.hashCode());
result = prime * result + ((md5sum == null) ? 0 : md5sum.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
return Objects.hash(name, filename, md5sum, targetFolderRelativeToTask);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Artifact other = (Artifact) obj;
if (filename == null) {
if (other.filename != null) {
return false;
}
} else if (!filename.equals(other.filename)) {
if (other == null || other.getClass() != this.getClass()) {
return false;
}
if (md5sum == null) {
if (other.md5sum != null) {
return false;
}
} else if (!md5sum.equals(other.md5sum)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;

Artifact that = (Artifact) other;

return Objects.equals(this.name, that.name)
&& Objects.equals(this.filename, that.filename)
&& Objects.equals(this.md5sum, that.md5sum)
&& Objects.equals(this.targetFolderRelativeToTask, that.targetFolderRelativeToTask);
}

@Override
public String toString() {
return "Artifact [name=" + name + ", filename=" + filename + ", md5sum=" + md5sum + "]";
return "Artifact [name=" + name + ", filename=" + filename + ", md5sum=" + md5sum + ", targetFolderRelativeToTask=" + targetFolderRelativeToTask + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.hubspot.deploy;

import java.util.Arrays;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -14,8 +17,9 @@ public class EmbeddedArtifact extends Artifact {

@JsonCreator
@SuppressFBWarnings("EI_EXPOSE_REP2")
public EmbeddedArtifact(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum, @JsonProperty("content") byte[] content) {
super(name, filename, md5sum);
public EmbeddedArtifact(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum,
@JsonProperty("content") byte[] content, @JsonProperty("targetFolderRelativeToTask") Optional<String> targetFolderRelativeToTask) {
super(name, filename, md5sum, targetFolderRelativeToTask);
this.content = content;
}

Expand All @@ -24,9 +28,30 @@ public byte[] getContent() {
return content;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), content);
}

@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;
}

EmbeddedArtifact that = (EmbeddedArtifact) o;
return Arrays.equals(content, that.content);
}

@Override
public String toString() {
return "EmbeddedArtifact [getName()=" + getName() + ", getFilename()=" + getFilename() + ", getMd5sum()=" + getMd5sum() + "]";
return "EmbeddedArtifact [parent=" + super.toString() + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hubspot.deploy;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;
Expand All @@ -9,18 +11,40 @@ public class ExternalArtifact extends RemoteArtifact {
private final String url;

@JsonCreator
public ExternalArtifact(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum, @JsonProperty("url") String url, @JsonProperty("filesize") Optional<Long> filesize) {
super(name, filename, md5sum, filesize);
public ExternalArtifact(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum,
@JsonProperty("url") String url, @JsonProperty("filesize") Optional<Long> filesize, @JsonProperty("targetFolderRelativeToTask") Optional<String> targetFolderRelativeToTask) {
super(name, filename, md5sum, filesize, targetFolderRelativeToTask);
this.url = url;
}

public String getUrl() {
return url;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), url);
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null || other.getClass() != this.getClass()) {
return false;
}
if (!super.equals(other)) {
return false;
}

ExternalArtifact that = (ExternalArtifact) other;
return Objects.equals(this.url, that.url);
}

@Override
public String toString() {
return "ExternalArtifact [url=" + url + ", getFilesize()=" + getFilesize() + ", getName()=" + getName() + ", getFilename()=" + getFilename() + ", getMd5sum()=" + getMd5sum() + "]";
return "ExternalArtifact [url=" + url + ", parent=" + super.toString() + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.hubspot.deploy;

import java.util.Objects;

import com.google.common.base.Optional;

public abstract class RemoteArtifact extends Artifact {

private final Optional<Long> filesize;

public RemoteArtifact(String name, String filename, Optional<String> md5sum, Optional<Long> filesize) {
super(name, filename, md5sum);
public RemoteArtifact(String name, String filename, Optional<String> md5sum, Optional<Long> filesize, Optional<String> targetFolderRelativeToTask) {
super(name, filename, md5sum, targetFolderRelativeToTask);
this.filesize = filesize;
}

Expand All @@ -16,38 +18,28 @@ public Optional<Long> getFilesize() {
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((filesize == null) ? 0 : filesize.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!super.equals(obj)) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (getClass() != obj.getClass()) {
if (!super.equals(o)) {
return false;
}
RemoteArtifact other = (RemoteArtifact) obj;
if (filesize == null) {
if (other.filesize != null) {
return false;
}
} else if (!filesize.equals(other.filesize)) {
return false;
}
return true;
RemoteArtifact that = (RemoteArtifact) o;
return Objects.equals(filesize, that.filesize);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), filesize);
}

@Override
public String toString() {
return "RemoteArtifact [filesize=" + filesize + "]";
return "RemoteArtifact [filesize=" + filesize + ", parent=" + super.toString() + "]";
}

}
43 changes: 14 additions & 29 deletions SingularityBase/src/main/java/com/hubspot/deploy/S3Artifact.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hubspot.deploy;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;
Expand All @@ -11,8 +13,9 @@ public class S3Artifact extends RemoteArtifact {

@JsonCreator
public S3Artifact(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum, @JsonProperty("filesize") Optional<Long> filesize,
@JsonProperty("s3Bucket") String s3Bucket, @JsonProperty("s3ObjectKey") String s3ObjectKey) {
super(name, filename, md5sum, filesize);
@JsonProperty("s3Bucket") String s3Bucket, @JsonProperty("s3ObjectKey") String s3ObjectKey, @JsonProperty("targetFolderRelativeToTask") Optional<String> targetFolderRelativeToTask) {
super(name, filename, md5sum, filesize, targetFolderRelativeToTask);

this.s3Bucket = s3Bucket;
this.s3ObjectKey = s3ObjectKey;
}
Expand All @@ -27,46 +30,28 @@ public String getS3ObjectKey() {

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((s3Bucket == null) ? 0 : s3Bucket.hashCode());
result = prime * result + ((s3ObjectKey == null) ? 0 : s3ObjectKey.hashCode());
return result;
return Objects.hash(super.hashCode(), s3Bucket, s3ObjectKey);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
S3Artifact other = (S3Artifact) obj;
if (s3Bucket == null) {
if (other.s3Bucket != null) {
return false;
}
} else if (!s3Bucket.equals(other.s3Bucket)) {
if (other == null || getClass() != other.getClass()) {
return false;
}
if (s3ObjectKey == null) {
if (other.s3ObjectKey != null) {
return false;
}
} else if (!s3ObjectKey.equals(other.s3ObjectKey)) {
if (!super.equals(other)) {
return false;
}
return true;
S3Artifact that = (S3Artifact) other;
return Objects.equals(s3Bucket, that.s3Bucket) &&
Objects.equals(s3ObjectKey, s3ObjectKey);
}

@Override
public String toString() {
return "S3Artifact [s3Bucket=" + s3Bucket + ", s3ObjectKey=" + s3ObjectKey + ", getFilesize()=" + getFilesize() + ", getName()=" + getName() + ", getFilename()=" + getFilename()
+ ", getMd5sum()=" + getMd5sum() + "]";
return "S3Artifact [s3Bucket=" + s3Bucket + ", s3ObjectKey=" + s3ObjectKey + ", parent=" + super.toString() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
import com.google.common.base.Optional;

public class S3ArtifactSignature extends S3Artifact {

private final String artifactFilename;

@JsonCreator
public S3ArtifactSignature(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum, @JsonProperty("filesize") Optional<Long> filesize, @JsonProperty("s3Bucket") String s3Bucket, @JsonProperty("s3ObjectKey") String s3ObjectKey, @JsonProperty("artifactFilename") String artifactFilename) {
super(name, filename, md5sum, filesize, s3Bucket, s3ObjectKey);
public S3ArtifactSignature(@JsonProperty("name") String name, @JsonProperty("filename") String filename, @JsonProperty("md5sum") Optional<String> md5sum,
@JsonProperty("filesize") Optional<Long> filesize, @JsonProperty("s3Bucket") String s3Bucket, @JsonProperty("s3ObjectKey") String s3ObjectKey,
@JsonProperty("artifactFilename") String artifactFilename, @JsonProperty("targetFolderRelativeToTask") Optional<String> targetFolderRelativeToTask) {
super(name, filename, md5sum, filesize, s3Bucket, s3ObjectKey, targetFolderRelativeToTask);

this.artifactFilename = artifactFilename;
}

Expand All @@ -38,4 +42,10 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(super.hashCode(), artifactFilename);
}

@Override
public String toString() {
return "S3ArtifactSignature [artifactFilename=" + artifactFilename + ", parent=" + super.toString() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.apache.mesos.Protos.MasterInfo;
import org.apache.mesos.Protos.Offer;
import org.apache.mesos.Protos.Resource;
import org.apache.mesos.Protos.TaskInfo;
import org.apache.mesos.Protos.TaskState;
import org.apache.mesos.Protos.Value;
import org.apache.mesos.Protos.Value.Range;
Expand Down
Loading

1 comment on commit 9f2d4a0

@tpetr
Copy link
Contributor

@tpetr tpetr commented on 9f2d4a0 Mar 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Please sign in to comment.