Wednesday, December 27, 2017

Cloud Info

@Controller
public class IndexController {

private static final Logger logger = LoggerFactory.getLogger(IndexController.class);


@Autowired (required=false) Cloud cloud;

/**
* Gets basic environment information.  This is the application's
* default action.
* @param model The model for this action.
* @return The path to the view.
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(Model model) throws Exception {

Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy h:mm a");
String serverTime = dateFormat.format(date);
model.addAttribute("serverTime", serverTime);

String port = System.getenv("PORT");
model.addAttribute("port", port);

String vcapServices = System.getenv("VCAP_SERVICES");
model.addAttribute("vcapServices", vcapServices);

if (cloud == null ){
model.addAttribute("isCloudEnvironment",false);
} else {
model.addAttribute("isCloudEnvironment",true);
model.addAttribute("vcapApplication", cloud.getApplicationInstanceInfo().getProperties());
logger.info("VCAP_SERVICES [{}] ", vcapServices);
logger.info("VCAP_APPLICATION [{}] ", System.getenv("VCAP_APPLICATION"));
}

logger.info("Current date and time = [{}], port = [{}].", serverTime, port);

return "index";
}


@RequestMapping(value = "/environment", method = RequestMethod.GET)
public String environment(Model model) throws Exception {

// Dump the environment variables to the page. 
// The TreeMap produces alphabetical order:
model.addAttribute(
"environmentVariables",
new TreeMap<String,String>(System.getenv()));

return "env";
}

/**
* Action to initiate shutdown of the system.  In CF, the application
* <em>should</em>f restart.  In other environments, the application
* runtime will be shut down.
*/
@RequestMapping(value = "/kill", method = RequestMethod.GET)
public void kill() {

logger.warn("*** The system is shutting down. ***");
System.exit(-1);

}

}

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...