1616// under the License.
1717package org .apache .cloudstack .storage .resource ;
1818
19+
20+ import static com .cloud .utils .S3Utils .mputFile ;
21+ import static com .cloud .utils .S3Utils .putFile ;
22+ import static com .cloud .utils .StringUtils .join ;
23+ import static com .cloud .utils .db .GlobalLock .executeWithNoWaitLock ;
24+ import static java .lang .String .format ;
25+ import static java .util .Arrays .asList ;
26+ import static org .apache .commons .lang .StringUtils .substringAfterLast ;
27+
1928import java .io .BufferedReader ;
2029import java .io .BufferedWriter ;
2130import java .io .File ;
4049
4150import javax .naming .ConfigurationException ;
4251
52+ import org .apache .commons .codec .digest .DigestUtils ;
53+ import org .apache .commons .lang .StringUtils ;
54+ import org .apache .http .HttpEntity ;
55+ import org .apache .http .HttpResponse ;
56+ import org .apache .http .NameValuePair ;
57+ import org .apache .http .client .HttpClient ;
58+ import org .apache .http .client .methods .HttpGet ;
59+ import org .apache .http .client .utils .URLEncodedUtils ;
60+ import org .apache .http .impl .client .DefaultHttpClient ;
61+ import org .apache .log4j .Logger ;
62+
63+ import com .amazonaws .services .s3 .model .S3ObjectSummary ;
64+
4365import org .apache .cloudstack .storage .command .CopyCmdAnswer ;
4466import org .apache .cloudstack .storage .command .CopyCommand ;
4567import org .apache .cloudstack .storage .command .DeleteCommand ;
5072import org .apache .cloudstack .storage .template .DownloadManagerImpl .ZfsPathParser ;
5173import org .apache .cloudstack .storage .template .UploadManager ;
5274import org .apache .cloudstack .storage .template .UploadManagerImpl ;
53- import org .apache .cloudstack .storage .to .ImageStoreTO ;
54- import org .apache .cloudstack .storage .to .PrimaryDataStoreTO ;
5575import org .apache .cloudstack .storage .to .SnapshotObjectTO ;
5676import org .apache .cloudstack .storage .to .TemplateObjectTO ;
5777import org .apache .cloudstack .storage .to .VolumeObjectTO ;
58- import org .apache .commons .codec .digest .DigestUtils ;
59- import org .apache .commons .lang .StringUtils ;
60- import org .apache .http .HttpEntity ;
61- import org .apache .http .HttpResponse ;
62- import org .apache .http .NameValuePair ;
63- import org .apache .http .client .HttpClient ;
64- import org .apache .http .client .methods .HttpGet ;
65- import org .apache .http .client .utils .URLEncodedUtils ;
66- import org .apache .http .impl .client .DefaultHttpClient ;
67- import org .apache .log4j .Logger ;
6878
69- import com .amazonaws .services .s3 .model .S3ObjectSummary ;
7079import com .cloud .agent .api .Answer ;
7180import com .cloud .agent .api .CheckHealthAnswer ;
7281import com .cloud .agent .api .CheckHealthCommand ;
108117import com .cloud .resource .ServerResourceBase ;
109118import com .cloud .storage .DataStoreRole ;
110119import com .cloud .storage .Storage .ImageFormat ;
111- import com .cloud .storage .Storage .StoragePoolType ;
112120import com .cloud .storage .StorageLayer ;
113121import com .cloud .storage .VMTemplateStorageResourceAssoc ;
114122import com .cloud .storage .template .Processor ;
128136import com .cloud .utils .script .OutputInterpreter ;
129137import com .cloud .utils .script .Script ;
130138import com .cloud .vm .SecondaryStorageVm ;
131- import com .google .common .io .Files ;
132-
133- import static com .cloud .utils .S3Utils .putFile ;
134- import static com .cloud .utils .StringUtils .join ;
135- import static com .cloud .utils .db .GlobalLock .executeWithNoWaitLock ;
136- import static java .lang .String .format ;
137- import static java .util .Arrays .asList ;
138- import static org .apache .commons .lang .StringUtils .substringAfterLast ;
139139
140140public class NfsSecondaryStorageResource extends ServerResourceBase implements SecondaryStorageResource {
141141
@@ -197,7 +197,7 @@ public void disconnected() {
197197 }
198198
199199 public void setInSystemVM (boolean inSystemVM ) {
200- this . _inSystemVM = inSystemVM ;
200+ _inSystemVM = inSystemVM ;
201201 }
202202
203203 @ Override
@@ -297,7 +297,7 @@ protected CopyCmdAnswer postProcessing(File destFile, String downloadPath, Strin
297297 String finalFileName = templateFilename ;
298298 String finalDownloadPath = destPath + File .separator + templateFilename ;
299299 // compute the size of
300- long size = this . _storage .getSize (downloadPath + File .separator + templateFilename );
300+ long size = _storage .getSize (downloadPath + File .separator + templateFilename );
301301
302302 DataTO newDestTO = null ;
303303
@@ -374,7 +374,7 @@ public String determineFileName(final String key) {
374374
375375 protected Answer copySnapshotToTemplateFromNfsToNfsXenserver (CopyCommand cmd , SnapshotObjectTO srcData ,
376376 NfsTO srcDataStore , TemplateObjectTO destData , NfsTO destDataStore ) {
377- String srcMountPoint = this . getRootDir (srcDataStore .getUrl ());
377+ String srcMountPoint = getRootDir (srcDataStore .getUrl ());
378378 String snapshotPath = srcData .getPath ();
379379 int index = snapshotPath .lastIndexOf ("/" );
380380 String snapshotName = snapshotPath .substring (index + 1 );
@@ -384,16 +384,16 @@ protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, Sn
384384 snapshotPath = snapshotPath .substring (0 , index );
385385
386386 snapshotPath = srcMountPoint + File .separator + snapshotPath ;
387- String destMountPoint = this . getRootDir (destDataStore .getUrl ());
387+ String destMountPoint = getRootDir (destDataStore .getUrl ());
388388 String destPath = destMountPoint + File .separator + destData .getPath ();
389389
390390 String errMsg = null ;
391391 try {
392- this . _storage .mkdir (destPath );
392+ _storage .mkdir (destPath );
393393
394394 String templateUuid = UUID .randomUUID ().toString ();
395395 String templateName = templateUuid + ".vhd" ;
396- Script command = new Script (this . createTemplateFromSnapshotXenScript , cmd .getWait () * 1000 , s_logger );
396+ Script command = new Script (createTemplateFromSnapshotXenScript , cmd .getWait () * 1000 , s_logger );
397397 command .add ("-p" , snapshotPath );
398398 command .add ("-s" , snapshotName );
399399 command .add ("-n" , templateName );
@@ -468,7 +468,7 @@ protected Answer copySnapshotToTemplateFromNfsToNfs(CopyCommand cmd, SnapshotObj
468468 bufferWriter .write ("\n " );
469469 bufferWriter .write ("filename=" + fileName );
470470 bufferWriter .write ("\n " );
471- long size = this . _storage .getSize (destFileFullPath );
471+ long size = _storage .getSize (destFileFullPath );
472472 bufferWriter .write ("size=" + size );
473473 bufferWriter .close ();
474474 writer .close ();
@@ -630,7 +630,7 @@ protected Answer execute(CopyCommand cmd) {
630630 NfsTO destImageStore = (NfsTO ) destDataStore ;
631631 if (srcDataStore instanceof S3TO ) {
632632 S3TO s3 = (S3TO ) srcDataStore ;
633- return this . copyFromS3ToNfs (cmd , srcData , s3 , destData , destImageStore );
633+ return copyFromS3ToNfs (cmd , srcData , s3 , destData , destImageStore );
634634 } else if (srcDataStore instanceof SwiftTO ) {
635635 return copyFromSwiftToNfs (cmd , srcData , (SwiftTO )srcDataStore , destData , destImageStore );
636636 }
@@ -857,9 +857,13 @@ protected Answer copyFromNfsToS3(CopyCommand cmd) {
857857 }
858858 }
859859 }
860- ImageFormat format = this . getTemplateFormat (srcFile .getName ());
860+ ImageFormat format = getTemplateFormat (srcFile .getName ());
861861 String key = destData .getPath () + S3Utils .SEPARATOR + srcFile .getName ();
862- putFile (s3 , srcFile , bucket , key );
862+ if (s3 .isMultipartEnabled ()){
863+ mputFile (s3 , srcFile , bucket , key );
864+ } else {
865+ putFile (s3 , srcFile , bucket , key );
866+ }
863867
864868 DataTO retObj = null ;
865869 if (destData .getObjectType () == DataObjectType .TEMPLATE ) {
@@ -1271,9 +1275,9 @@ private String deleteSnapshotBackupFromLocalFileSystem(final String secondarySto
12711275 int index = name .lastIndexOf (File .separator );
12721276 String snapshotPath = name .substring (0 , index );
12731277 if (deleteAllFlag ) {
1274- lPath = this . getRootDir (secondaryStorageUrl ) + File .separator + snapshotPath + File .separator + "*" ;
1278+ lPath = getRootDir (secondaryStorageUrl ) + File .separator + snapshotPath + File .separator + "*" ;
12751279 } else {
1276- lPath = this . getRootDir (secondaryStorageUrl ) + File .separator + name + "*" ;
1280+ lPath = getRootDir (secondaryStorageUrl ) + File .separator + name + "*" ;
12771281 }
12781282
12791283 final String result = deleteLocalFile (lPath );
@@ -1461,7 +1465,7 @@ Map<String, TemplateProp> swiftListTemplate(SwiftTO swift) {
14611465 Map <String , TemplateProp > s3ListTemplate (S3TO s3 ) {
14621466 String bucket = s3 .getBucketName ();
14631467 // List the objects in the source directory on S3
1464- final List <S3ObjectSummary > objectSummaries = S3Utils .getDirectory (s3 , bucket , this . TEMPLATE_ROOT_DIR );
1468+ final List <S3ObjectSummary > objectSummaries = S3Utils .getDirectory (s3 , bucket , TEMPLATE_ROOT_DIR );
14651469 if (objectSummaries == null ) {
14661470 return null ;
14671471 }
@@ -1470,7 +1474,7 @@ Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
14701474 String key = objectSummary .getKey ();
14711475 // String installPath = StringUtils.substringBeforeLast(key,
14721476 // S3Utils.SEPARATOR);
1473- String uniqueName = this . determineS3TemplateNameFromKey (key );
1477+ String uniqueName = determineS3TemplateNameFromKey (key );
14741478 // TODO: isPublic value, where to get?
14751479 TemplateProp tInfo = new TemplateProp (uniqueName , key , objectSummary .getSize (), objectSummary .getSize (),
14761480 true , false );
@@ -1483,7 +1487,7 @@ Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
14831487 Map <Long , TemplateProp > s3ListVolume (S3TO s3 ) {
14841488 String bucket = s3 .getBucketName ();
14851489 // List the objects in the source directory on S3
1486- final List <S3ObjectSummary > objectSummaries = S3Utils .getDirectory (s3 , bucket , this . VOLUME_ROOT_DIR );
1490+ final List <S3ObjectSummary > objectSummaries = S3Utils .getDirectory (s3 , bucket , VOLUME_ROOT_DIR );
14871491 if (objectSummaries == null ) {
14881492 return null ;
14891493 }
@@ -1492,7 +1496,7 @@ Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
14921496 String key = objectSummary .getKey ();
14931497 // String installPath = StringUtils.substringBeforeLast(key,
14941498 // S3Utils.SEPARATOR);
1495- Long id = this . determineS3VolumeIdFromKey (key );
1499+ Long id = determineS3VolumeIdFromKey (key );
14961500 // TODO: how to get volume template name
14971501 TemplateProp tInfo = new TemplateProp (id .toString (), key , objectSummary .getSize (), objectSummary .getSize (),
14981502 true , false );
0 commit comments