use of com.google.appengine.tools.cloudstorage.GcsService in project pratilipi by Pratilipi.
the class DataStoreUtil method main.
public static void main(String... args) throws IOException, UnexpectedServerException, InterruptedException, ParseException {
RemoteApiOptions options = new RemoteApiOptions().server("m.gamma.pratilipi.com", 80).useServiceAccountCredential("prod-pratilipi@appspot.gserviceaccount.com", "PrivateKey.p12").remoteApiPath("/remote_api");
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
ObjectifyService.begin();
Memcache memcache = DataAccessorFactory.getL2CacheAccessor();
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
SearchAccessor searchAccessor = DataAccessorFactory.getSearchAccessor();
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
// START
// END
installer.uninstall();
}
use of com.google.appengine.tools.cloudstorage.GcsService in project pratilipi by Pratilipi.
the class PratilipiBackupApi method post.
@Post
public GenericResponse post(PostRequest request) throws UnexpectedServerException {
Pratilipi pratilipi = DataAccessorFactory.getDataAccessor().getPratilipi(request.pratilipiId);
Date dateTime = new Date(pratilipi.getLastUpdated().getTime() + TimeUnit.HOURS.toMillis(1L) - 1);
DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd-HH'.00'-z");
dateTimeFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
String srcBucket = "static.pratilipi.com";
String dstBucket = "backup.pratilipi.com";
String srcPrefix = "pratilipi/" + request.pratilipiId + "/";
String dstPrefix = srcBucket + "/pratilipi-" + dateTimeFormat.format(dateTime) + "/" + request.pratilipiId + "/";
try {
ListResult result = gcsService.list(srcBucket, new ListOptions.Builder().setPrefix(srcPrefix).build());
while (result.hasNext()) {
String srcName = result.next().getName();
String dstName = dstPrefix + srcName.substring(srcPrefix.length());
gcsService.copy(new GcsFilename(srcBucket, srcName), new GcsFilename(dstBucket, dstName));
}
} catch (IOException e) {
logger.log(Level.SEVERE, "", e);
throw new UnexpectedServerException();
}
return new GenericResponse();
}
Aggregations