Add Admin Logging

This commit is contained in:
Nicolas Héron 2018-10-12 13:35:39 +02:00
commit e117f24d8d
7 changed files with 79 additions and 7 deletions

View file

@ -54,6 +54,11 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-push</artifactId>
<version>7.7.6</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>

View file

@ -13,6 +13,7 @@ import org.springframework.context.annotation.PropertySource;
@Configuration @Configuration
@SpringBootApplication @SpringBootApplication
//@ComponentScan({"com.assurfleet.front.courtier.petiteflotte.maj","com.assurfleet.jms.services"}) //@ComponentScan({"com.assurfleet.front.courtier.petiteflotte.maj","com.assurfleet.jms.services"})
@PropertySource("classpath:application.properties") @PropertySource("classpath:application.properties")
@ImportResource("classpath:applicationContext.xml") @ImportResource("classpath:applicationContext.xml")

View file

@ -0,0 +1,38 @@
package org.chtijbug.drools.console;
import com.vaadin.ui.PopupView;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
public class WorkOnGoingView extends PopupView {
private Table table;
public WorkOnGoingView() {
super("Logging", new VerticalLayout());
//this.
VerticalLayout verticalLayout = (VerticalLayout) this.getContent().getPopupComponent();
this.table = new Table("Logging");
table = new Table();
table.setSizeFull();
table.setPageLength(0);
table.setSelectable(false);
table.setColumnCollapsingAllowed(false);
table.setColumnReorderingAllowed(false);
table.setImmediate(true);
table.setNullSelectionAllowed(false);
table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
table.addContainerProperty("Message", String.class, null);
verticalLayout.addComponent(table);
}
public void addRow(String textToAdd) {
String[] cells = new String[1];
cells[0] = textToAdd;
table.addItem(cells, "Message");
}
}

View file

@ -2,6 +2,7 @@ package org.chtijbug.drools.console.service;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.chtijbug.drools.console.DroolsAdminConsole;
import org.chtijbug.drools.console.service.model.kie.JobStatus; import org.chtijbug.drools.console.service.model.kie.JobStatus;
import org.chtijbug.drools.console.service.model.kie.Space; import org.chtijbug.drools.console.service.model.kie.Space;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -52,7 +53,7 @@ public class KieRepositoryService {
return reponseMoteur; return reponseMoteur;
} }
public JobStatus buildProject(String url, String username, String password, String space, String project, String command) { public JobStatus buildProject(String url, String username, String password, String space, String project, String command, DroolsAdminConsole workOnGoingView) {
String completeurl = url + "/spaces/" + space + "/projects/" + project + "/maven/" + command; String completeurl = url + "/spaces/" + space + "/projects/" + project + "/maven/" + command;
logger.info("url Maven install : " + completeurl); logger.info("url Maven install : " + completeurl);
ResponseEntity<JobStatus> response = restTemplateKiewb ResponseEntity<JobStatus> response = restTemplateKiewb
@ -70,6 +71,7 @@ public class KieRepositoryService {
JobStatus reponseMoteur; JobStatus reponseMoteur;
reponseMoteur = response.getBody(); reponseMoteur = response.getBody();
workOnGoingView.addRow(reponseMoteur.toString());
return reponseMoteur; return reponseMoteur;
} }
@ -114,7 +116,7 @@ public class KieRepositoryService {
}; };
} }
public String waitForJobToBeEnded(String url, String username, String password, String jobID) { public String waitForJobToBeEnded(String url, String username, String password, String jobID, DroolsAdminConsole workOnGoingView) {
String isJobDone = "NO"; String isJobDone = "NO";
while ("NO".equals(isJobDone)) { while ("NO".equals(isJobDone)) {
JobStatus jobStatus = this.getStatusJobID(url, JobStatus jobStatus = this.getStatusJobID(url,
@ -123,11 +125,11 @@ public class KieRepositoryService {
if ("DUPLICATE_RESOURCE".equals(jobStatus.getStatus()) if ("DUPLICATE_RESOURCE".equals(jobStatus.getStatus())
|| "SUCCESS".equals(jobStatus.getStatus())) { || "SUCCESS".equals(jobStatus.getStatus())) {
isJobDone = "YES"; isJobDone = "YES";
System.out.println("JonId=" + jobID + " finished"); workOnGoingView.addRow("JobID=" + jobID + " finished");
} else if ("ACCEPTED".equals(jobStatus.getStatus()) } else if ("ACCEPTED".equals(jobStatus.getStatus())
|| ("APPROVED".equals(jobStatus.getStatus()))) { || ("APPROVED".equals(jobStatus.getStatus()))) {
try { try {
System.out.println("JonId=" + jobID + " not yet finished"); workOnGoingView.addRow("JobID=" + jobID + " not yet finished");
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -3,6 +3,7 @@ package org.chtijbug.drools.console.service;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.chtijbug.drools.console.DroolsAdminConsole;
import org.chtijbug.drools.console.service.model.kie.KieContainerInfo; import org.chtijbug.drools.console.service.model.kie.KieContainerInfo;
import org.chtijbug.drools.console.service.model.kie.KieContainerRequest; import org.chtijbug.drools.console.service.model.kie.KieContainerRequest;
import org.chtijbug.drools.console.service.model.kie.KieServerJobStatus; import org.chtijbug.drools.console.service.model.kie.KieServerJobStatus;
@ -74,7 +75,7 @@ public class KieServerRepositoryService {
return results; return results;
} }
public KieServerJobStatus stopContainer(String url, String username, String password, String containerId) { public KieServerJobStatus stopContainer(String url, String username, String password, String containerId, DroolsAdminConsole workOnGoingView) {
KieServerJobStatus results = null; KieServerJobStatus results = null;
String completeurl = url + "/containers/" + containerId; String completeurl = url + "/containers/" + containerId;
logger.info("url kie server container : " + completeurl); logger.info("url kie server container : " + completeurl);
@ -92,10 +93,11 @@ public class KieServerRepositoryService {
}); });
KieServerJobStatus reponseMoteur; KieServerJobStatus reponseMoteur;
reponseMoteur = response.getBody(); reponseMoteur = response.getBody();
workOnGoingView.addRow(reponseMoteur.toString());
return reponseMoteur; return reponseMoteur;
} }
public KieContainerInfo createContainer(String url, String username, String password, String containerId, KieContainerRequest request) { public KieContainerInfo createContainer(String url, String username, String password, String containerId, KieContainerRequest request, DroolsAdminConsole workOnGoingView) {
String completeurl = url + "/containers/" + containerId; String completeurl = url + "/containers/" + containerId;
logger.info("url kie server container : " + completeurl); logger.info("url kie server container : " + completeurl);
ResponseEntity<Map<String, Object>> response = restTemplateKiewb ResponseEntity<Map<String, Object>> response = restTemplateKiewb
@ -117,7 +119,7 @@ public class KieServerRepositoryService {
Map<String, Object> reponseMoteur; Map<String, Object> reponseMoteur;
reponseMoteur = response.getBody(); reponseMoteur = response.getBody();
workOnGoingView.addRow(reponseMoteur.toString());
KieContainerInfo result = new KieContainerInfo(); KieContainerInfo result = new KieContainerInfo();
return result; return result;
} }

View file

@ -1,5 +1,6 @@
package org.chtijbug.drools.console.service.model.kie; package org.chtijbug.drools.console.service.model.kie;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
public class JobStatus { public class JobStatus {
@ -11,6 +12,19 @@ public class JobStatus {
private Date lastModified; private Date lastModified;
private String detailedResult[]; private String detailedResult[];
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("JobStatus{");
sb.append("status='").append(status).append('\'');
sb.append(", jobId='").append(jobId).append('\'');
sb.append(", spaceName='").append(spaceName).append('\'');
sb.append(", projectName='").append(projectName).append('\'');
sb.append(", result='").append(result).append('\'');
sb.append(", lastModified=").append(lastModified);
sb.append(", detailedResult=").append(detailedResult == null ? "null" : Arrays.asList(detailedResult).toString());
sb.append('}');
return sb.toString();
}
public String getStatus() { public String getStatus() {
return status; return status;

View file

@ -28,4 +28,14 @@ public class KieServerJobStatus {
public void setResult(String result) { public void setResult(String result) {
this.result = result; this.result = result;
} }
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("KieServerJobStatus{");
sb.append("type='").append(type).append('\'');
sb.append(", msg='").append(msg).append('\'');
sb.append(", result='").append(result).append('\'');
sb.append('}');
return sb.toString();
}
} }