001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.microservice.management;
018
019import org.apache.juneau.marshall.collections.*;
020import org.apache.juneau.rest.server.*;
021import org.apache.juneau.rest.server.servlet.*;
022
023/**
024 * Child-resource flavor of the {@code /info} endpoint.
025 *
026 * <p>
027 * Mounts as a routed child via {@link Rest#children() @Rest(children=InfoResource.class)} under the subtree
028 * {@code /info} and delegates to a shared {@link InfoManager} worker &mdash; the same logic the
029 * {@link InfoMixin mixin} flavor uses, so the two forms cannot drift.  Extends {@link BasicRestResource} so
030 * the returned bean serializes via the {@code BasicUniversalConfig} set (mirrors {@code HealthResource}).
031 *
032 * <h5 class='section'>See Also:</h5><ul>
033 *    <li class='jc'>{@link InfoMixin}
034 *    <li class='jc'>{@link InfoManager}
035 * </ul>
036 *
037 * @since 10.0.0
038 */
039@Rest(path="/info")
040public class InfoResource extends BasicRestResource {
041
042   private final InfoManager manager = new InfoManager();
043
044   /**
045    * [GET /] - Application build/version/git metadata from the manifest.
046    *
047    * @param req The HTTP request.
048    * @return The manifest main attributes as a sorted map (empty when no manifest is registered).
049    */
050   @RestGet(
051      path="/*",
052      summary="Application info",
053      description="Renders the running application's manifest main attributes (build/version/git metadata)."
054   )
055   public JsonMap getInfo(RestRequest req) {
056      return manager.getInfo(manager.resolveManifest(req.getContext()));
057   }
058}