usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [46/50] [abbrv] git commit: adding status mojo to maven chop plugin
Date Mon, 07 Jul 2014 18:17:03 GMT
adding status mojo to maven chop plugin


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

Branch: refs/heads/two-dot-o
Commit: be554bf7695cf6ad6a6fac7ab28d25ecd4c06da2
Parents: 5ff3c1e
Author: Salih Kardan <kardan38@gmail.com>
Authored: Tue Jul 1 11:17:33 2014 +0300
Committer: Salih Kardan <kardan38@gmail.com>
Committed: Tue Jul 1 11:17:33 2014 +0300

----------------------------------------------------------------------
 .../apache/usergrid/chop/plugin/StatusMojo.java | 99 ++++++++++++++++++++
 .../webapp/coordinator/rest/StatusResource.java | 91 ++++++++++++++++++
 2 files changed, 190 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/be554bf7/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/StatusMojo.java
----------------------------------------------------------------------
diff --git a/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/StatusMojo.java b/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/StatusMojo.java
new file mode 100644
index 0000000..a4a2176
--- /dev/null
+++ b/chop/plugin/src/main/java/org/apache/usergrid/chop/plugin/StatusMojo.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.usergrid.chop.plugin;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Mojo;
+
+import org.apache.usergrid.chop.api.Project;
+import org.apache.usergrid.chop.api.RestParams;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+
+/** Hits the coordinator endpoint to get current state */
+@Mojo ( name = "status" )
+public class StatusMojo extends MainMojo {
+
+    @Override
+    public void execute() throws MojoExecutionException {
+        initCertStore();
+
+        /** First check that the runner.jar is ready and up-to-date */
+        if ( ! isReadyToDeploy() ) {
+            throw new MojoExecutionException( "Runner file was not ready, quitting." );
+        }
+
+        Properties props = new Properties();
+        try {
+            File extractedConfigPropFile = new File( getExtractedRunnerPath(), PROJECT_FILE
);
+            FileInputStream inputStream = new FileInputStream( extractedConfigPropFile );
+            props.load( inputStream );
+            inputStream.close();
+        }
+        catch ( Exception e ) {
+            LOG.error( "Error while reading project.properties in runner.jar", e );
+            throw new MojoExecutionException( e.getMessage() );
+        }
+
+        /** Status  */
+        DefaultClientConfig clientConfig = new DefaultClientConfig();
+        Client client = Client.create( clientConfig );
+        WebResource resource = client.resource( endpoint ).path( "/status" );
+
+        LOG.info( "Commit ID: {}", props.getProperty( Project.GIT_UUID_KEY ) );
+        LOG.info( "Artifact Id: {}", props.getProperty( Project.ARTIFACT_ID_KEY ) );
+        LOG.info( "Group Id: {}", props.getProperty( Project.GROUP_ID_KEY ) );
+        LOG.info( "Version: {}", props.getProperty( Project.PROJECT_VERSION_KEY ) );
+        LOG.info( "Username: {}", username );
+
+
+        ClientResponse resp = resource
+                .queryParam( RestParams.COMMIT_ID, props.getProperty( Project.GIT_UUID_KEY
) )
+                .queryParam( RestParams.MODULE_ARTIFACTID, props.getProperty( Project.ARTIFACT_ID_KEY
) )
+                .queryParam( RestParams.MODULE_GROUPID, props.getProperty( Project.GROUP_ID_KEY
) )
+                .queryParam( RestParams.MODULE_VERSION, props.getProperty( Project.PROJECT_VERSION_KEY
) )
+                .queryParam( RestParams.USERNAME, username )
+                .type( MediaType.APPLICATION_JSON )
+                .accept( MediaType.APPLICATION_JSON )
+                .post( ClientResponse.class );
+
+        if( resp.getStatus() != Response.Status.OK.getStatusCode() &&
+                resp.getStatus() != Response.Status.CREATED.getStatusCode() ) {
+            LOG.error( "Could not get the status from coordinator, HTTP status: {}", resp.getStatus()
);
+            LOG.error( "Error Message: {}", resp.getEntity( String.class ) );
+
+            throw new MojoExecutionException( "Status plugin goal has failed" );
+        }
+
+        LOG.info( "====== Response from the coordinator ======" );
+        LOG.info( resp.getEntity( String.class ) );
+        LOG.info( "===========================================" );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/be554bf7/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StatusResource.java
----------------------------------------------------------------------
diff --git a/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StatusResource.java
b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StatusResource.java
new file mode 100644
index 0000000..bdde58e
--- /dev/null
+++ b/chop/webapp/src/main/java/org/apache/usergrid/chop/webapp/coordinator/rest/StatusResource.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.usergrid.chop.webapp.coordinator.rest;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.usergrid.chop.api.RestParams;
+import org.apache.usergrid.chop.stack.SetupStackState;
+import org.apache.usergrid.chop.webapp.coordinator.StackCoordinator;
+import org.safehaus.jettyjam.utils.TestMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+
+/**
+ * REST operation to get current state.
+ */
+@Singleton
+@Produces( MediaType.APPLICATION_JSON )
+@Path( StatusResource.ENDPOINT)
+public class StatusResource extends TestableResource implements RestParams {
+
+    public final static String ENDPOINT = "/status";
+
+    private static final Logger LOG = LoggerFactory.getLogger( DestroyResource.class );
+
+    @Inject
+    private StackCoordinator stackCoordinator;
+
+    public StatusResource() {
+        super( ENDPOINT );
+    }
+
+
+    @POST
+    @Consumes( MediaType.APPLICATION_JSON )
+    @Produces( MediaType.APPLICATION_JSON )
+    public Response status(
+            @QueryParam( RestParams.COMMIT_ID ) String commitId,
+            @QueryParam( RestParams.MODULE_ARTIFACTID ) String artifactId,
+            @QueryParam( RestParams.MODULE_GROUPID ) String groupId,
+            @QueryParam( RestParams.MODULE_VERSION ) String version,
+            @QueryParam( RestParams.USERNAME ) String user,
+            @Nullable @QueryParam( TestMode.TEST_MODE_PROPERTY ) String testMode
+    ) {
+
+        if( inTestMode( testMode ) ) {
+            LOG.info( "Calling /status in test mode ..." );
+            LOG.info( "  Commit Id: {}", commitId );
+            LOG.info( "  Group Id: {}", groupId );
+            LOG.info( "  Artifact Id: {}", artifactId );
+            LOG.info( "  Version: {}", version );
+            LOG.info( "  User: {}", user );
+        }
+        else {
+            LOG.info( "Calling /status" );
+        }
+
+        SetupStackState status = stackCoordinator.stackStatus( commitId, artifactId, groupId,
version, user );
+
+        return Response.status( Response.Status.CREATED )
+                .entity( "Current state: " + status )
+                .type( MediaType.APPLICATION_JSON )
+                .build();
+    }
+}


Mime
View raw message