Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0da119a
commit 53dafd4
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
hawkular-alerts-rest/src/main/java/org/hawkular/alerts/rest/ManifestUtil.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,67 @@ | ||
/* | ||
* 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.alerts.rest; | ||
|
||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.Manifest; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.servlet.ServletContext; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
/** | ||
* Manifest extraction. | ||
* Credits to Hawkular Metrics team. | ||
* | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
@ApplicationScoped | ||
public class ManifestUtil { | ||
private static final String IMPLEMENTATION_VERSION = "Implementation-Version"; | ||
private static final String BUILT_FROM_GIT = "Built-From-Git-SHA1"; | ||
|
||
private static final List<String> VERSION_ATTRIBUTES = ImmutableList.of(IMPLEMENTATION_VERSION, | ||
BUILT_FROM_GIT); | ||
|
||
private Map<String, String> manifestInformation = new HashMap<>(); | ||
|
||
public Map<String, String> getFrom(ServletContext servletContext) { | ||
if (!manifestInformation.containsKey(IMPLEMENTATION_VERSION) && | ||
!manifestInformation.containsKey(BUILT_FROM_GIT)) { | ||
try (InputStream inputStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF")) { | ||
Manifest manifest = new Manifest(inputStream); | ||
Attributes attr = manifest.getMainAttributes(); | ||
for (String attribute : VERSION_ATTRIBUTES) { | ||
manifestInformation.put(attribute, attr.getValue(attribute)); | ||
} | ||
} catch (Exception e) { | ||
for (String attribute : VERSION_ATTRIBUTES) { | ||
if (manifestInformation.get(attribute) == null) { | ||
manifestInformation.put(attribute, "Unknown"); | ||
} | ||
} | ||
} | ||
} | ||
return manifestInformation; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
hawkular-alerts-rest/src/main/java/org/hawkular/alerts/rest/StatusHandler.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,71 @@ | ||
/* | ||
* 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.alerts.rest; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.ejb.EJB; | ||
import javax.inject.Inject; | ||
import javax.servlet.ServletContext; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.hawkular.alerts.api.services.DefinitionsService; | ||
|
||
import com.wordnik.swagger.annotations.Api; | ||
|
||
/** | ||
* REST endpoint for status | ||
* | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
@Path("/status") | ||
@Api(value = "/status", description = "Status of Alerts Service") | ||
public class StatusHandler { | ||
private static final String STATUS = "status"; | ||
private static final String STARTED = "STARTED"; | ||
private static final String FAILED = "FAILED"; | ||
|
||
@EJB | ||
DefinitionsService definitionsService; | ||
|
||
@Inject | ||
ManifestUtil manifestUtil; | ||
|
||
@GET | ||
@Path("/") | ||
@Produces(APPLICATION_JSON) | ||
public Response status(@Context ServletContext servletContext) { | ||
Map<String, String> status = new HashMap<>(); | ||
status.putAll(manifestUtil.getFrom(servletContext)); | ||
try { | ||
definitionsService.getActionPlugins(); | ||
status.put(STATUS, STARTED); | ||
} catch (Exception e) { | ||
status.put(STATUS, FAILED); | ||
} | ||
return ResponseUtil.ok(status); | ||
} | ||
|
||
} |
53dafd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍