ServiceComponentDesiredStateEntityPK pkHS = new ServiceComponentDesiredStateEntityPK();
pkHS.setComponentName("HISTORYSERVER");
pkHS.setClusterId(clusterEntity.getClusterId());
pkHS.setServiceName("MAPREDUCE");
ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntityHS = serviceComponentDesiredStateDAO.findByPK(pkHS);
// already have historyserver
if(serviceComponentDesiredStateEntityHS != null)
continue;
ServiceComponentDesiredStateEntityPK pkJT = new ServiceComponentDesiredStateEntityPK();
pkJT.setComponentName("JOBTRACKER");
pkJT.setClusterId(clusterEntity.getClusterId());
pkJT.setServiceName("MAPREDUCE");
ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntityJT = serviceComponentDesiredStateDAO.findByPK(pkJT);
// no jobtracker present probably mapreduce is not installed
if(serviceComponentDesiredStateEntityJT == null)
continue;
HostComponentStateEntity jtHostComponentStateEntity = serviceComponentDesiredStateEntityJT.getHostComponentStateEntities().iterator().next();
HostComponentDesiredStateEntity jtHostComponentDesiredStateEntity = serviceComponentDesiredStateEntityJT.getHostComponentDesiredStateEntities().iterator().next();
String jtHostname = jtHostComponentStateEntity.getHostName();
State jtCurrState = jtHostComponentStateEntity.getCurrentState();
State jtHostComponentDesiredState = jtHostComponentDesiredStateEntity.getDesiredState();
State jtServiceComponentDesiredState = serviceComponentDesiredStateEntityJT.getDesiredState();
ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
pk.setClusterId(clusterEntity.getClusterId());
pk.setServiceName("MAPREDUCE");
ClusterServiceEntity clusterServiceEntity = clusterServiceDAO.findByPK(pk);
final ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = new ServiceComponentDesiredStateEntity();
serviceComponentDesiredStateEntity.setComponentName("HISTORYSERVER");
serviceComponentDesiredStateEntity.setDesiredStackVersion(clusterEntity.getDesiredStackVersion());
serviceComponentDesiredStateEntity.setDesiredState(jtServiceComponentDesiredState);
serviceComponentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
serviceComponentDesiredStateEntity.setHostComponentDesiredStateEntities(new ArrayList<HostComponentDesiredStateEntity>());
final HostComponentStateEntity stateEntity = new HostComponentStateEntity();
stateEntity.setHostName(jtHostname);
stateEntity.setCurrentState(jtCurrState);
stateEntity.setCurrentStackVersion(clusterEntity.getDesiredStackVersion());