Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Microprofile BOM/POM #41

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2017-2017 Contributors to the Eclipse Foundation
// Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand Down
18 changes: 13 additions & 5 deletions microprofile-sample-canonical/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**********************************************************************
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICES file(s) distributed with this work for additional
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -29,7 +29,7 @@
<parent>
<groupId>org.eclipse.microprofile.sample</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</parent>

<artifactId>canonical</artifactId>
Expand All @@ -42,10 +42,11 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<!-- JAVA EE -->
<!-- BOM -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<type>pom</type>
</dependency>
<!-- TEST -->
<dependency>
Expand All @@ -70,6 +71,13 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.eclipse.microprofile.health</groupId>
<artifactId>microprofile-health-api</artifactId>
<version>1.0</version>
</dependency>
-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.eclipse.microprofile.sample.canonical.rest;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.sample.canonical.utils.QLogger;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Logger;

@Path("/health")
@RequestScoped
public class HealthEndpoint {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you want this either according to what @Emily-Jiang wrote, but rather just provide an @Health method as e.g. shown in https://github.com/pilhuhn/microprofile-demo/blob/master/src/main/java/de/bsd/microprofiledemo/rest/HealthDemo.java#L29-L37

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above example looks vendor-neutral as opposed to what @Emily-Jiang suggested sounded a bit more like abandoning a vendor-neutral Eclipse example altogether in favor of examples by OpenLiberty, Wildfly, Kumuluz, etc. ?;-O


@Inject
@QLogger
private Logger logger;

@GET
@Produces(MediaType.APPLICATION_JSON)
public String getHealthStatus() {
final String NAME = "CDs";
HealthCheckResponse response;
final List<Integer> randomCDs = getRandomNumbers();
if (randomCDs.size() > 0) {
response = HealthCheckResponse.named(NAME).up().build();
} else {
response = HealthCheckResponse.named(NAME).down().build();
}
return response.toString();
}

private List<Integer> getRandomNumbers() {
final List<Integer> randomCDs = new ArrayList<>();
final Random r = new Random();
for (int i=0; i < r.nextInt(); i++) {
randomCDs.add(i + 1101);
}

logger.info("Top CDs are " + randomCDs);

return randomCDs;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*
* Copyright (C) 2016, 2017 Antonio Goncalves and others.
* Copyright (c) 2016, 2017 Contributors to the Eclipse Foundation
*
* 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
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*
* Copyright (C) 2016, 2017 Antonio Goncalves and others.
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* 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
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.eclipse.microprofile.sample.canonical.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
import org.eclipse.microprofile.health.spi.HealthCheckResponseProvider;

/**
* @author Werner Keil
*/
public class CanonicalHealthCheckResponseProvider implements HealthCheckResponseProvider{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the app does not implement the spi but use application server's implementation, e.g. Open Liberty etc. Application should only provide the HealthCheckResponse. One of the benefits of MP programming model is to make app development a lot easier.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@Override
public HealthCheckResponseBuilder createResponseBuilder() {
return new ResponseBuilder();
}

private static class ResponseBuilder extends HealthCheckResponseBuilder {
private String name;
private boolean state;
private Map<String, Object> data = new ConcurrentHashMap<>();

@Override
public HealthCheckResponseBuilder name(String name) {
this.name = name;
return this;
}

@Override
public HealthCheckResponseBuilder withData(String key, String value) {
data.put(key, value);
return this;
}

@Override
public HealthCheckResponseBuilder withData(String key, long value) {
data.put(key, value);
return this;
}

@Override
public HealthCheckResponseBuilder withData(String key, boolean value) {
data.put(key, value);
return this;
}

@Override
public HealthCheckResponseBuilder up() {
return state(true);
}

@Override
public HealthCheckResponseBuilder down() {
return state(false);
}

@Override
public HealthCheckResponseBuilder state(boolean up) {
this.state = up;
return this;
}

@Override
public HealthCheckResponse build() {
return new Response(this.name, this.state, this.data);
}

private class Response extends HealthCheckResponse {
private final String name;
private final boolean up;
private final Map<String, Object> data;

public Response(String name, boolean up, Map<String, Object> map) {
this.name = name;
this.up = up;
this.data = setData(map);
}

@Override
public String toString() {
return "Response [" + name + "=" + getState() +
(data!= null ? ", data=" + data : "") + "]";
}

private Map<String,Object> setData(Map<String, Object> map) {
if (map.isEmpty()) {
return null;
}
Map<String, Object> data = new HashMap<>();
for (String key : map.keySet()) {
final Object modelValue = map.get(key);
final Object value;
if (modelValue instanceof Long) {
value = ((Long)modelValue).longValue();
} else {
value = modelValue;
}
data.put(key, value);
}
return data;
}

@Override
public String getName() {
return name;
}

@Override
public State getState() {
return up ? State.UP : State.DOWN;
}

@Override
public Optional<Map<String, Object>> getData() {
return Optional.ofNullable(data);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.microprofile.sample.canonical.utils.CanonicalHealthCheckResponseProvider
46 changes: 20 additions & 26 deletions microprofile-sample-swagger/pom.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**********************************************************************
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICES file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/
-->
<!-- /**********************************************************************
* Copyright (c) 2017 Contributors to the Eclipse Foundation
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
* 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.
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/ -->
<project 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"
xmlns="http://maven.apache.org/POM/4.0.0">
Expand All @@ -29,7 +22,7 @@
<parent>
<groupId>org.eclipse.microprofile.sample</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</parent>

<artifactId>swagger</artifactId>
Expand All @@ -42,10 +35,11 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<!-- JAVA EE -->
<!-- BOM -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<type>pom</type>
</dependency>
<!-- OTHERS -->
<dependency>
Expand Down
Loading