Author: adietish
Date: 2011-09-15 13:08:51 -0400 (Thu, 15 Sep 2011)
New Revision: 34773
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/StringResponseUnmarshaller.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationStatusReader.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationStatusResponseUnmarshaller.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java
Log:
[JBIDE-9510] implementing IOpenshiftService#getApplicationStatus and
ApplicationStatusReader
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java 2011-09-15
16:10:00 UTC (rev 34772)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -16,6 +16,7 @@
private String name;
private Cartridge cartridge;
private IOpenshiftService service;
+ private ApplicationLogReader logReader;
public Application(String name, Cartridge cartridge, IOpenshiftService service) {
this.name = name;
@@ -47,7 +48,10 @@
service.stopApplication(name, cartridge);
}
- public ApplicationStatusReader getStatus() throws OpenshiftException {
- return new ApplicationStatusReader(this, service);
+ public ApplicationLogReader getLog() throws OpenshiftException {
+ if (logReader == null) {
+ this.logReader = new ApplicationLogReader(this, service);
+ }
+ return logReader;
}
}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java
(from rev 34765,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationStatusReader.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.openshift.core;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author André Dietisheim
+ */
+public class ApplicationLogReader extends Reader {
+
+ private static final Pattern LOG_REGEX = Pattern.compile("Tail of .+$",
Pattern.MULTILINE);
+
+ private IOpenshiftService service;
+ private StringReader logReader;
+ private Application application;
+ private int logIndex = 0;
+
+ public ApplicationLogReader(Application application, IOpenshiftService service) {
+ this.application = application;
+ this.service = service;
+ }
+
+ @Override
+ public int read(char[] cbuf, int off, int len) throws IOException {
+ int charactersRead = -1;
+ if (logReader == null) {
+ this.logReader = createLogReader(requestStatus());
+ }
+ charactersRead = logReader.read(cbuf, off, len);
+ if (charactersRead != -1) {
+ logIndex += charactersRead;
+ return charactersRead;
+ }
+ this.logReader = null;
+ return -1;
+ }
+
+ protected StringReader createLogReader(String status) throws IOException {
+ String log = getLog(status);
+ return new StringReader(log);
+ }
+
+ private String getLog(String status) throws IOException {
+ Matcher matcher = LOG_REGEX.matcher(status);
+ if (matcher.find()) {
+ logIndex = matcher.end() + 1;
+ }
+ return status.substring(logIndex);
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (logReader != null) {
+ logReader.close();
+ }
+ }
+
+ protected String requestStatus() throws IOException {
+ try {
+ return service.getStatus(application.getName(), application.getCartridge());
+ } catch (OpenshiftException e) {
+ throw new IOException(e);
+ }
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationStatusReader.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationStatusReader.java 2011-09-15
16:10:00 UTC (rev 34772)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationStatusReader.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.as.openshift.core;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-
-/**
- * @author André Dietisheim
- */
-public class ApplicationStatusReader extends Reader {
-
- private IOpenshiftService service;
- private Application application;
- private StringReader serviceResponseReader;
-
- public ApplicationStatusReader(Application application, IOpenshiftService service) {
- this.application = application;
- this.service = service;
- }
-
- protected String requestStatus() throws IOException {
- try {
- return service.getStatus(application.getName(), application.getCartridge());
- } catch (OpenshiftException e) {
- throw new IOException(e);
- }
- }
-
- @Override
- public int read(char[] cbuf, int off, int len) throws IOException {
- int charactersRead = -1;
- for (;;) {
- charactersRead = getServiceResponseReader().read(cbuf, off, len);
- if (charactersRead != -1) {
- return charactersRead;
- }
- }
- }
-
- private Reader getServiceResponseReader() throws IOException {
- if (serviceResponseReader == null) {
- this.serviceResponseReader = new StringReader(requestStatus());
- }
- return serviceResponseReader;
-
- }
-
- @Override
- public void close() throws IOException {
- if (serviceResponseReader != null) {
- serviceResponseReader.close();
- }
- }
-}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-15
16:10:00 UTC (rev 34772)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -31,7 +31,7 @@
public Application stopApplication(String name, Cartridge cartridge) throws
OpenshiftException;
- public String getStatus(String applicationName, Cartridge cartridge) throws
OpenshiftException;
+ public String getStatus(String name, Cartridge cartridge) throws OpenshiftException;
public Domain changeDomain(String domainName, SSHKey sshKey) throws OpenshiftException;
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java 2011-09-15
16:10:00 UTC (rev 34772)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -188,9 +188,9 @@
* ,"app_name","api"],"exit_code":0}
*/
@Override
- public String getStatus(String name, Cartridge cartridge) throws OpenshiftException {
+ public String getStatus(String applicationName, Cartridge cartridge) throws
OpenshiftException {
ApplicationRequest applicationRequest =
- new ApplicationRequest(name, cartridge, ApplicationAction.STATUS, username, true);
+ new ApplicationRequest(applicationName, cartridge, ApplicationAction.STATUS,
username, true);
String url = applicationRequest.getUrlString(BASE_URL);
try {
String applicationRequestString =
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationStatusResponseUnmarshaller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationStatusResponseUnmarshaller.java 2011-09-15
16:10:00 UTC (rev 34772)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationStatusResponseUnmarshaller.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -10,15 +10,10 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.core.internal.response;
-import org.jboss.dmr.ModelNode;
/**
* @author André Dietisheim
*/
-public class ApplicationStatusResponseUnmarshaller extends
AbstractOpenshiftJsonResponseUnmarshaller<String> {
+public class ApplicationStatusResponseUnmarshaller extends StringResponseUnmarshaller {
- @Override
- protected String createFromResultNode(ModelNode node) {
- return node.asString();
- }
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/StringResponseUnmarshaller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/StringResponseUnmarshaller.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/StringResponseUnmarshaller.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.openshift.core.internal.response;
+
+import org.jboss.dmr.ModelNode;
+
+/**
+ * @author André Dietisheim
+ */
+public class StringResponseUnmarshaller extends
AbstractOpenshiftJsonResponseUnmarshaller<String> {
+
+ @Override
+ protected String createFromResultNode(ModelNode node) {
+ return node.asString();
+ }
+
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/StringResponseUnmarshaller.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java 2011-09-15
16:10:00 UTC (rev 34772)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java 2011-09-15
17:08:51 UTC (rev 34773)
@@ -11,9 +11,14 @@
package org.jboss.ide.eclipse.as.openshift.test.internal.core;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URLEncoder;
+import org.jboss.ide.eclipse.as.openshift.core.Application;
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationLogReader;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
@@ -38,20 +43,8 @@
private static final String APPLICATION_NAME = "1316010645406";
private static final Cartridge APPLICATION_CARTRIDGE = Cartridge.JBOSSAS_7;
- private static final String statusResponse =
- "{\"messages\":\"\","
- + "\"debug\":\"\","
- + "\"data\":null,"
- + "\"api\":\"1.1.1\","
- + "\"api_c\":[\"placeholder\"],"
- + "\"result\":\""
- + "tailing /var/lib/libra/664e4d4dbce74c69ac321053149546df/"
- + APPLICATION_NAME
- + "//"
- + APPLICATION_CARTRIDGE
- + "/standalone/log/server.log\n"
- + "------ Tail of 1316010645406 application server.log ------\n"
- + "10:30:38,700 INFO [org.apache.catalina.core.AprLifecycleListener] (MSC
service thread 1-1) "
+ private static final String log =
+ "10:30:38,700 INFO [org.apache.catalina.core.AprLifecycleListener] (MSC service
thread 1-1) "
+ "The Apache Tomcat Native library which allows optimal performance in
production environments was not found on the java.library.path:"
+
"/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64:"
+
"/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib\n"
@@ -63,7 +56,32 @@
+ "10:30:39,339 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3)
Starting deployment of \\\"ROOT.war\\\"\n"
+ "10:30:39,424 INFO [org.jboss.as.jpa] (MSC service thread 1-1) added
javax.persistence.api dependency to ROOT.war\n"
+ "10:30:39,700 INFO [org.jboss.web] (MSC service thread 1-2) registering web
context: \n"
- + "10:30:39,742 INFO [org.jboss.as.server.controller]
(DeploymentScanner-threads - 2) Deployed \\\"ROOT.war\\\"\n"
+ + "10:30:39,742 INFO [org.jboss.as.server.controller]
(DeploymentScanner-threads - 2) Deployed \\\"ROOT.war\\\"\n";
+
+ private static final String tail =
+ "tailing /var/lib/libra/664e4d4dbce74c69ac321053149546df/"
+
+ + APPLICATION_NAME
+
+ + "//"
+
+ + APPLICATION_CARTRIDGE
+
+ + "/standalone/log/server.log\n"
+ + "------ Tail of 1316010645406 application server.log ------\n"
+
+ + log;
+
+ private static final String statusResponse =
+ "{\"messages\":\"\","
+ + "\"debug\":\"\","
+ + "\"data\":null,"
+ + "\"api\":\"1.1.1\","
+ + "\"api_c\":[\"placeholder\"],"
+ + "\"result\":\""
+
+ + tail
+
+ "\","
+ "\"broker\":\"1.1.1\","
+
"\"broker_c\":[\"namespace\",\"rhlogin\",\"ssh\",\"app_uuid\",\"debug\",\"alter\",\"cartridge\",\"cart_type\",\"action\",\"app_name\",\"api\"],"
@@ -120,16 +138,30 @@
OpenshiftResponse<String> openshiftResponse =
new ApplicationStatusResponseUnmarshaller().unmarshall(response);
String status = openshiftResponse.getOpenshiftObject();
+ assertNotNull(status);
+ assertTrue(status.startsWith("tailing "));
}
@Test
- public void canReadFromApplicationStatusReader() {
+ public void applicationLogReaderReturnsAllowsToReadFromStatus() throws IOException {
IOpenshiftService service = new NoopOpenshiftServiceFake() {
@Override
public String getStatus(String applicationName, Cartridge cartridge) throws
OpenshiftException {
- return statusResponse;
+ return tail;
}
};
+
+ Application application = new Application(APPLICATION_NAME, APPLICATION_CARTRIDGE,
service);
+ ApplicationLogReader reader = new ApplicationLogReader(application, service);
+
+ int toMatchIndex = 0;
+ for (int character = -1; (character = reader.read()) != -1;) {
+ assertEquals(
+ "character at position " + toMatchIndex
+ + " was '" + ((char) character) + "'"
+ + " but we expected '" + log.charAt(toMatchIndex) +
"'.",
+ log.charAt(toMatchIndex++), character);
+ }
}
}