This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from jpkrohling/HAWKULAR-556-JDR-Case-Opening
HAWKULAR-556 - Attach Hawkular's JDR to case.
- Loading branch information
Showing
15 changed files
with
588 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
and other contributors as indicated by the @author tags. | ||
Licensed 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.hawkular</groupId> | ||
<artifactId>hawkular</artifactId> | ||
<version>1.0.0.Alpha5-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>hawkular-redhat-access-integration-backend</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<description>Red Hat Access Portal Backend components, including JDR support</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-jaxrs</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.redhat.gss</groupId> | ||
<artifactId>redhat-support-lib-java</artifactId> | ||
<version>1.0.4.jbossorg-1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss</groupId> | ||
<artifactId>jboss-dmr</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.msc</groupId> | ||
<artifactId>jboss-msc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wildfly.core</groupId> | ||
<artifactId>wildfly-controller-client</artifactId> | ||
<version>1.0.0.Final</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<name>Hawkular: Red Hat Access Portal Backend</name> | ||
|
||
<build> | ||
<finalName>hawkular-redhat-access-integration-backend</finalName> | ||
</build> | ||
|
||
</project> |
95 changes: 95 additions & 0 deletions
95
...n-backend/src/main/java/org/hawkular/accesportal/backend/boundary/AttachmentEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed 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.hawkular.accesportal.backend.boundary; | ||
|
||
import java.io.File; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.hawkular.accesportal.backend.control.JDRLocalReport; | ||
import org.hawkular.accesportal.backend.control.RedHatAccessConfiguration; | ||
import org.hawkular.accesportal.backend.entity.SelectedFileForUpload; | ||
|
||
import com.redhat.gss.redhat_support_lib.api.API; | ||
|
||
/** | ||
* @author Juraci Paixão Kröhling | ||
*/ | ||
@Path("/attachments") | ||
public class AttachmentEndpoint { | ||
private static final String SERVER_REPORT = "Hawkular Server JDR Report"; | ||
|
||
@Inject | ||
RedHatAccessConfiguration configuration; | ||
|
||
@GET | ||
@Consumes({MediaType.APPLICATION_JSON}) | ||
@Produces({MediaType.TEXT_PLAIN}) | ||
public Response getAvailableAttachments() { | ||
// for now, the only possible option is Hawkular's own JDR report. | ||
return Response.ok(SERVER_REPORT + "?checked=true\n").build(); | ||
} | ||
|
||
@POST | ||
@Consumes({MediaType.APPLICATION_JSON}) | ||
@Produces({MediaType.APPLICATION_JSON}) | ||
public Response uploadFilesToCase(SelectedFileForUpload selectedFileForUpload) throws Exception { | ||
API api = new API( | ||
selectedFileForUpload.getUsername(), | ||
selectedFileForUpload.getPassword(), | ||
configuration.getUrl(), | ||
configuration.getProxyUser(), | ||
configuration.getProxyPassword(), | ||
configuration.getProxyUrl(), | ||
configuration.getProxyPort(), | ||
configuration.getUserAgent(), | ||
configuration.isDevel() | ||
); | ||
|
||
// tests the connectivity first... if it breaks here, we don't even need to generate the JDR (which is | ||
// expensive). | ||
api.getProblems().diagnoseStr("test"); | ||
|
||
if (SERVER_REPORT.equalsIgnoreCase(selectedFileForUpload.getAttachment())) { | ||
String report = new JDRLocalReport().getReportLocation(); | ||
|
||
try { | ||
api.getAttachments().add( | ||
selectedFileForUpload.getCaseNum(), // to which case should we attach this report? | ||
true, // public visibility | ||
report, // the location of the report on the local file system | ||
selectedFileForUpload.getAttachment() // the name of the report | ||
); | ||
} catch (Exception e) { | ||
// we cannot recover from this | ||
e.printStackTrace(); | ||
} | ||
|
||
boolean deleted = new File(report).delete(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ration-backend/src/main/java/org/hawkular/accesportal/backend/control/JDRLocalReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed 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.hawkular.accesportal.backend.control; | ||
|
||
import java.net.UnknownHostException; | ||
|
||
import org.jboss.as.controller.client.ModelControllerClient; | ||
import org.jboss.dmr.ModelNode; | ||
|
||
/** | ||
* @author Juraci Paixão Kröhling | ||
*/ | ||
public class JDRLocalReport { | ||
final ModelControllerClient client; | ||
|
||
public JDRLocalReport() throws UnknownHostException { | ||
String host = System.getProperty("jboss.bind.address.management", "127.0.0.1"); | ||
int port = Integer.parseInt(System.getProperty("jboss.management.native.port", "9990")); | ||
client = ModelControllerClient.Factory.create(host, port); | ||
} | ||
|
||
public String getReportLocation() throws Exception { | ||
ModelNode op = new ModelNode(); | ||
ModelNode address = op.get("address").setEmptyList(); | ||
address.add("subsystem", "jdr"); | ||
op.get("operation").set("generate-jdr-report"); | ||
ModelNode result = client.execute(op); | ||
if (isSuccess(result)) { | ||
return result.get("result").get("report-location").asString(); | ||
} else { | ||
throw new Exception("Failed to generate JDR report " + result.asString()); | ||
} | ||
} | ||
|
||
public static boolean isSuccess(ModelNode operationResult) { | ||
if (operationResult != null) { | ||
return operationResult.hasDefined("outcome") && operationResult.get("outcome").asString().equals("success"); | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.