Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordonald.g.dunne2017-06-20 19:09:05 -0400
committerDonald Dunne2017-08-04 12:22:28 -0400
commit9f2b95a0b66999a77378febbf33e64ce620089a0 (patch)
tree5ef384101985ddadbead0c2b6ce17d227bc6ba5e
parentfefa2bb820b3a4dd11d59280dea1d329bc905630 (diff)
downloadorg.eclipse.osee-9f2b95a0b66999a77378febbf33e64ce620089a0.tar.gz
org.eclipse.osee-9f2b95a0b66999a77378febbf33e64ce620089a0.tar.xz
org.eclipse.osee-9f2b95a0b66999a77378febbf33e64ce620089a0.zip
feature: Add ATS Health Checks to server
-rw-r--r--plugins/org.eclipse.osee.ats.api/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java2
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/IAtsStoreService.java2
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/HealthCheckResults.java87
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheck.java32
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheckProvider.java21
-rw-r--r--plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java4
-rw-r--r--plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsStoreService.java10
-rw-r--r--plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.mail.ref.xml5
-rw-r--r--plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.provider.service.xml5
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/IAtsServer.java2
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java2
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java2
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java5
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckOperation.java219
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckProviderService.java34
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/HealthResource.java57
-rw-r--r--plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/health/ValidateResults.java1
18 files changed, 485 insertions, 6 deletions
diff --git a/plugins/org.eclipse.osee.ats.api/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ats.api/META-INF/MANIFEST.MF
index 98972b1b9f..a17a6b3ecc 100644
--- a/plugins/org.eclipse.osee.ats.api/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.ats.api/META-INF/MANIFEST.MF
@@ -25,6 +25,7 @@ Export-Package: org.eclipse.osee.ats.api,
org.eclipse.osee.ats.api.team,
org.eclipse.osee.ats.api.user,
org.eclipse.osee.ats.api.util,
+ org.eclipse.osee.ats.api.util.health,
org.eclipse.osee.ats.api.version,
org.eclipse.osee.ats.api.workdef,
org.eclipse.osee.ats.api.workdef.model,
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java
index 4f8efd28ad..f49fcd6a33 100644
--- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/IAtsServices.java
@@ -176,7 +176,7 @@ public interface IAtsServices extends IAtsEarnedValueServiceProvider, IAtsConfig
void sendNotifications(AtsNotificationCollector notifications);
- Collection<ArtifactToken> getArtifacts(List<Long> ids);
+ Collection<ArtifactToken> getArtifacts(Collection<Long> ids);
IAgileService getAgileService();
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/IAtsStoreService.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/IAtsStoreService.java
index 3ad3826912..40b3e9f390 100644
--- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/IAtsStoreService.java
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/IAtsStoreService.java
@@ -78,4 +78,6 @@ public interface IAtsStoreService {
Result setTransactionAssociatedArtifact(TransactionId trans, IAtsTeamWorkflow teamWf);
+ boolean isDeleted(ArtifactId artifact);
+
}
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/HealthCheckResults.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/HealthCheckResults.java
new file mode 100644
index 0000000000..c676bda24a
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/HealthCheckResults.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.api.util.health;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.ArtifactId;
+import org.eclipse.osee.framework.core.util.result.XResultData;
+import org.eclipse.osee.framework.jdk.core.type.CountingMap;
+import org.eclipse.osee.framework.jdk.core.type.HashCollection;
+import org.eclipse.osee.framework.jdk.core.type.MutableInteger;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class HealthCheckResults {
+
+ private final CountingMap<String> testNameToTimeSpentMap = new CountingMap<>();
+ private final HashCollection<String, String> testNameToResultsMap = new HashCollection<>(50);
+ private final HashCollection<String, String> testNameToIdMap = new HashCollection<>(50);
+
+ public void logTestTimeSpent(Date date, String testName) {
+ Date now = new Date();
+ int spent = new Long(now.getTime() - date.getTime()).intValue();
+ testNameToTimeSpentMap.put(testName, spent);
+ }
+
+ public void log(ArtifactId artifact, String testName, String message) {
+ if (artifact != null) {
+ testNameToIdMap.put(testName, artifact.getIdString());
+ }
+ log(testName, message);
+ }
+
+ public void log(String testName, String message) {
+ testNameToResultsMap.put(testName, message);
+ }
+
+ public void addResultsMapToResultData(XResultData xResultData) {
+ String[] keys = testNameToResultsMap.keySet().toArray(new String[testNameToResultsMap.keySet().size()]);
+ Arrays.sort(keys);
+ for (String testName : keys) {
+ xResultData.log(testName);
+ for (String result : testNameToResultsMap.getValues(testName)) {
+ xResultData.log(" - " + result);
+ }
+ // uniqueize guids
+ Set<String> idStrs = new HashSet<>();
+ Collection<String> values = testNameToIdMap.getValues(testName);
+ if (values != null) {
+ idStrs.addAll(values);
+ }
+ xResultData.log(testName + "IDs: " + Collections.toString(",", idStrs) + "\n");
+ }
+ }
+
+ public void addTestTimeMapToResultData(XResultData xResultData) {
+ xResultData.log("\n\nTime Spent in Tests");
+ long totalTime = 0;
+ for (Entry<String, MutableInteger> entry : testNameToTimeSpentMap.getCounts()) {
+ xResultData.log(
+ " " + entry.getKey() + " - " + (entry.getValue().getValue() / 1000) + " sec " + " - " + entry.getValue() + " ms");
+ totalTime += entry.getValue().getValue();
+ }
+ xResultData.log("TOTAL - " + (totalTime / 1000) + " sec " + totalTime + " ms");
+
+ xResultData.log("\n");
+ }
+
+ public HashCollection<String, String> getTestNameToResultsMap() {
+ return testNameToResultsMap;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheck.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheck.java
new file mode 100644
index 0000000000..64e88d641a
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheck.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.api.util.health;
+
+import org.eclipse.osee.ats.api.IAtsServices;
+import org.eclipse.osee.ats.api.IAtsWorkItem;
+import org.eclipse.osee.framework.core.data.ArtifactId;
+
+/**
+ * @author Donald G. Dunne
+ */
+public interface IAtsHealthCheck {
+
+ public void check(ArtifactId artifact, IAtsWorkItem workItem, HealthCheckResults results, IAtsServices services);
+
+ public default String getName() {
+ return getClass().getSimpleName();
+ }
+
+ public default void error(HealthCheckResults results, IAtsWorkItem workItem, String format, Object... data) {
+ results.log(workItem.getStoreObject(), getClass().getSimpleName(),
+ String.format("Error: " + format + " for " + workItem.getAtsId(), data));
+ }
+}
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheckProvider.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheckProvider.java
new file mode 100644
index 0000000000..60982be88a
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/util/health/IAtsHealthCheckProvider.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.api.util.health;
+
+import java.util.List;
+
+/**
+ * @author Donald G. Dunne
+ */
+public interface IAtsHealthCheckProvider {
+
+ List<IAtsHealthCheck> getHealthChecks();
+}
diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java
index 477c295fac..94f5fe71fc 100644
--- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java
+++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsClientImpl.java
@@ -134,7 +134,7 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient {
logFactory = AtsCoreFactory.newLogFactory();
stateFactory = AtsCoreFactory.newStateFactory(getServices(), logFactory);
- storeService = new AtsStoreService(workItemFactory, getUserServiceClient(), jdbcService);
+ storeService = new AtsStoreService(this, workItemFactory, getUserServiceClient(), jdbcService);
queryService = new AtsQueryServiceImpl(this, jdbcService);
actionableItemManager = new ActionableItemManager(attributeResolverService, storeService, this);
@@ -518,7 +518,7 @@ public class AtsClientImpl extends AtsCoreServiceImpl implements IAtsClient {
}
@Override
- public Collection<ArtifactToken> getArtifacts(List<Long> ids) {
+ public Collection<ArtifactToken> getArtifacts(Collection<Long> ids) {
List<ArtifactId> artifactIds = new ArrayList<>(ids.size());
for (Long id : ids) {
artifactIds.add(ArtifactId.valueOf(id));
diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsStoreService.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsStoreService.java
index 051b0ed4ac..c75648254e 100644
--- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsStoreService.java
+++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/internal/AtsStoreService.java
@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.osee.ats.api.IAtsObject;
+import org.eclipse.osee.ats.api.IAtsServices;
import org.eclipse.osee.ats.api.IAtsWorkItem;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
import org.eclipse.osee.ats.api.team.IAtsWorkItemFactory;
@@ -52,8 +53,10 @@ public class AtsStoreService implements IAtsStoreService {
private final IAtsWorkItemFactory workItemFactory;
private final IAtsUserService userService;
private final JdbcService jdbcService;
+ private final IAtsServices services;
- public AtsStoreService(IAtsWorkItemFactory workItemFactory, IAtsUserService userService, JdbcService jdbcService) {
+ public AtsStoreService(IAtsServices services, IAtsWorkItemFactory workItemFactory, IAtsUserService userService, JdbcService jdbcService) {
+ this.services = services;
this.workItemFactory = workItemFactory;
this.userService = userService;
this.jdbcService = jdbcService;
@@ -208,4 +211,9 @@ public class AtsStoreService implements IAtsStoreService {
throw new UnsupportedOperationException();
}
+ @Override
+ public boolean isDeleted(ArtifactId artifact) {
+ return ((Artifact) services.getArtifact(artifact)).isDeleted();
+ }
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.mail.ref.xml b/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.mail.ref.xml
new file mode 100644
index 0000000000..51ac3b74c0
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.mail.ref.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+ <implementation class="org.eclipse.osee.ats.rest.internal.util.health.HealthResource"/>
+ <reference bind="setMailService" cardinality="1..1" interface="org.eclipse.osee.mail.api.MailService" name="MailService" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.provider.service.xml b/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.provider.service.xml
new file mode 100644
index 0000000000..78eb06a427
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/OSGI-INF/ats.health.check.provider.service.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+ <implementation class="org.eclipse.osee.ats.rest.internal.util.health.AtsHealthCheckProviderService"/>
+ <reference bind="addHealthCheckProvider" cardinality="1..1" interface="org.eclipse.osee.ats.api.util.health.IAtsHealthCheckProvider" name="IAtsHealthCheckProvider" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/IAtsServer.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/IAtsServer.java
index 084be48e73..39d7afe946 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/IAtsServer.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/IAtsServer.java
@@ -55,7 +55,7 @@ public interface IAtsServer extends IAtsServices, IAtsNotifier, IAtsConfigItemFa
ArtifactReadable getArtifact(Long uuid);
@Override
- Collection<ArtifactToken> getArtifacts(List<Long> uuids);
+ Collection<ArtifactToken> getArtifacts(Collection<Long> uuids);
void addAtsDatabaseConversion(IAtsDatabaseConversion conversion);
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java
index a30cce4709..e17b99a380 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsApplication.java
@@ -36,6 +36,7 @@ import org.eclipse.osee.ats.rest.internal.config.VersionResource;
import org.eclipse.osee.ats.rest.internal.cpa.CpaResource;
import org.eclipse.osee.ats.rest.internal.cpa.CpaServiceRegistry;
import org.eclipse.osee.ats.rest.internal.notify.AtsNotifyEndpointImpl;
+import org.eclipse.osee.ats.rest.internal.util.health.HealthResource;
import org.eclipse.osee.ats.rest.internal.workitem.ActionUiResource;
import org.eclipse.osee.ats.rest.internal.workitem.AtsActionEndpointImpl;
import org.eclipse.osee.ats.rest.internal.workitem.AtsRuleEndpointImpl;
@@ -111,6 +112,7 @@ public class AtsApplication extends Application {
singletons.add(new CpaResource(orcsApi, atsServer, cpaRegistry));
singletons.add(new UserResource(atsServer.getUserService()));
singletons.add(new WorldResource(atsServer));
+ singletons.add(new HealthResource(atsServer, jdbcService));
// Endpoints
singletons.add(new AgileEndpointImpl(atsServer, registry, jdbcService));
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java
index 28554a4eb6..bc1f4669c1 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/AtsServerImpl.java
@@ -235,7 +235,7 @@ public class AtsServerImpl extends AtsCoreServiceImpl implements IAtsServer {
}
@Override
- public Collection<ArtifactToken> getArtifacts(List<Long> uuids) {
+ public Collection<ArtifactToken> getArtifacts(Collection<Long> uuids) {
Collection<ArtifactToken> artifacts = new LinkedList<>();
Iterator<ArtifactReadable> iterator =
orcsApi.getQueryFactory().fromBranch(getAtsBranch()).andUuids(uuids).getResults().iterator();
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java
index 8626390129..f5c407238e 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsStoreServiceImpl.java
@@ -201,4 +201,9 @@ public class AtsStoreServiceImpl implements IAtsStoreService {
return Result.TrueResult;
}
+ @Override
+ public boolean isDeleted(ArtifactId artifact) {
+ return atsServer.getArtifact(artifact).isDeleted();
+ }
+
}
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckOperation.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckOperation.java
new file mode 100644
index 0000000000..1fbd21b963
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckOperation.java
@@ -0,0 +1,219 @@
+package org.eclipse.osee.ats.rest.internal.util.health;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.osee.ats.api.IAtsServices;
+import org.eclipse.osee.ats.api.IAtsWorkItem;
+import org.eclipse.osee.ats.api.data.AtsRelationTypes;
+import org.eclipse.osee.ats.api.util.health.HealthCheckResults;
+import org.eclipse.osee.ats.api.util.health.IAtsHealthCheck;
+import org.eclipse.osee.ats.api.util.health.IAtsHealthCheckProvider;
+import org.eclipse.osee.ats.api.version.IAtsVersion;
+import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow;
+import org.eclipse.osee.framework.core.data.ArtifactId;
+import org.eclipse.osee.framework.core.data.ArtifactToken;
+import org.eclipse.osee.framework.core.util.result.XResultData;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.AHTML;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.eclipse.osee.framework.jdk.core.util.DateUtil;
+import org.eclipse.osee.framework.jdk.core.util.ElapsedTime;
+import org.eclipse.osee.framework.jdk.core.util.ElapsedTime.Units;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.jdbc.JdbcStatement;
+import org.eclipse.osee.mail.api.MailMessage;
+import org.eclipse.osee.mail.api.MailService;
+import org.eclipse.osee.mail.api.MailStatus;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class AtsHealthCheckOperation {
+
+ private static String SELECT_INWORK_WORKFLOWS =
+ "SELECT distinct art.art_id FROM osee_artifact art, osee_txs txs, OSEE_ATTRIBUTE attr " //
+ + "WHERE attr.gamma_id = txs.gamma_id AND txs.tx_current = 1 AND txs.branch_id = 570 and " //
+ + "attr.ART_ID = art.ART_ID and attr.ATTR_TYPE_ID = 1152921504606847147 and attr.VALUE = 'Working'";
+ private final IAtsServices services;
+ private final JdbcService jdbcService;
+ private final MailService mailService;
+ boolean inTest = false;
+ private List<IAtsHealthCheck> healthChecks;
+
+ public AtsHealthCheckOperation(IAtsServices services, JdbcService jdbcService, MailService mailService) {
+ this.services = services;
+ this.jdbcService = jdbcService;
+ this.mailService = mailService;
+ }
+
+ public XResultData run() {
+ XResultData rd = new XResultData();
+ try {
+ ElapsedTime time = new ElapsedTime("ATS Health Check");
+ runIt(rd);
+ String elapsedStr = time.end(Units.SEC);
+ rd.log("\n\n" + elapsedStr);
+ time.end();
+ emailResults(rd);
+ } catch (Exception ex) {
+ rd.errorf("Exception running reports [%s]", Lib.exceptionToString(ex));
+ }
+ return rd;
+ }
+
+ private void emailResults(XResultData rd) {
+ if (mailService != null) {
+ MailMessage msg = MailMessage.newBuilder() //
+ .from("noop@osee.com") //
+ .recipients(Arrays.asList("donald.g.dunne@boeing.com")) //
+ .subject("ATS Health Check") //
+ .addHtml(AHTML.simplePage(rd.toString().replaceAll("\n", "</br>")))//
+ .build();
+
+ List<MailStatus> sendMessages = mailService.sendMessages(msg);
+ System.out.println(sendMessages);
+ }
+ }
+
+ public void runIt(XResultData rd) throws OseeCoreException {
+ SevereLoggingMonitor monitorLog = new SevereLoggingMonitor();
+ OseeLog.registerLoggerListener(monitorLog);
+
+ int count = 0;
+ HealthCheckResults vResults = new HealthCheckResults();
+ if (inTest) {
+ vResults.log("testMap1", "blah blah");
+ vResults.log("testMap2", "blah blah");
+ vResults.log("testMap1", "blah blah");
+ vResults.log("testMap3", "blah blah");
+ } else {
+ List<IAtsHealthCheck> checks = getHealthChecks();
+
+ // Break artifacts into blocks so don't run out of memory
+ List<Collection<Long>> artIdLists = loadWorkingWorkItemIds(rd);
+ int numblocks = artIdLists.size();
+ int x = 1;
+ for (Collection<Long> artIdList : artIdLists) {
+
+ System.err.println(String.format("processing %s / %s", x++, numblocks));
+ Collection<ArtifactToken> allArtifacts = services.getArtifacts(artIdList);
+
+ // remove all deleted/purged artifacts first
+ List<ArtifactId> artifacts = new ArrayList<>(allArtifacts.size());
+ for (ArtifactId artifact : allArtifacts) {
+ if (!services.getStoreService().isDeleted(artifact)) {
+ artifacts.add(artifact);
+ }
+ }
+ count += artifacts.size();
+
+ for (ArtifactId artifact : artifacts) {
+ for (IAtsHealthCheck check : checks) {
+ if (services.getStoreService().isDeleted(artifact)) {
+ continue;
+ }
+ IAtsWorkItem workItem = services.getWorkItemFactory().getWorkItem((ArtifactToken) artifact);
+ Date date = new Date();
+ try {
+ check.check(artifact, workItem, vResults, services);
+ } catch (Exception ex) {
+ vResults.log(artifact, check.getName(), "Error: Exception: " + Lib.exceptionToString(ex));
+ }
+ vResults.logTestTimeSpent(date, check.getName());
+ }
+ }
+ System.gc();
+ }
+ }
+ // Log resultMap data into xResultData
+ vResults.addResultsMapToResultData(rd);
+ vResults.addTestTimeMapToResultData(rd);
+
+ rd.logf("Completed processing %s work items.", count);
+ }
+
+ private List<IAtsHealthCheck> getHealthChecks() {
+ if (healthChecks == null) {
+ healthChecks = new LinkedList<>();
+ healthChecks.add(new TestWorkflowTeamDefinition());
+ healthChecks.add(new TestWorkflowVersions());
+ for (IAtsHealthCheckProvider provider : AtsHealthCheckProviderService.getHealthCheckProviders()) {
+ healthChecks.addAll(provider.getHealthChecks());
+ }
+ }
+ return healthChecks;
+ }
+
+ private static class TestWorkflowTeamDefinition implements IAtsHealthCheck {
+
+ @Override
+ public void check(ArtifactId artifact, IAtsWorkItem workItem, HealthCheckResults results, IAtsServices services) {
+ if (workItem.isTeamWorkflow()) {
+ if (workItem.getParentTeamWorkflow().getTeamDefinition() == null) {
+ error(results, workItem, "Team workflow has no Team Definition (re-run conversion?)");
+ }
+ }
+ }
+ }
+
+ private static class TestWorkflowVersions implements IAtsHealthCheck {
+
+ @Override
+ public void check(ArtifactId artifact, IAtsWorkItem workItem, HealthCheckResults results, IAtsServices services) {
+ if (workItem.isTeamWorkflow()) {
+ IAtsTeamWorkflow teamWf = workItem.getParentTeamWorkflow();
+ Collection<ArtifactToken> versions = services.getRelationResolver().getRelated(teamWf,
+ AtsRelationTypes.TeamWorkflowTargetedForVersion_Version);
+ if (versions.size() > 1) {
+ error(results, workItem, "Team workflow has " + versions.size() + " versions; should only be 0 or 1");
+ } else {
+ IAtsVersion version = services.getVersionService().getTargetedVersion(teamWf);
+ if (version != null && teamWf.getTeamDefinition() != null && teamWf.getTeamDefinition().getTeamDefinitionHoldingVersions() != null) {
+ if (!teamWf.getTeamDefinition().getTeamDefinitionHoldingVersions().getVersions().contains(version)) {
+ error(results, workItem,
+ "Team workflow " + teamWf.getAtsId() + " has version" + version.toStringWithId() + " that does not belong to teamDefHoldingVersions ");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private List<Collection<Long>> loadWorkingWorkItemIds(XResultData rd) throws OseeCoreException {
+ rd.log("testLoadAllCommonArtifactIds - Started " + DateUtil.getMMDDYYHHMM());
+ List<Long> artIds = getCommonArtifactIds(rd);
+ if (artIds.isEmpty()) {
+ rd.error("Error: Artifact load returned 0 artifacts to check");
+ }
+ rd.log("testLoadAllCommonArtifactIds - Completed " + DateUtil.getMMDDYYHHMM());
+ return Collections.subDivide(artIds, 4000);
+ }
+
+ private List<Long> getCommonArtifactIds(XResultData rd) throws OseeCoreException {
+ List<Long> artIds = new ArrayList<>();
+ // For single or re-runs of subset
+ // artIds.addAll(Arrays.asList(8381138L, 600305128L, 9115994L, 8003310L, 8646243L, 8660113L, 9036993L, 8646249L));
+ // OR
+ // Load all inwork workflows
+ rd.log("getCommonArtifactIds - Started " + DateUtil.getMMDDYYHHMM());
+ JdbcStatement chStmt = jdbcService.getClient().getStatement();
+ try {
+ chStmt.runPreparedQuery(SELECT_INWORK_WORKFLOWS);
+ while (chStmt.next()) {
+ artIds.add(Long.valueOf(chStmt.getInt(1)));
+ }
+ } finally {
+ chStmt.close();
+ rd.log("getCommonArtifactIds - Completed " + DateUtil.getMMDDYYHHMM());
+ }
+ return artIds;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckProviderService.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckProviderService.java
new file mode 100644
index 0000000000..d730c084dd
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/AtsHealthCheckProviderService.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.rest.internal.util.health;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.osee.ats.api.util.health.IAtsHealthCheckProvider;
+
+/**
+ * ATS Health Service to collect health checks to be run on server
+ *
+ * @author Donald G. Dunne
+ */
+public class AtsHealthCheckProviderService {
+
+ public static List<IAtsHealthCheckProvider> healthCheckProviders = new LinkedList<>();
+
+ public void addHealthCheckProvider(IAtsHealthCheckProvider healthCheck) {
+ healthCheckProviders.add(healthCheck);
+ }
+
+ public static List<IAtsHealthCheckProvider> getHealthCheckProviders() {
+ return healthCheckProviders;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/HealthResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/HealthResource.java
new file mode 100644
index 0000000000..e148e4f942
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/health/HealthResource.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.rest.internal.util.health;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.eclipse.osee.ats.api.IAtsServices;
+import org.eclipse.osee.framework.core.util.result.XResultData;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.mail.api.MailService;
+
+/**
+ * @author Donald G. Dunne
+ */
+@Path("health")
+public final class HealthResource {
+
+ private IAtsServices services;
+ private JdbcService jdbcService;
+ private static MailService mailService;
+
+ public void setMailService(MailService mailService) {
+ HealthResource.mailService = mailService;
+ }
+
+ public HealthResource() {
+ // for osgi instantiation; this optionally sets the mail service if available
+ }
+
+ public HealthResource(IAtsServices services, JdbcService jdbcService) {
+ this.services = services;
+ this.jdbcService = jdbcService;
+ }
+
+ /**
+ * @return html representation of ATS Health Checks
+ */
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public Response get() throws Exception {
+ AtsHealthCheckOperation validate = new AtsHealthCheckOperation(services, jdbcService, mailService);
+ XResultData rd = validate.run();
+ return Response.ok(rd.toString().replaceAll("\n", "</br>")).build();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/health/ValidateResults.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/health/ValidateResults.java
index 41ed5a0903..85a18af118 100644
--- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/health/ValidateResults.java
+++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/health/ValidateResults.java
@@ -38,6 +38,7 @@ public class ValidateResults {
testNameToGuidMap.put(testName, artifact.getGuid());
}
log(testName, message);
+ System.err.println(testName + " - " + message);
}
public void log(String testName, String message) {

Back to the top