package com.aws.samples.opensearch.controller; /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.net.InetAddress; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import com.aws.samples.opensearch.model.Customer; import com.aws.samples.opensearch.service.CustomerService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; /** * @author Angel Conde * */ @Controller @Slf4j public class UIController { public UIController() { } @GetMapping("/search") public String home(Model model) { // obtain a hostname. First try to get the host name from docker container (from the "HOSTNAME" environment variable) String hostName = System.getenv("HOSTNAME"); // get the os name String os = System.getProperty("os.name"); // if the application is not running in a docker container, we can to obtain the hostname using the "java.net.InetAddress" class if(hostName == null || hostName.isEmpty()) { try { InetAddress addr = InetAddress.getLocalHost(); hostName = addr.getHostName(); } catch (Exception e) { log.error(e.getLocalizedMessage()); hostName = "Unknow"; } } model.addAttribute("data","Bootful Search app: "+ hostName+" running on: "+ os); return "search"; } }