Skip to content

Commit 306c66f

Browse files
author
arnett, stu
committed
v2.1.2
1 parent 75d0a3f commit 306c66f

14 files changed

+100
-49
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
allprojects {
1616
group = 'com.emc.ecs'
17-
version = '2.1.1'
17+
version = '2.1.2'
1818
}
1919

2020
ext.mainClass = 'com.emc.ecs.sync.EcsSync'
@@ -60,7 +60,7 @@ dependencies {
6060
"commons-cli:commons-cli:1.3.1",
6161
"com.google.code.gson:gson:2.0",
6262
"com.emc.ecs:atmos-client:2.2.2.1",
63-
"com.emc.ecs:object-client:2.1.1",
63+
"com.emc.ecs:object-client:2.2.1",
6464
"mysql:mysql-connector-java:5.1.37",
6565
"org.springframework:spring-jdbc:3.2.6.RELEASE",
6666
"org.springframework:spring-context:3.2.6.RELEASE",

src/main/java/com/emc/ecs/sync/model/SyncMetadata.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.emc.ecs.sync.model;
1616

1717
import com.emc.ecs.sync.CommonOptions;
18+
import com.emc.ecs.sync.util.SyncUtil;
1819
import com.google.gson.GsonBuilder;
1920
import com.google.gson.JsonElement;
2021
import com.google.gson.JsonObject;
@@ -171,8 +172,8 @@ public void setExpirationDate(Date expirationDate) {
171172
*/
172173
public static String getMetaPath(String relativePath, boolean directory) {
173174
String name = new File(relativePath).getName();
174-
String base = directory ? relativePath : new File(relativePath).getParent();
175-
return new File(new File(base, METADATA_DIR), directory ? DIR_META_FILE : name).getPath();
175+
String base = directory ? relativePath : SyncUtil.parentPath(relativePath);
176+
return SyncUtil.combinePath(SyncUtil.combinePath(base, METADATA_DIR), directory ? DIR_META_FILE : name);
176177
}
177178

178179
public static SyncMetadata fromJson(String json) {

src/main/java/com/emc/ecs/sync/source/FilesystemSource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ protected String getRelativePath(File file) {
287287
if (!useAbsolutePath && rootFile != null && relativePath.startsWith(rootFile.getAbsolutePath())) {
288288
relativePath = relativePath.substring(rootFile.getAbsolutePath().length());
289289
}
290-
if (File.separatorChar == '\\') {
291-
relativePath = relativePath.replace('\\', '/');
290+
if (File.separatorChar != '/') {
291+
relativePath = relativePath.replace(File.separatorChar, '/');
292292
}
293293
if (relativePath.startsWith("/")) {
294294
relativePath = relativePath.substring(1);

src/main/java/com/emc/ecs/sync/target/CasSimpleTarget.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public class CasSimpleTarget extends SyncTarget {
5959
public static final String TAG_ARG_NAME = "tag";
6060
public static final String TAG_PATTERN = "^(_|[a-zA-Z])+([a-zA-Z0-9]|\\.|-)*$";
6161

62+
public static final String CLIP_NAME_OPTION = "clip-name";
63+
public static final String CLIP_NAME_DESC = "Specifies a generic name to be set on each clip.";
64+
public static final String CLIP_NAME_ARG_NAME = "name";
65+
6266
public static final String RETENTION_CLASS_OPTION = "retention-class";
6367
public static final String RETENTION_CLASS_DESC = "Specifies the target retention class to specify on the clip.";
6468
public static final String RETENTION_CLASS_ARG_NAME = "class";
@@ -92,6 +96,7 @@ public class CasSimpleTarget extends SyncTarget {
9296

9397
private String topTagName = DEFAULT_TOP_TAG;
9498
private String retentionClass;
99+
private String clipName;
95100
private int blobEmbedThreshold = 0;
96101
private int retentionPeriod;
97102
private int retentionPeriodEbr;
@@ -112,6 +117,8 @@ public Options getCustomOptions() {
112117
.hasArg().argName(EBR_RETENTION_PERIOD_ARG_NAME).build());
113118
opts.addOption(Option.builder().longOpt(EMBEDDED_DATA_THRESHOLD_OPTION).desc(EMBEDDED_DATA_THRESHOLD_DESC)
114119
.hasArg().argName(EMBEDDED_DATA_THRESHOLD_ARG_NAME).build());
120+
opts.addOption(Option.builder().longOpt(CLIP_NAME_OPTION).desc(CLIP_NAME_DESC)
121+
.hasArg().argName(CLIP_NAME_ARG_NAME).build());
115122
return opts;
116123
}
117124

@@ -127,6 +134,8 @@ protected void parseCustomOptions(CommandLine line) {
127134

128135
connectionString = targetUri.replaceFirst("^" + this.URI_PREFIX, "");
129136

137+
if (line.hasOption(CLIP_NAME_OPTION))
138+
clipName = line.getOptionValue(CLIP_NAME_OPTION);
130139
if (line.hasOption(RETENTION_CLASS_OPTION))
131140
retentionClass = line.getOptionValue(RETENTION_CLASS_OPTION);
132141
if (line.hasOption(RETENTION_PERIOD_OPTION))
@@ -238,7 +247,11 @@ public void filter(SyncObject obj){
238247
clip = TimingUtil.time(this, this.OPERATION_CREATE_CLIP, new Callable<FPClip>() {
239248
@Override
240249
public FPClip call() throws Exception {
241-
return new FPClip(pool);
250+
if(clipName != null) {
251+
return new FPClip(pool, clipName);
252+
} else {
253+
return new FPClip(pool);
254+
}
242255
}
243256
});
244257

@@ -429,4 +442,8 @@ public void setBlobEmbedThreshold (int blobEmbedThreshold) {
429442
}
430443

431444
public int getBlobEmbedThreshold () { return blobEmbedThreshold; }
445+
446+
public void setClipName (String clipName) { this.clipName = clipName; }
447+
448+
public String getClipName() { return clipName; }
432449
}

src/main/java/com/emc/ecs/sync/util/FilesystemUtil.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,16 @@ public static SyncMetadata createFilesystemMetadata(File file, MimetypesFileType
106106

107107
if (preserveFileMeta) {
108108
// preserve file times
109-
FileTime mtime = basicAttr.lastModifiedTime();
109+
long mtime = basicAttr.lastModifiedTime().toMillis();
110110
FileTime atime = basicAttr.lastAccessTime();
111111
FileTime crtime = basicAttr.creationTime();
112112

113-
metadata.setModificationTime(new Date(mtime.toMillis()));
114-
metadata.setUserMetadataValue(META_MTIME, mtime.toString());
115-
if (atime != null) metadata.setUserMetadataValue(META_ATIME, atime.toString());
116-
if (crtime != null) metadata.setUserMetadataValue(META_CRTIME, crtime.toString());
113+
metadata.setModificationTime(new Date(mtime));
114+
metadata.setUserMetadataValue(META_MTIME, Iso8601Util.format(new Date(mtime)));
115+
if (atime != null)
116+
metadata.setUserMetadataValue(META_ATIME, Iso8601Util.format(new Date(atime.toMillis())));
117+
if (crtime != null)
118+
metadata.setUserMetadataValue(META_CRTIME, Iso8601Util.format(new Date(crtime.toMillis())));
117119

118120
// preserve POSIX ACL
119121
if (posixAttr != null) {

src/main/java/com/emc/ecs/sync/util/SyncUtil.java

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package com.emc.ecs.sync.util;
1616

17+
import java.io.File;
1718
import java.io.IOException;
1819
import java.io.InputStream;
1920
import java.text.MessageFormat;
@@ -58,6 +59,19 @@ public static String join(List<?> objects, String delimiter) {
5859
return result;
5960
}
6061

62+
public static String parentPath(String path) {
63+
String parentPath = new File(path).getParent();
64+
if (parentPath != null && File.separatorChar != '/')
65+
parentPath = parentPath.replace(File.separatorChar, '/');
66+
return parentPath;
67+
}
68+
69+
public static String combinePath(String parent, String child) {
70+
String path = new File(parent, child).getPath();
71+
if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/');
72+
return path;
73+
}
74+
6175
private SyncUtil() {
6276
}
6377
}

src/test/java/com/emc/ecs/sync/CliTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
public class CliTest {
3939
@Test
4040
public void testFilesystemCli() throws Exception {
41-
File sourceFile = new File("/tmp/foo");
42-
File targetFile = new File("/tmp/bar");
41+
String sourcePath = "/tmp/foo";
42+
String targetPath = "/tmp/bar";
4343
String[] args = new String[]{
44-
"-source", "file://" + sourceFile,
45-
"-target", "file://" + targetFile,
44+
"-source", "file://" + sourcePath,
45+
"-target", "file://" + targetPath,
4646
"--use-absolute-path"
4747
};
4848

@@ -61,9 +61,9 @@ public void testFilesystemCli() throws Exception {
6161
Assert.assertTrue("target is not FilesystemTarget", target instanceof FilesystemTarget);
6262
FilesystemTarget fsTarget = (FilesystemTarget) target;
6363

64-
Assert.assertEquals("source file mismatch", sourceFile, fsSource.getRootFile());
64+
Assert.assertEquals("source file mismatch", new File(sourcePath), fsSource.getRootFile());
6565
Assert.assertTrue("source use-absolute-path should be enabled", fsSource.isUseAbsolutePath());
66-
Assert.assertEquals("target file mismatch", targetFile, fsTarget.getTargetRoot());
66+
Assert.assertEquals("target file mismatch", new File(targetPath), fsTarget.getTargetRoot());
6767
}
6868

6969
@Test

src/test/java/com/emc/ecs/sync/EncryptionTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public void setUp() throws Exception {
5050
}
5151

5252
@Test
53-
public void testEncryptionDescription() throws Exception {
54-
final File tempDir = new File("/tmp/ecs-sync-encryption-test");
53+
public void testEncryptionDecryption() throws Exception {
54+
final File tempDir = File.createTempFile("ecs-sync-encryption-test", null);
55+
tempDir.delete();
5556
tempDir.mkdir();
5657
tempDir.deleteOnExit();
5758

src/test/java/com/emc/ecs/sync/EndToEndTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public void testTestPlugins() throws Exception {
9696

9797
@Test
9898
public void testFilesystem() throws Exception {
99-
final File tempDir = new File("/tmp/ecs-sync-filesystem-test"); // File.createTempFile("ecs-sync-filesystem-test", "dir");
99+
final File tempDir = File.createTempFile("ecs-sync-filesystem-test", null);
100+
tempDir.delete();
100101
tempDir.mkdir();
101102
tempDir.deleteOnExit();
102103

@@ -130,8 +131,9 @@ public boolean isEstimator() {
130131

131132
@Test
132133
public void testArchive() throws Exception {
133-
final File archive = new File("/tmp/ecs-sync-archive-test.zip");
134-
if (archive.exists()) archive.delete();
134+
File tempFile = File.createTempFile("ecs-sync-archive-test", null);
135+
tempFile.deleteOnExit();
136+
final File archive = new File(tempFile.getParentFile(), "ecs-sync-archive-test.zip");
135137
archive.deleteOnExit();
136138

137139
PluginGenerator<FileSyncObject> archiveGenerator = new PluginGenerator<FileSyncObject>(null) {

src/test/java/com/emc/ecs/sync/source/FilesystemSourceTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
public class FilesystemSourceTest {
3838
@Test
3939
public void testModifiedSince() throws Exception {
40-
final File tempDir = new File("/tmp/ecs-sync-filesystem-source-test"); // File.createTempFile("ecs-sync-filesystem-test", "dir");
40+
final File tempDir = File.createTempFile("ecs-sync-filesystem-test", null);
41+
tempDir.delete();
4142
tempDir.mkdir();
4243
tempDir.deleteOnExit();
4344

@@ -106,7 +107,8 @@ public void testModifiedSince() throws Exception {
106107

107108
@Test
108109
public void testFileTimes() throws Exception {
109-
final File tempDir = new File("/tmp/ecs-sync-filesystem-source-test");
110+
final File tempDir = File.createTempFile("ecs-sync-filesystem-source-test", null);
111+
tempDir.delete();
110112
tempDir.mkdir();
111113
tempDir.deleteOnExit();
112114

src/test/java/com/emc/ecs/sync/target/CasSimpleTargetTest.java

+20-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class CasSimpleTargetTest {
4343

4444
private String connectString;
4545
private String retentionClass;
46+
private String clipName;
4647
private Integer retentionPeriod;
4748
private Integer retentionPeriodEbr;
4849

@@ -55,6 +56,7 @@ public void setup() throws Exception {
5556

5657
connectString = syncProperties.getProperty(SyncConfig.PROP_CAS_CONNECT_STRING);
5758
retentionClass = syncProperties.getProperty(SyncConfig.PROP_CAS_RETENTION_CLASS);
59+
clipName = syncProperties.getProperty(SyncConfig.PROP_CAS_CLIP_NAME);
5860
if (syncProperties.getProperty(SyncConfig.PROP_CAS_RETENTION_PERIOD) != null)
5961
retentionPeriod = Integer.parseInt(syncProperties.getProperty(SyncConfig.PROP_CAS_RETENTION_PERIOD));
6062
if (syncProperties.getProperty(SyncConfig.PROP_CAS_RETENTION_PERIOD_EBR) != null)
@@ -81,6 +83,7 @@ public void testSyncWithVerification() throws Exception {
8183
source.configure(null, null, null);
8284
CasSimpleTarget target = new CasSimpleTarget();
8385
target.setConnectionString(connectString);
86+
target.setClipName(clipName);
8487

8588
IdCollector idCollector = new IdCollector();
8689

@@ -196,13 +199,15 @@ public void testCli() throws Exception {
196199
String rClass = "rcTest";
197200
String rPeriod = "100";
198201
String rPeriodEbr = "200";
202+
String clipName = "Clip";
199203
String[] args = new String[]{
200204
"-source", "file:///tmp/foo",
201205
"-target", "cas-simple:hpp://cas.ip.address?cas.pea",
202206
"--target-top-tag", tagName,
203207
"--retention-class", rClass,
204208
"--retention-period", rPeriod,
205-
"--ebr-retention-period", rPeriodEbr
209+
"--ebr-retention-period", rPeriodEbr,
210+
"--clip-name", clipName
206211
};
207212

208213
// use reflection to bootstrap EcsSync using CLI arguments
@@ -219,6 +224,7 @@ public void testCli() throws Exception {
219224
Assert.assertEquals("retention period mismatch", Integer.parseInt(rPeriod), csTarget.getRetentionPeriod());
220225
Assert.assertEquals("ebr retention period mismatch", Integer.parseInt(rPeriodEbr), csTarget.getRetentionPeriodEbr());
221226
Assert.assertEquals("tag name mismatch", tagName, csTarget.getTopTagName());
227+
Assert.assertEquals("clip name mismatch", clipName, csTarget.getClipName());
222228
}
223229

224230
private void verify(TestObjectSource source, CasSimpleTarget target) throws Exception {
@@ -244,6 +250,10 @@ private void verifyClipIntegrity(String clipId, TestSyncObject sourceObject, Cas
244250

245251
Assert.assertEquals("x-emc-data", tagName);
246252

253+
if(target.getClipName() != null) {
254+
Assert.assertEquals("clip name does not match", clipName, clip.getName());
255+
}
256+
247257
if (target.getRetentionClass() != null) {
248258
Assert.assertEquals("retention class does not match", retentionClass, clip.getRetentionClassName());
249259
}
@@ -293,13 +303,15 @@ private void deleteClips(CasSimpleTarget target, Collection<String> clipIds) {
293303
ExecutorService executor = Executors.newFixedThreadPool(32);
294304
List<Future> futures = new ArrayList<>();
295305
for (final String clipId : clipIds) {
296-
futures.add(executor.submit(new Callable<Void>() {
297-
@Override
298-
public Void call() throws Exception {
299-
FPClip.Delete(pool, clipId);
300-
return null;
301-
}
302-
}));
306+
if (clipId != null) {
307+
futures.add(executor.submit(new Callable<Void>() {
308+
@Override
309+
public Void call() throws Exception {
310+
FPClip.Delete(pool, clipId);
311+
return null;
312+
}
313+
}));
314+
}
303315
}
304316

305317
for (Future future : futures) {

src/test/java/com/emc/ecs/sync/test/SyncConfig.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class SyncConfig {
3939
public static final String PROP_CAS_RETENTION_CLASS = "cas.retention_class";
4040
public static final String PROP_CAS_RETENTION_PERIOD = "cas.retention_period";
4141
public static final String PROP_CAS_RETENTION_PERIOD_EBR = "cas.retention_period_ebr";
42+
public static final String PROP_CAS_CLIP_NAME = "cas.clip_name";
4243

4344
public static final String PROP_HTTP_PROXY_URI = "http.proxyUri";
4445

src/test/java/com/emc/ecs/sync/test/TestObjectSource.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import com.emc.ecs.sync.model.SyncMetadata;
2121
import com.emc.ecs.sync.source.SyncSource;
2222
import com.emc.ecs.sync.target.SyncTarget;
23+
import com.emc.ecs.sync.util.SyncUtil;
2324
import org.apache.commons.cli.CommandLine;
2425
import org.apache.commons.cli.Options;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
2728

28-
import java.io.File;
2929
import java.util.*;
3030

3131
public class TestObjectSource extends SyncSource<TestSyncObject> {
@@ -133,7 +133,8 @@ private List<TestSyncObject> generateRandomObjects(String parentPath, int levelC
133133
for (int i = 0; i < levelCount; i++) {
134134
boolean hasChildren = random.nextInt(100) < CHANCE_OF_CHILDREN;
135135

136-
String path = new File(parentPath, "random" + i + (hasChildren ? ".dir" : ".object")).getPath();
136+
String name = "random" + i + (hasChildren ? ".dir" : ".object");
137+
String path = SyncUtil.combinePath(parentPath, name);
137138
log.info("generating object {}", path);
138139

139140
TestSyncObject object = new TestSyncObject(this, path, path,

0 commit comments

Comments
 (0)