2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.babel.service;
23 import java.time.Clock;
24 import java.time.LocalDateTime;
25 import java.time.LocalTime;
26 import java.time.format.DateTimeFormatter;
27 import java.time.temporal.ChronoUnit;
28 import java.time.temporal.Temporal;
29 import javax.ws.rs.DefaultValue;
30 import javax.ws.rs.GET;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.Produces;
33 import javax.ws.rs.QueryParam;
34 import org.springframework.stereotype.Service;
37 * Information service for the micro-service. Return status details to the caller.
41 @Path("/core/core-service")
43 public class InfoService {
45 private Clock clock = Clock.systemDefaultZone();
46 private LocalDateTime startTime = LocalDateTime.now(clock);
47 private long infoCount = 0L;
50 * @param format is an optional setting - html requests an HTML format
51 * @return a formatted status report
55 @Produces("text/plain")
56 public String getInfo(@DefaultValue("text") @QueryParam("format") String format) {
57 return "Status: Up\n" + statusReport(clock) + "\n";
60 /** @return a status report showing the up time for the service */
61 public String statusReport(Clock clock) {
62 Temporal reportTime = LocalDateTime.now(clock);
63 long upTime = ChronoUnit.SECONDS.between(startTime, reportTime);
64 long upTimeDays = ChronoUnit.DAYS.between(startTime, reportTime);
66 StringBuilder sb = new StringBuilder("Started at ");
67 sb.append(startTime).append('\n').append("Up time ");
69 sb.append(upTimeDays).append(" day");
75 sb.append(LocalTime.MIDNIGHT.plusSeconds(upTime).format(DateTimeFormatter.ofPattern("HH:mm:ss"))).append('\n');
77 sb.append('\n').append("Info Service").append('\n');
78 sb.append("total=").append(++infoCount).append('\n');