usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [01/50] [abbrv] git commit: Revised test to post valid test data ( the export should still fail with the test though) Made certain that the rest endpoint is being called. ( Test still fails due to having null for organizations though) Added in all of the
Date Tue, 25 Feb 2014 06:21:15 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/pull/60/head [created] 22a17dc80
  refs/pull/60/merge [created] cfef069c7


Revised test to post valid test data ( the export should still fail with the test though)
Made certain that the rest endpoint is being called. ( Test still fails due to having null
for organizations though)
Added in all of the code needed for export collections into ExportServiceDos.
( still haven’t handled injects in this commit, maybe that is why things are failing).


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9e941ca7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9e941ca7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9e941ca7

Branch: refs/pull/60/merge
Commit: 9e941ca79f718431454565bcd943e1d684479f0f
Parents: a1903bd
Author: GERey <greyes@apigee.com>
Authored: Tue Feb 4 16:36:40 2014 -0800
Committer: GERey <greyes@apigee.com>
Committed: Tue Feb 4 16:36:40 2014 -0800

----------------------------------------------------------------------
 .../rest/management/ManagementResource.java     | 12 +++-
 .../rest/management/ManagementResourceIT.java   | 40 ++++++++-----
 .../management/export/ExportServiceDos.java     | 60 ++++++++++++++++----
 3 files changed, 85 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e941ca7/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
b/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
index 532e3b2..b610607 100644
--- a/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
+++ b/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
@@ -449,16 +449,24 @@ public class ManagementResource extends AbstractContextResource {
     public Response exportPostJson (@Context UriInfo ui, Map<String, Object> json,
                                     @QueryParam( "callback" ) @DefaultValue( "callback" )
String callback){
 
+        try {
+
+
         //parse the json into some useful object (the config params)
         ExportInfo objEx = new ExportInfo(json);
 
         ExportService ex = new ExportServiceDos();
 
         // exportService.schedule(config)
-        ex.schedule( objEx );
+        ex.doExport( objEx );
+        }
+        catch (Exception e) {
+            //TODO:throw descriptive error message and or include on in the response
+            return Response.serverError().build();
+        }
 
         //TODO: make schedule or doExport return a response? Or create one.
-        return null;
+        return Response.ok().build();
 
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e941ca7/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
b/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
index 03c7a4f..e5fe07a 100644
--- a/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
@@ -435,21 +435,6 @@ public class ManagementResourceIT extends AbstractRestIT {
     }
 
     @Test
-    public void exportCallSuccessful() throws Exception {
-        Status responseStatus = null;
-
-        try {
-            resource().path( "/management/export" ).accept( MediaType.APPLICATION_JSON )
-                    .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class );
-        }
-        catch ( UniformInterfaceException uie ) {
-            responseStatus = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.BAD_REQUEST, responseStatus );
-    }
-
-    @Test
     public void revokeToken() throws Exception {
         String token1 = super.adminToken();
         String token2 = super.adminToken();
@@ -542,4 +527,29 @@ public class ManagementResourceIT extends AbstractRestIT {
 
         assertEquals( Status.OK, status );
     }
+
+    @Test
+    public void exportCallSuccessful() throws Exception {
+        Status responseStatus = null;
+
+        //        Map<String, String> payload =
+        //                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com"
).map( "password", "test" )
+        //                                                   .map( "ttl", Long.MAX_VALUE
+ "" );
+        Map<String, String> storageinfo = hashMap ( "s3_token","insert_token_data_here").map("s3_key","insert_secret_here")
+                .map( "bucket_location","insert_bucket_location_here");
+        Map<String, Object> propertiesPayload = hashMap("storage_provider",(Object)"s3").map("storage_info",storageinfo);
+        Map<String, Object> payload = hashMap( "path", (Object)"test-organization/test-app/user"
);
+        payload.put( "properties", propertiesPayload );
+        //.map( "properties",propertiesPayload);
+
+        try {
+            resource().path( "/management/export" ).accept( MediaType.APPLICATION_JSON )
+                      .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class , payload
);
+        }
+        catch ( UniformInterfaceException uie ) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( Status.OK, responseStatus );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e941ca7/stack/services/src/main/java/org/usergrid/management/export/ExportServiceDos.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/export/ExportServiceDos.java
b/stack/services/src/main/java/org/usergrid/management/export/ExportServiceDos.java
index db96944..4669fd7 100644
--- a/stack/services/src/main/java/org/usergrid/management/export/ExportServiceDos.java
+++ b/stack/services/src/main/java/org/usergrid/management/export/ExportServiceDos.java
@@ -1,5 +1,6 @@
 package org.usergrid.management.export;
 
+
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -14,6 +15,9 @@ import org.codehaus.jackson.JsonFactory;
 import org.codehaus.jackson.JsonGenerator;
 import org.codehaus.jackson.impl.DefaultPrettyPrinter;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.usergrid.batch.service.SchedulerService;
 import org.usergrid.management.ExportInfo;
 import org.usergrid.management.ManagementService;
@@ -24,13 +28,9 @@ import org.usergrid.persistence.EntityManagerFactory;
 import org.usergrid.persistence.Query;
 import org.usergrid.persistence.Results;
 import org.usergrid.persistence.cassandra.CassandraService;
-import org.usergrid.utils.JsonUtils;
 
 import com.google.common.collect.BiMap;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 
 /**
  *
@@ -40,17 +40,21 @@ public class ExportServiceDos implements ExportService{
 
     //dependency injection
     //inject scheduler - needs to be auto wired
+    @Autowired
     private SchedulerService sch;
     //inject the entity manager - needs to be auto wired
+    @Autowired
     private EntityManager em;
 
     //injected the Entity Manager Factory
     protected EntityManagerFactory emf;
 
     //inject properties for organization properties
+    @Autowired
     private Properties properties;
 
     //inject Management Service to access Organization Data
+    @Autowired
     private ManagementService managementService;
 
     //ORG uuid .
@@ -61,6 +65,12 @@ public class ExportServiceDos implements ExportService{
 
     private JsonFactory jsonFactory = new JsonFactory();
 
+    private String outputDir = "~/";
+
+    protected long startTime = System.currentTimeMillis();
+
+    protected static final String PATH_REPLACEMENT = "USERGIRD-PATH-BACKSLASH";
+
     //TODO: Todd, do I refactor most of the methods out to just leave schedule and doExport
much like
     //the exporting toolbase class?
 
@@ -78,10 +88,10 @@ public class ExportServiceDos implements ExportService{
         Map<UUID, String> organizations = getOrgs();
         for ( Map.Entry<UUID, String> organization : organizations.entrySet() ) {
 
-            if ( organization.equals( properties.getProperty( "usergrid.test-account.organization"
) ) ) {
-                // Skip test data from being exported.
-                continue;
-            }
+//            if ( organization.equals( properties.getProperty( "usergrid.test-account.organization"
) ) ) {
+//                // Skip test data from being exported.
+//                continue;
+//            }
 
             exportApplicationsForOrg( organization );
         }
@@ -262,10 +272,10 @@ public class ExportServiceDos implements ExportService{
         }
 
         // Write connections
-        saveConnections( entity, em, jg );
+        //saveConnections( entity, em, jg );
 
         // Write dictionaries
-        saveDictionaries( entity, em, jg );
+        //saveDictionaries( entity, em, jg );
 
         // End the object if it was Started
         jg.writeEndObject();
@@ -284,4 +294,34 @@ public class ExportServiceDos implements ExportService{
         return jg;
     }
 
+    protected File createOutputFile( String type, String name ) {
+        return new File( outputDir, prepareOutputFileName( type, name ) );
+    }
+
+
+    /**
+     * @param type just a label such us: organization, application.
+     *
+     * @return the file name concatenated with the type and the name of the collection
+     */
+    protected String prepareOutputFileName( String type, String name ) {
+        name = name.replace( "/", PATH_REPLACEMENT );
+        // Add application and timestamp
+        StringBuilder str = new StringBuilder();
+        // str.append(baseOutputFileName);
+        // str.append(".");
+        str.append( type );
+        str.append( "." );
+        str.append( name );
+        str.append( "." );
+        str.append( startTime );
+        str.append( ".json" );
+
+        String outputFileName = str.toString();
+
+        //logger.info( "Creating output filename:" + outputFileName );
+
+        return outputFileName;
+    }
+
 }


Mime
View raw message