Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWKMETRICS-683] Initial work for the vert.x conversion using the fra…
…mework from Hawkular Commons.
- Loading branch information
Stefan Negrea
committed
Aug 3, 2017
1 parent
69eeb41
commit 85f1659
Showing
5 changed files
with
216 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/MetricsApp.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,48 @@ | ||
/* | ||
* Copyright 2014-2017 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.metrics.api; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
import org.hawkular.commons.log.MsgLogger; | ||
import org.hawkular.commons.log.MsgLogging; | ||
import org.hawkular.commons.properties.HawkularProperties; | ||
import org.hawkular.handlers.BaseApplication; | ||
|
||
public class MetricsApp implements BaseApplication { | ||
private static final MsgLogger log = MsgLogging.getMsgLogger(MetricsApp.class); | ||
private static final String BASE_URL = "hawkular-merics.base-url"; | ||
private static final String BASE_URL_DEFAULT = "/hawkular/metrics"; | ||
|
||
ExecutorService executor; | ||
String baseUrl = HawkularProperties.getProperty(BASE_URL, BASE_URL_DEFAULT); | ||
|
||
@Override | ||
public void start() { | ||
log.infof("Metrics app started on [ %s ] ", baseUrl()); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
log.infof("Metrics app stopped", baseUrl()); | ||
} | ||
|
||
@Override | ||
public String baseUrl() { | ||
return baseUrl; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/handler/PingHandler.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,51 @@ | ||
/* | ||
* Copyright 2014-2017 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.metrics.api.handler; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
import org.hawkular.handlers.RestEndpoint; | ||
import org.hawkular.handlers.RestHandler; | ||
import org.hawkular.metrics.api.JsonUtil; | ||
import org.hawkular.metrics.api.jaxrs.util.StringValue; | ||
|
||
import io.swagger.annotations.ApiOperation; | ||
import io.vertx.ext.web.Router; | ||
import io.vertx.ext.web.RoutingContext; | ||
import io.vertx.rx.java.ObservableHandler; | ||
import io.vertx.rx.java.RxHelper; | ||
|
||
/** | ||
* @author Stefan Negrea | ||
*/ | ||
@RestEndpoint(path = "/ping") | ||
public class PingHandler implements RestHandler { | ||
|
||
@Override | ||
public void initRoutes(String baseUrl, Router router) { | ||
router.get(baseUrl + "/ping").handler(ping().toHandler()); | ||
} | ||
|
||
@ApiOperation(value = "Returns the current time and serves to check for the availability of the api.", response = | ||
Map.class) | ||
public ObservableHandler<RoutingContext> ping() { | ||
ObservableHandler<RoutingContext> oh = RxHelper.observableHandler(true); | ||
oh.subscribe(ctx -> ctx.response().end(JsonUtil.toJson(new StringValue(new Date().toString())))); | ||
return oh; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
api/metrics-api-jaxrs/src/main/resources/hawkular.properties
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,19 @@ | ||
# | ||
# Copyright 2014-2017 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. | ||
# | ||
|
||
# Internal configuration registration, used to provide default values | ||
test = 1 |
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