Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #429 from jpkrohling/HAWKULAR-556-JDR-Case-Opening
Browse files Browse the repository at this point in the history
HAWKULAR-556 - Attach Hawkular's JDR to case.
  • Loading branch information
mtho11 committed Sep 3, 2015
2 parents 874b704 + 9039d42 commit 50335ca
Show file tree
Hide file tree
Showing 15 changed files with 588 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var attachmentsRequest = 'hawkular-redhat-access-integration-backend/attachments';

angular.module('RedhatAccess.JON', ['RedhatAccess.cases'])
.controller('customCase', ['$scope', 'securityService', 'NEW_DEFAULTS', '$location', '$http', function($scope, securityService, NEW_DEFAULTS , $location, $http) {
NEW_DEFAULTS.product = "Red Hat JBoss Operations Network";
NEW_DEFAULTS.version = "3.3.0";

var params = $location.search();

// handle support case for managed resource
if ($location.path().indexOf('/resource-case') >= 0) {
NEW_DEFAULTS.product = params.product;
Expand All @@ -16,3 +18,19 @@ angular.module('RedhatAccess.JON', ['RedhatAccess.cases'])
securityService.validateLogin(true);
};
}]);

angular.module('RedhatAccess.cases')
.controller('BackEndAttachmentsCtrl', ['$scope', 'TreeViewSelectorData', 'AttachmentsService',
function ($scope, TreeViewSelectorData, AttachmentsService) {
$scope.name = 'Attachments';
$scope.attachmentTree = [];
TreeViewSelectorData.getTree(attachmentsRequest).then(
function (tree) {
$scope.attachmentTree = tree;
AttachmentsService.updateBackEndAttachments(tree);
},
function () {
console.log('Unable to get tree data');
});
}
]);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! redhat_access_angular_ui - v0.9.85 - 2015-08-03
* Copyright (c) 2015 ;
* Licensed
* Licensed
*/
angular.module('gettext').run(['gettextCatalog', function (gettextCatalog) {
/* jshint -W100 */
Expand Down Expand Up @@ -2263,7 +2263,7 @@ angular.module('RedhatAccess.cases').controller('AddCommentSection', [
AlertService.addStrataErrorMessage(error);
});
}

};
var onError = function (error) {
AlertService.addStrataErrorMessage(error);
Expand Down Expand Up @@ -2971,7 +2971,7 @@ angular.module('RedhatAccess.cases').controller('DefaultGroup', [
$scope.usersLoaded = false;
$scope.usersAndGroupsFinishedLoading = false;
$scope.userCanManageDefaultGroups = true;

$scope.init = function() {
if(securityService.userAllowedToManageDefaultGroups()){
$scope.groupsLoading = true;
Expand Down Expand Up @@ -3031,7 +3031,7 @@ angular.module('RedhatAccess.cases').controller('DefaultGroup', [
};

$scope.setDefaultGroup = function () {
//Remove old group is_default
//Remove old group is_default
var tmpGroup = {
name: $scope.selectedGroup.name,
number: $scope.selectedGroup.number,
Expand Down Expand Up @@ -3522,7 +3522,7 @@ angular.module('RedhatAccess.cases').controller('EditGroup', [
$scope.accountNumber = null;
$scope.isUsersPrestine = true;
$scope.isGroupPrestine = true;

var reloadTable = false;
var tableBuilt = false;
var buildTable = function () {
Expand Down Expand Up @@ -3607,7 +3607,7 @@ angular.module('RedhatAccess.cases').controller('EditGroup', [
}
$scope.isUsersPrestine = false;
};

$scope.onMasterWriteCheckboxClicked = function (masterWriteSelected) {
for(var i = 0; i < $scope.usersOnAccount.length; i++){
if (!$scope.usersOnAccount[i].org_admin) {
Expand Down Expand Up @@ -4073,7 +4073,7 @@ angular.module('RedhatAccess.cases').controller('List', [
CaseService.clearCase();
SearchCaseService.clear();
});

$scope.$on('$destroy', function () {
$scope.doSearchDeregister();
$scope.listAuthEventDeregister();
Expand Down Expand Up @@ -5160,7 +5160,7 @@ angular.module('RedhatAccess.cases').directive('rhaCasecomments', ['$location','
text = '\n' + text;
}
$('#case-comment-box').val($('#case-comment-box').val()+text).keyup();

//Copying the code from the link to comment method
var old = $location.hash();
$location.hash('case-comment-box');
Expand Down Expand Up @@ -5581,7 +5581,7 @@ angular.module('RedhatAccess.cases').service('AttachmentsService', [
caseNum: caseId
};
var deferred = $q.defer();
$http.post('attachments', jsonData).success(function (data, status, headers, config) {
$http.post('hawkular-redhat-access-integration-backend/attachments', jsonData).success(function (data, status, headers, config) {
deferred.resolve(data);
AlertService.addSuccessMessage(translate('Successfully uploaded attachment') + ' ' + jsonData.attachment + ' ' + translate('to case') + ' ' + caseId);
}).error(function (data, status, headers, config) {
Expand Down Expand Up @@ -6987,7 +6987,7 @@ angular.module('RedhatAccess.cases').controller('EscalationRequest', [
$scope.ESCALATION_TYPE = ESCALATION_TYPE;
$scope.partnerGeoList = ['NA','EMEA','LATAM','APAC'];
$scope.iceGeoList = ['NA','EMEA','LATAM','APAC','Combo'];

$scope.submitEscalationRequest = function(escalationType) {
var recordType = '';
var emailCheck = true;
Expand Down Expand Up @@ -7059,7 +7059,7 @@ angular.module('RedhatAccess.cases').service('EscalationRequestService', [
'securityService',
'translate',
function (strataService, AlertService, RHAUtils, ESCALATION_TYPE, securityService, translate) {

this.accountNumber = '';
this.caseNumber = '';
this.alreadyEscalated = false;
Expand Down
1 change: 1 addition & 0 deletions dist/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<include>org.hawkular.bus:hawkular-feed-comm-war</include>
<include>org.hawkular:hawkular-pinger</include>
<include>org.hawkular:hawkular-avail-creator</include>
<include>org.hawkular:hawkular-redhat-access-integration-backend</include>
<include>org.hawkular.accounts:hawkular-accounts:war</include>
<include>org.hawkular.alerts:hawkular-alerts-rest:war</include>
<include>org.hawkular.alerts:hawkular-alerts-actions-email:war</include>
Expand Down
6 changes: 6 additions & 0 deletions dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
<artifactId>hawkular-accounts-events-backend</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>org.hawkular</groupId>
<artifactId>hawkular-redhat-access-integration-backend</artifactId>
<version>1.0.0.Alpha5-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions dist/src/main/resources/wildfly/patches/standalone.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,16 @@
<xsl:value-of select="$uuid.hawkular.accounts.backend"/>
</credential>
</secure-deployment>
<secure-deployment name="hawkular-redhat-access-integration-backend.war">
<realm>hawkular</realm>
<resource>hawkular-accounts-backend</resource>
<use-resource-role-mappings>true</use-resource-role-mappings>
<enable-cors>true</enable-cors>
<enable-basic-auth>true</enable-basic-auth>
<credential name="secret">
<xsl:value-of select="$uuid.hawkular.accounts.backend"/>
</credential>
</secure-deployment>
</subsystem>
</xsl:copy>
</xsl:template>
Expand Down
73 changes: 73 additions & 0 deletions modules/redhat-access-integration-backend/pom.xml
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>
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;
}

}
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;
}
}

0 comments on commit 50335ca

Please sign in to comment.