All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.elephantdrummer.tool.PlatformInformation Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
package com.elephantdrummer.tool;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

import com.elephantdrummer.container.ContainerElement;
import com.elephantdrummer.executor.base.ExecutorBase;
import com.elephantdrummer.model.PtApplication;

/**
 * Copyright 2018 Elephant Software Klaudiusz Wojtkowiak e-mail: [email protected]
 * 
 * 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. 
 */
public class PlatformInformation implements ContainerElement{

	
	private String applicationName="not specified";



	public String getApplicationName() {
		return applicationName;
	}

	public void setApplicationName(String applicationName) {
		this.applicationName = applicationName;
	}
	

	
//	private @Inject @Any Instance allTriggers;
	private List> allJobs;
//	
//	private @Inject IPtApplicationDao ptplatformdao;
//	private @Inject IPtJobApplicationDao ptJobApplicationdao;
	//private @Inject InternalLogger log;
	private PtApplication ptPlatform;
	
//	@PostConstruct
	public void init(){
		 try {
				InetAddress adr=InetAddress.getLocalHost();
				PtApplication pp=new PtApplication();
				pp.setHost(adr.getHostName());
				pp.setIp(adr.getHostAddress());
				
				String platform=null;
				boolean platformfound=false;
				
				String server_node=System.getProperties().getProperty("jboss.node.name");
				if (server_node==null==false && platformfound==false){
					platform="Red Hat Jboss/WildFly";
					platformfound=true;
				}else{
					server_node=System.getProperties().getProperty("weblogic.Name");
				}
				
				if (platformfound==false){
					if (server_node==null==false ){
						platform="Oracle Weblogic";
						platformfound=true;
					}else{
						server_node=System.getProperties().getProperty("was.node");
					}
				}
				
				if (platformfound==false){
					if (server_node==null==false && platformfound==false){
						platform="IBM WebSphere";
						platformfound=true;
					}else{
						server_node=System.getProperties().getProperty("com.sun.aas.hostName");
					}
				}
				
				if (platformfound==false){
					if (server_node==null==false && platformfound==false){
						platform="Oracle GlassFish";
						platformfound=true;
					}
				}
				
				if (server_node==null==false && platformfound==false){
					platform="Unresolved";
				}
				
				pp.setNodeName(server_node);
				
//				if (applicationInfo==null==false){
//					for (ApplicationInformation info:applicationInfo){
//						pp.setApplicationName(info==null?"not specified":info.getApplicationName());
//					}
//				}
				
				pp.setApplicationName(getApplicationName());
				pp.setPlatform(platform);
				pp.setLibraryVersion(PlatformInformation.class.getPackage().getImplementationVersion());

					
//				FindByPropertyWrapper wrapper=new FindByPropertyWrapper();
//				wrapper.add(IPtApplicationDao.HOST, adr.getHostName());
//				wrapper.add(IPtApplicationDao.APP_NAME, pp.getApplicationName());
//				wrapper.add(IPtApplicationDao.IP, adr.getHostAddress());
//				wrapper.add(IPtApplicationDao.NODE_NAME, pp.getNodeName()==null?"":pp.getNodeName());
//				wrapper.add(IPtApplicationDao.PLATFORM, pp.getPlatform()==null?"":pp.getPlatform());
//				
//				List lp=ptplatformdao.findByWrapper(wrapper);
//				
//				if (lp==null||lp.isEmpty()){
//					ptplatformdao.saveTransactional(pp);
//					setPtPlatform(pp);
//				}else{
//					setPtPlatform(lp.get(0));
//				}
				markPlatformAsAlived();
				
				
		 } catch (UnknownHostException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
		}
		 
		 
	}
	
	

	public PtApplication getPtPlatform() {
		return ptPlatform;
	}

	public void setPtPlatform(PtApplication ptPlatform) {
		this.ptPlatform = ptPlatform;
	}
	
	public void markPlatformAsAlived(){
//		PtApplication pp=getPtPlatform();
//		
//		pp=ptplatformdao.findById(pp.getId());
//		if (Boolean.TRUE.equals(pp.getChangeOrdered())){
//			log.info("CHANGE_ORDERED!!!!!!!!!!");
//			List pttaskapp=ptJobApplicationdao.findByProperty("ptApplicationId", pp.getPtApplicationId());
//			if (pttaskapp==null==false){
//				for (PtJobApplication ptta:pttaskapp){
//					ExecutorBase task=getJobById(ptta.getPtJobId());
//					if (ptta.getForcedTriggerStep()==null==false&&ptta.getForcedTriggerStep().longValue()>0){
//						task.getTrigger().setStep(ptta.getForcedTriggerStep().longValue());
//					}
//				}
//			}
//		}
//		pp.setChangeOrdered(Boolean.FALSE);
//		pp.setHeartbeatDate(new Date());
//		pp.setLibraryVersion(this.getClass().getPackage().getImplementationVersion());
//		ptplatformdao.updateTransactional(pp);
	}

	public List> getAllJobs() {
		return allJobs;
	}

	public void setAllJobs(List> allJobs) {
		this.allJobs = allJobs;
	}

	
//	private ExecutorBase getJobById(BigDecimal taskId){
//		if (taskId==null) return null;
//		for (ExecutorBase task:allJobs){
//			if (taskId.equals(task.getPtJob().getPtJobId())){
//				return task;
//			}
//		}
//		return null;
//	}




	


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy