Java tutorial
/* Copyright (C) 2006 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.repository.session; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; import java.util.concurrent.locks.ReentrantReadWriteLock; import javax.persistence.EntityExistsException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.clustercontrol.accesscontrol.bean.PrivilegeConstant.ObjectPrivilegeMode; import com.clustercontrol.bean.SnmpSecurityLevelConstant; import com.clustercontrol.bean.SnmpVersionConstant; import com.clustercontrol.commons.bean.SettingUpdateInfo; import com.clustercontrol.commons.util.EmptyJpaTransactionCallback; import com.clustercontrol.commons.util.HinemosSessionContext; import com.clustercontrol.commons.util.JpaTransactionManager; import com.clustercontrol.fault.FacilityDuplicate; import com.clustercontrol.fault.FacilityNotFound; import com.clustercontrol.fault.HinemosUnknown; import com.clustercontrol.fault.InvalidRole; import com.clustercontrol.fault.InvalidSetting; import com.clustercontrol.fault.ObjectPrivilege_InvalidRole; import com.clustercontrol.fault.SnmpResponseError; import com.clustercontrol.fault.UsedFacility; import com.clustercontrol.hinemosagent.bean.TopicInfo; import com.clustercontrol.hinemosagent.util.AgentConnectUtil; import com.clustercontrol.infra.session.InfraControllerBean; import com.clustercontrol.jobmanagement.session.JobControllerBean; import com.clustercontrol.maintenance.util.HinemosPropertyUtil; import com.clustercontrol.monitor.run.util.NodeMonitorPollerController; import com.clustercontrol.monitor.run.util.NodeToMonitorCacheChangeCallback; import com.clustercontrol.monitor.session.MonitorControllerBean; import com.clustercontrol.nodemap.session.NodeMapControllerBean; import com.clustercontrol.notify.session.NotifyControllerBean; import com.clustercontrol.repository.IRepositoryListener; import com.clustercontrol.repository.bean.AgentStatusInfo; import com.clustercontrol.repository.bean.FacilitySortOrderConstant; import com.clustercontrol.repository.bean.FacilityTreeItem; import com.clustercontrol.repository.bean.NodeInfoDeviceSearch; import com.clustercontrol.repository.bean.RepositoryTableInfo; import com.clustercontrol.repository.entity.CollectorPlatformMstData; import com.clustercontrol.repository.entity.CollectorSubPlatformMstData; import com.clustercontrol.repository.factory.AgentLibDownloader; import com.clustercontrol.repository.factory.FacilityModifier; import com.clustercontrol.repository.factory.FacilitySelector; import com.clustercontrol.repository.factory.NodeProperty; import com.clustercontrol.repository.factory.ScopeProperty; import com.clustercontrol.repository.factory.SearchNodeBySNMP; import com.clustercontrol.repository.model.CollectorPlatformMstEntity; import com.clustercontrol.repository.model.CollectorSubPlatformMstEntity; import com.clustercontrol.repository.model.FacilityInfo; import com.clustercontrol.repository.model.NodeInfo; import com.clustercontrol.repository.model.ScopeInfo; import com.clustercontrol.repository.util.FacilityIdCacheInitCallback; import com.clustercontrol.repository.util.FacilityTreeCache; import com.clustercontrol.repository.util.FacilityTreeCacheRefreshCallback; import com.clustercontrol.repository.util.JobMultiplicityCacheKickCallback; import com.clustercontrol.repository.util.NodeCacheRemoveCallback; import com.clustercontrol.repository.util.NodeCacheUpdateCallback; import com.clustercontrol.repository.util.QueryUtil; import com.clustercontrol.repository.util.RepositoryChangedNotificationCallback; import com.clustercontrol.repository.util.RepositoryListenerCallback; import com.clustercontrol.repository.util.RepositoryListenerCallback.Type; import com.clustercontrol.repository.util.RepositoryValidator; import com.clustercontrol.util.MessageConstant; /** * * ??????? * ??SessionBean<BR> * ?? Entity Bean ????Session Bean ????? * */ public class RepositoryControllerBean { private static Log m_log = LogFactory.getLog(RepositoryControllerBean.class); public static final int ALL = 0; public static final int ONE_LEVEL = 1; private static final List<IRepositoryListener> _listenerList = new ArrayList<IRepositoryListener>(); /** * ID????FacilityEntity ???? * * @param facilityId ID * @return FacilityEntity * @return HinemosUnknown */ public FacilityInfo getFacilityEntityByPK(String facilityId) throws FacilityNotFound, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; FacilityInfo facilityEntity = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ facilityEntity = QueryUtil.getFacilityPK(facilityId); jtm.commit(); } catch (FacilityNotFound | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (Exception e) { m_log.warn("getFacilityEntityByPK() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return facilityEntity; } /** * ID????NodeEntity ???? * * @param facilityId ID * @return facilityEntity * @return InvalidRole * @return HinemosUnknown */ public NodeInfo getNodeEntityByPK(String facilityId) throws FacilityNotFound, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; NodeInfo nodeEntity = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ nodeEntity = QueryUtil.getNodePK(facilityId); jtm.commit(); } catch (FacilityNotFound e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("getNodeEntityByPK() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return nodeEntity; } /** * ?????<BR> * * @param CollectorPlatformMstData ? * @throws EntityExistsException * @throws HinemosUnknown */ public void addCollectorPratformMst(CollectorPlatformMstData data) throws EntityExistsException, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); FacilityModifier.addCollectorPratformMst(data); jtm.commit(); } catch (EntityExistsException e) { if (jtm != null) jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("addCollectorPratformMst() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ?????<BR> * * @param CollectorSubPlatformMstData ? * @throws EntityExistsException * @throws HinemosUnknown */ public void addCollectorSubPlatformMst(CollectorSubPlatformMstData data) throws EntityExistsException, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); FacilityModifier.addCollectorSubPratformMst(data); jtm.commit(); } catch (EntityExistsException e) { if (jtm != null) jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("addCollectorSubPlatformMst() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ??ID?????<BR> * * @param platformId ID * @throws FacilityNotFound * @throws HinemosUnknown */ public void deleteCollectorPratformMst(String platformId) throws FacilityNotFound, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); FacilityModifier.deleteCollectorPratformMst(platformId); jtm.commit(); } catch (FacilityNotFound e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("deleteCollectorPratformMst() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ??ID?????<BR> * * @param subPlatformId ID * @throws FacilityNotFound * @throws HinemosUnknown */ public void deleteCollectorSubPratformMst(String subPlatformId) throws FacilityNotFound, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); FacilityModifier.deleteCollectorSubPratformMst(subPlatformId); jtm.commit(); } catch (FacilityNotFound e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("deleteCollectorSubPratformMst() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ??? * * @return List<CollectorPlatformMstEntity> */ public List<CollectorPlatformMstEntity> getCollectorPlatformMstList() throws HinemosUnknown { JpaTransactionManager jtm = null; List<CollectorPlatformMstEntity> ct = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ ct = QueryUtil.getAllCollectorPlatformMst(); jtm.commit(); } catch (Exception e) { m_log.warn("getCollectorPlatformMstList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return ct; } /** * ??? * * @return List<CollectorSubPlatformMstEntity> */ public List<CollectorSubPlatformMstEntity> getCollectorSubPlatformMstList() throws HinemosUnknown { JpaTransactionManager jtm = null; List<CollectorSubPlatformMstEntity> ct = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ ct = QueryUtil.getAllCollectorSubPlatformMstEntity(); jtm.commit(); } catch (Exception e) { m_log.warn("CollectorSubPlatformMstEntity() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return ct; } /********************** * ? **********************/ /** * ????? * <BR> * ???????????<BR> * ?????????? * ????????????<BR> * ?????scope????? * * @version 1.0.0 * @since 1.0.0 * * @param ownerRoleId ID * @param locale ? * @return FacilityTreeItem? * @throws HinemosUnknown */ public FacilityTreeItem getFacilityTree(String ownerRoleId, Locale locale) throws HinemosUnknown { JpaTransactionManager jtm = null; FacilityTreeItem treeItem = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ treeItem = FacilitySelector.getFacilityTree(locale, false, null, ownerRoleId); jtm.commit(); } catch (Exception e) { m_log.warn("getFacilityTree() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return treeItem; } /** * ?????(???) * <BR> * ???????????<BR> * ?????????? * ????????????<BR> * ?????scope????? * * @version 4.0.0 * @since 4.0.0 * * @param facilityId ID * @param ownerRoleId ID * @param locale ? * @return FacilityTreeItem? * @throws HinemosUnknown */ public FacilityTreeItem getExecTargetFacilityTree(String facilityId, String ownerRoleId, Locale locale) throws HinemosUnknown { JpaTransactionManager jtm = null; FacilityTreeItem treeItem = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ treeItem = FacilitySelector.getFacilityTree(facilityId, locale, false, Boolean.TRUE, ownerRoleId); jtm.commit(); } catch (Exception e) { m_log.warn("getExecTargetFacilityTree() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return treeItem; } /** * ????? * <BR> * ??????????????<BR> * ?????????? * ????????????<BR> * ?????scope????? * * @param locale ? * @param ownerRoleId ID * @return FacilityTreeItem? * @throws HinemosUnknown */ public FacilityTreeItem getNodeFacilityTree(Locale locale, String ownerRoleId) throws HinemosUnknown { JpaTransactionManager jtm = null; FacilityTreeItem treeItem = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ treeItem = FacilitySelector.getNodeFacilityTree(locale, ownerRoleId); jtm.commit(); } catch (Exception e) { m_log.warn("getNodeFacilityTree() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return treeItem; } /********************** * ?(getter) **********************/ /** * ????<BR> * ?????????????<BR> * ?NodeInfo?ArrayList??NodeInfo?? * ????????? * ID * ?? * IP??IPv4, Ipv6 * * getNodeFacilityIdList???getNode??????? * * @version 1.0.0 * @since 1.0.0 * * @return NodeInfo?? * @throws HinemosUnknown */ public ArrayList<NodeInfo> getNodeList() throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<NodeInfo> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeList(); jtm.commit(); } catch (Exception e) { m_log.warn("getExecTargetFacilityTree() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????<BR> * * @version 4.0.0 * @since 4.0.0 * * @return NodeInfo?? * @throws HinemosUnknown */ public List<NodeInfo> getNodeDetailList() throws HinemosUnknown { JpaTransactionManager jtm = null; List<NodeInfo> list = new ArrayList<NodeInfo>(); try { jtm = new JpaTransactionManager(); jtm.begin(); for (String facilityId : FacilitySelector.getFacilityIdList("REGISTERED", null, 0, false, false)) { NodeInfo nodeInfo = NodeProperty.getProperty(facilityId); list.add(nodeInfo); } jtm.commit(); } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("getNodeDetailList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????<BR> * * ??????????????<BR> * ?NodeInfo???"ID"?"??"?""? * "IP"?"OS??"?"OS"?"?"?""??????? * ??????????<BR> * ?NodeInfo?ArrayList??NodeInfo?? * ?"ID"?"??"?""????????<BR> * * @version 1.0.0 * @since 1.0.0 * * @param property?? * @return NodeInfo?? * @throws HinemosUnknown */ public ArrayList<NodeInfo> getFilterNodeList(NodeInfo property) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<NodeInfo> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getFilterNodeList(property); jtm.commit(); } catch (Exception e) { m_log.warn("getFilterNodeList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * * ??????ID????? * ???ID?????????????? * * ?? * ???facilityId????ArrayList * ?????/????? * * ?? * ?????ID????ArrayList * ?????/??? * * * @version 3.0.0 * @since 3.0.0 * * * @param facilityId ????ID * @param ownerRoleId ??ID * @return ?????????????? * @throws HinemosUnknown */ public ArrayList<String> getExecTargetFacilityIdList(String facilityId, String ownerRoleId) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeFacilityIdList(facilityId, ownerRoleId, RepositoryControllerBean.ALL, false, true); jtm.commit(); } catch (Exception e) { m_log.warn("getExecTargetFacilityIdList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ?ID????<BR> * * ????????????<BR> * ? ID(String)?ArrayList<BR> * * getNodeList() ?????????ArrayList??????? * ??IDString???ArrayList * * @version 1.0.0 * @since 1.0.0 * * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getNodeFacilityIdList() throws HinemosUnknown { return getNodeFacilityIdList(false); } /** * ?ID????<BR> * * ????????????<BR> * ? ID(String)?ArrayList * ?sort?true??????list?Collator.compare()???????<BR> * * getNodeList() ?????????NodeInfo?ArrayList?????? * ??IDString???ArrayList * * @version 2.1.0 * @since 2.1.0 * * @param sort sort ??(?:true ???:false) * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getNodeFacilityIdList(boolean sort) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeFacilityIdList(sort); jtm.commit(); } catch (Exception e) { m_log.warn("getNodeFacilityIdList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ?????<BR> * * faciliyID???????<BR> * * @version 1.0.0 * @since 1.0.0 * * @param facilityId ID * @param locale ? * @return * @throws FacilityNotFound * @throws HinemosUnknown */ public NodeInfo getNode(String facilityId) throws FacilityNotFound, HinemosUnknown { JpaTransactionManager jtm = null; NodeInfo nodeInfo = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ nodeInfo = NodeProperty.getProperty(facilityId); jtm.commit(); } catch (FacilityNotFound e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("getNode() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return nodeInfo; } /** * ????<BR> * * ?????????????<BR> * ????????????<BR> * (>>DB?)<BR> * * @version 1.0.0 * @since 1.0.0 * * @param facilityId ID * @param parentFacilityId ??ID * @return String * @throws HinemosUnknown */ public String getFacilityPath(String facilityId, String parentFacilityId) throws HinemosUnknown { JpaTransactionManager jtm = null; String facilityPath = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ facilityPath = FacilitySelector.getNodeScopePath(parentFacilityId, facilityId); jtm.commit(); } catch (Exception e) { m_log.warn("getFacilityPath() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return facilityPath; } /** * SNMP???????<BR> * * * ?SNMP????????<BR> * SNMP??????? * ?NodeInfo * * @version 2.1.2 * @since 2.1.2 * * @param ??IP????????ID???????????? * @param locale ? * @return * @throws HinemosUnknown */ public NodeInfoDeviceSearch getNodePropertyBySNMP(String ipAddress, int port, String community, int version, String facilityID, String securityLevel, String user, String authPass, String privPass, String authProtocol, String privProtocol) throws HinemosUnknown, SnmpResponseError { JpaTransactionManager jtm = null; /** ? */ NodeInfo property = null; NodeInfo lastNode = null; NodeInfoDeviceSearch snmpInfo = new NodeInfoDeviceSearch(); if (version == SnmpVersionConstant.TYPE_V3) { snmpv3Check(securityLevel, user, authPass, privPass); } try { jtm = new JpaTransactionManager(); jtm.begin(); property = SearchNodeBySNMP.searchNode(ipAddress, port, community, version, facilityID, securityLevel, user, authPass, privPass, authProtocol, privProtocol); snmpInfo.setNodeInfo(property); boolean isUpdated = false; if (facilityID != null) { //???SNMP?? lastNode = new RepositoryControllerBean().getNode(facilityID); //?? isUpdated = !snmpInfo.equalsNodeInfo(lastNode); } m_log.debug("isUpdated:" + isUpdated); jtm.commit(); } catch (SnmpResponseError e) { jtm.rollback(); throw e; } catch (UnknownHostException e) { m_log.info("getNodePropertyBySNMP() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("getNodePropertyBySNMP() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return snmpInfo; } /** * ??HashMap???ID???<BR> * ?????????? * * @version 3.1.0 * @since 3.1.0 * * @return ArrayList<String> * @throws HinemosUnknown */ @Deprecated public ArrayList<String> findByCondition(HashMap<String, String> condition) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeFacilityIdListByCondition(condition); jtm.commit(); } catch (HinemosUnknown e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("findByCondition() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * IP???ID?? * * @version 4.0.0 * @since 4.0.0 * * @param ipaddr IP(Inet4Address or Inet6Address) * @return ID? * @throws HinemosUnknown ?????? */ public List<String> getFacilityIdByIpAddress(InetAddress ipaddr) throws HinemosUnknown { JpaTransactionManager jtm = null; List<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); list = FacilitySelector.getFacilityIdByIpAddress(ipaddr); jtm.commit(); } catch (HinemosUnknown e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("getFacilityIdByIpAddress() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ID????<BR> * * ????????IP???ID? * ????<BR> * ?ID(String)?ArrayList * getNodeList(NodeInfo)??? * * @version 1.0.0 * @since 1.0.0 * * @param hostName ???? * @param ipAddressIP(v4) * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getFacilityIdList(String hostName, String ipAddress) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getFacilityIdList(hostName, ipAddress); jtm.commit(); } catch (Exception e) { m_log.warn("getFacilityIdList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /********************** * ?(getter) **********************/ /** * ?????<BR> * ?????????"?"? * ????? * * @version 3.1.0 * @since 1.0.0 * * @param nodeinfo ?? * @throws FacilityDuplicate * @throws InvalidSetting * @throws HinemosUnknown */ public void addNode(NodeInfo nodeInfo) throws FacilityDuplicate, InvalidSetting, HinemosUnknown { addNode(nodeInfo, true); } /** * ??????TOPIC???<BR> * ?????????"?"? * ????? * * @version 3.1.0 * @since 1.0.0 * * @param nodeInfo ?? * @throws FacilityDuplicate * @throws InvalidSetting * @throws HinemosUnknown */ public void addNode(final NodeInfo nodeInfo, boolean topicSendFlg) throws FacilityDuplicate, InvalidSetting, HinemosUnknown { JpaTransactionManager jtm = new JpaTransactionManager(); try { jtm.begin(); // ??null????????????null?? nodeInfo.setDefaultInfo(); // ? RepositoryValidator.validateNodeInfo(nodeInfo); FacilityModifier.addNode(nodeInfo, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), FacilitySortOrderConstant.DEFAULT_SORT_ORDER_NODE); jtm.addCallback(new NodeCacheUpdateCallback(nodeInfo.getFacilityId())); jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); jtm.addCallback(new NodeToMonitorCacheChangeCallback()); jtm.addCallback(new EmptyJpaTransactionCallback() { @Override public void postCommit() { NodeMonitorPollerController.registNodeMonitorPoller(nodeInfo); } }); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { jtm.addCallback(new RepositoryListenerCallback(listener, Type.ADD_NODE, null, nodeInfo.getFacilityId())); } } finally { ListenerReadWriteLock.readUnlock(); } jtm.commit(); } catch (EntityExistsException e) { jtm.rollback(); throw new FacilityDuplicate(e.getMessage(), e); } catch (InvalidSetting e) { jtm.rollback(); throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("addNode() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { jtm.close(); } } /** * ???<BR> * ?property????????????<BR> * * @version 2.0.0 * @since 1.0.0 * * @param info?? * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void modifyNode(NodeInfo info) throws InvalidSetting, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); // ??null????????????null?? info.setDefaultInfo(); // ? RepositoryValidator.validateNodeInfo(info); /** ? */ FacilityModifier.modifyNode(info, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), true); jtm.addCallback(new NodeCacheUpdateCallback(info.getFacilityId())); jtm.addCallback(new JobMultiplicityCacheKickCallback(info.getFacilityId())); jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); // ??????????????????? if (info.getValid().booleanValue() != this.getNode(info.getFacilityId()).getValid().booleanValue()) { jtm.addCallback(new NodeToMonitorCacheChangeCallback()); } try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { jtm.addCallback( new RepositoryListenerCallback(listener, Type.CHANGE_NODE, null, info.getFacilityId())); } } finally { ListenerReadWriteLock.readUnlock(); } jtm.commit(); } catch (InvalidSetting | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("modifyNode() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ???<BR> * * faciityID???????? * * @version 1.0.0 * @since 1.0.0 * * @param facilityIds ID?? * @throws UsedFacility * @throws InvalidRole * @throws HinemosUnknown */ public void deleteNode(String[] facilityIds) throws UsedFacility, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; /** ? */ try { jtm = new JpaTransactionManager(); jtm.begin(); for (String facilityId : facilityIds) { checkIsUseFacility(facilityId); FacilityModifier.deleteNode(facilityId, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), true); } for (final String facilityId : facilityIds) { jtm.addCallback(new NodeCacheRemoveCallback(facilityId)); jtm.addCallback(new EmptyJpaTransactionCallback() { @Override public void postCommit() { NodeMonitorPollerController.unregistNodeMonitorPoller(facilityId); } }); } jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); jtm.addCallback(new NodeToMonitorCacheChangeCallback()); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { for (String facilityId : facilityIds) { jtm.addCallback( new RepositoryListenerCallback(listener, Type.REMOVE_NODE, null, facilityId)); } } } finally { ListenerReadWriteLock.readUnlock(); } // // ?????????? new NodeMapControllerBean().deleteMapInfo(Arrays.asList(facilityIds), null); jtm.commit(); } catch (UsedFacility | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("deleteNode() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /********************** * ? **********************/ /** * ID????<BR> * ?????????????<BR> * ??????????ID????<BR> * ?ArrayList??FacilityInfo???? * "ID"?"??"?""????????<BR> * * @version 1.0.0 * @since 1.0.0 * * @param parentFacilityId ID * @return ScopeInfo?? * @throws HinemosUnknown */ public ArrayList<FacilityInfo> getFacilityList(String parentFacilityId) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<FacilityInfo> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getFacilityListAssignedScope(parentFacilityId); jtm.commit(); } catch (Exception e) { m_log.warn("getFacilityList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????<BR> * * @version 1.0.0 * @since 1.0.0 * * @param facilityId ID * @param locale ? * @return ?ID???? * @throws FacilityNotFound * @throws HinemosUnknown * @throws InvalidRole */ public ScopeInfo getScope(String facilityId) throws FacilityNotFound, HinemosUnknown, InvalidRole { JpaTransactionManager jtm = null; /** ? */ ScopeInfo property = null; try { jtm = new JpaTransactionManager(); jtm.begin(); // ? if (facilityId == null) { property = new ScopeInfo(); } // else { property = ScopeProperty.getProperty_NONE(facilityId); //ID?????? FacilityTreeCache.getFacilityInfo(facilityId); } jtm.commit(); } catch (FacilityNotFound | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (ObjectPrivilege_InvalidRole e) { if (jtm != null) jtm.rollback(); throw new InvalidRole(e.getMessage(), e); } catch (Exception e) { m_log.warn("getScope() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return property; } /** * ?????<BR> * * parentFacilityId????property?? * ???<BR> * property???"ID"?"??"?""???????? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId * @param property * @throws FacilityDuplicate * @throws InvalidSetting * @thorws InvalidRole * @throws HinemosUnknown */ public void addScope(String parentFacilityId, ScopeInfo property) throws FacilityDuplicate, InvalidSetting, InvalidRole, HinemosUnknown { addScope(parentFacilityId, property, FacilitySortOrderConstant.DEFAULT_SORT_ORDER_SCOPE); } /** * ?????()<BR> * * parentFacilityId????property?? * ???<BR> * property???"ID"?"??"?""???????? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId * @param property * @param sortOrder * @throws FacilityDuplicate * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void addScope(String parentFacilityId, ScopeInfo property, int displaySortOrder) throws FacilityDuplicate, InvalidSetting, InvalidRole, HinemosUnknown { addScope(parentFacilityId, property, displaySortOrder, true); } /** * ?????(??TOPIC???)<BR> * * parentFacilityId????property?? * ???<BR> * property???"ID"?"??"?""???????? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId * @param info * @param sortOrder * @throws FacilityDuplicate * @throws InvalidSetting * @throws HinemosUnknown */ public void addScope(String parentFacilityId, ScopeInfo info, int displaySortOrder, boolean topicSendFlg) throws FacilityDuplicate, InvalidSetting, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; /** ? */ try { jtm = new JpaTransactionManager(); jtm.begin(); //? RepositoryValidator.validateScopeInfo(parentFacilityId, info, true); FacilityModifier.addScope(parentFacilityId, info, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), displaySortOrder, topicSendFlg); jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { jtm.addCallback( new RepositoryListenerCallback(listener, Type.ADD_SCOPE, info.getFacilityId(), null)); } } finally { ListenerReadWriteLock.readUnlock(); } jtm.commit(); } catch (InvalidSetting | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (EntityExistsException e) { if (jtm != null) jtm.rollback(); throw new FacilityDuplicate(e.getMessage(), e); } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (ObjectPrivilege_InvalidRole e) { if (jtm != null) jtm.rollback(); throw new InvalidRole(e.getMessage(), e); } catch (Exception e) { m_log.warn("addScope() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ????<BR> * * property???????<BR> * property???"ID"?"??"?""???????? * property???ID???????<BR> * * @version 1.0.0 * @since 1.0.0 * * @param info * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void modifyScope(ScopeInfo info) throws InvalidSetting, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); //? RepositoryValidator.validateScopeInfo(null, info, false); //?????? checkIsBuildInScope(info.getFacilityId()); /** ? */ FacilityModifier.modifyScope(info, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), true); jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { jtm.addCallback(new RepositoryListenerCallback(listener, Type.CHANGE_SCOPE, info.getFacilityId(), null)); } } finally { ListenerReadWriteLock.readUnlock(); } jtm.commit(); } catch (InvalidSetting | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (ObjectPrivilege_InvalidRole e) { if (jtm != null) jtm.rollback(); throw new InvalidRole(e.getMessage(), e); } catch (Exception e) { m_log.warn("modifyScope() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ???<BR> * * faciityID???????? * * @version 1.0.0 * @since 1.0.0 * * @param facilityIds ID * @throws UsedFacility * @throws InvalidRole * @throws HinemosUnknown */ public void deleteScope(String[] facilityIds) throws UsedFacility, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ for (String facilityId : facilityIds) { checkIsBuildInScope(facilityId); checkIsUseFacility(facilityId); FacilityModifier.deleteScope(facilityId, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), true); // // ?????????? new NodeMapControllerBean().deleteMapInfo(null, facilityId); } jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); jtm.addCallback(new NodeToMonitorCacheChangeCallback()); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { for (String facilityId : facilityIds) { jtm.addCallback( new RepositoryListenerCallback(listener, Type.REMOVE_SCOPE, facilityId, null)); } } } finally { ListenerReadWriteLock.readUnlock(); } jtm.commit(); } catch (UsedFacility | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (ObjectPrivilege_InvalidRole e) { if (jtm != null) jtm.rollback(); throw new InvalidRole(e.getMessage(), e); } catch (Exception e) { m_log.warn("deleteScope() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /********************** * ?? **********************/ /** * ????<BR> * * ?ID??????????<BR> * ?????level????????<BR> * ?NodeInfo?ArrayList??NodeInfo?? * ?"ID"?"??"?""????????<BR> * * * @version 1.0.0 * @since 1.0.0 * * @param parentFacilityId * @param level? 0:ALL(?) 1:ONE_LEVEL * @return NodeInfo?? * @throws HinemosUnknown */ public ArrayList<NodeInfo> getNodeList(String parentFacilityId, int level) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<NodeInfo> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeList(parentFacilityId, null, level); jtm.commit(); } catch (Exception e) { m_log.warn("getNodeList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????<BR> * ???????????? * ????? * ??????? * ?ArrayList?ArrayList??ArrayList??""???? * ?String??????? * ?ArrayList?????????????? * * * @version 1.0.0 * @since 1.0.0 * * @param facilityId ?ID * @return String?? * @throws InvalidRole * @throws HinemosUnknown */ public ArrayList<String> getNodeScopeList(String facilityId) throws InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeScopeList(facilityId); jtm.commit(); } catch (InvalidRole e) { jtm.rollback(); throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("getNodeScopeList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ID????<BR> * * ???ID???????? * ????<BR> * ????ID????<BR> * ? IDString?ArrayList * * @version 2.1.0 * @since 1.0.0 * * @param parentFacilityId ID * @param level? 0:ALL(?) 1:ONE_LEVEL * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getFacilityIdList(String parentFacilityId, int level) throws HinemosUnknown { /** ? */ return getFacilityIdList(parentFacilityId, level, true); } /** * ID????<BR> * * ???ID???????? * ????<BR> * ? IDString?ArrayList * * @version 2.1.0 * @since 1.0.0 * * @param parentFacilityId ID * @param level? 0:ALL(?) 1:ONE_LEVEL * @param scopeFlag ?????:true ????:false) * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getFacilityIdList(String parentFacilityId, int level, boolean scopeFlag) throws HinemosUnknown { /** ? */ return getFacilityIdList(parentFacilityId, level, false, scopeFlag); } /** * ID????<BR> * * ???ID???????? * ????<BR> * ? IDString?ArrayList * ?sort?true??????list?Collator.compare()??????? * * * @version 2.1.0 * @since 2.1.0 * * @param parentFacilityId ID * @param level ? 0:ALL(?) 1:ONE_LEVEL * @param sort ??(?:true ???:false) * @param scopeFlag ?????:true ????:false) * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getFacilityIdList(String parentFacilityId, int level, boolean sort, boolean scopeFlag) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getFacilityIdList(parentFacilityId, null, level, sort, scopeFlag); jtm.commit(); } catch (Exception e) { m_log.warn("getFacilityIdList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ?ID????<BR> * * ???ID??????? * ????<BR> * ? IDString?ArrayList * * @version 2.1.0 * @since 1.0.0 * * @param parentFacilityId ID * @param ownerRoleId ID * @param level ? 0:ALL(?) 1:ONE_LEVEL * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getNodeFacilityIdList(String parentFacilityId, String ownerRoleId, int level) throws HinemosUnknown { /** ? */ return getNodeFacilityIdList(parentFacilityId, ownerRoleId, level, false, true); } /** * ?ID?<BR> * ???ID??????? * ????<BR> * ? IDString?ArrayList * ?sort?true??????list?Collator.compare()??????? * * @version 2.1.0 * @since 2.1.0 * * @param parentFacilityId * @param ownerRoleId * @param level ? 0:ALL(?) 1:ONE_LEVEL * @param sort sort ??(?:true ???:false) * @return ID?? * @throws HinemosUnknown */ public ArrayList<String> getNodeFacilityIdList(String parentFacilityId, String ownerRoleId, int level, boolean sort, Boolean valid) throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = null; try { jtm = new JpaTransactionManager(); jtm.begin(); /** ? */ list = FacilitySelector.getNodeFacilityIdList(parentFacilityId, ownerRoleId, level, sort, valid); jtm.commit(); } catch (Exception e) { m_log.warn("getNodeFacilityIdList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????????TOPIC???<BR> * * parentFacilityId???facilityIds?? * ??? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId? * @param facilityIds ???() * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void assignNodeScope(String parentFacilityId, String[] facilityIds, boolean topicSendFlg) throws InvalidSetting, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); //? RepositoryValidator.validateaAssignNodeScope(parentFacilityId, facilityIds); //?????? checkIsBuildInScope(parentFacilityId); /** ? */ FacilityModifier.assignFacilitiesToScope(parentFacilityId, facilityIds); jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); jtm.addCallback(new NodeToMonitorCacheChangeCallback()); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { for (String facilityId : facilityIds) { jtm.addCallback(new RepositoryListenerCallback(listener, Type.ASSIGN_NODE_TO_SCOPE, parentFacilityId, facilityId)); } } } finally { ListenerReadWriteLock.readUnlock(); } jtm.commit(); } catch (InvalidSetting | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (ObjectPrivilege_InvalidRole e) { if (jtm != null) jtm.rollback(); throw new InvalidRole(e.getMessage(), e); } catch (Exception e) { m_log.warn("assignNodeScope() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /** * ???????<BR> * * parentFacilityId???facilityIds?? * ??? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId? * @param facilityIds ???() * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void assignNodeScope(String parentFacilityId, String[] facilityIds) throws InvalidSetting, InvalidRole, HinemosUnknown { assignNodeScope(parentFacilityId, facilityIds, true); } /** * ????????<BR> * parentFacilityId???facilityIds?? * ???? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId ??? * @param facilityIds ?? * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void releaseNodeScope(String parentFacilityId, String[] facilityIds) throws InvalidSetting, InvalidRole, HinemosUnknown { releaseNodeScope(parentFacilityId, facilityIds, true); } /** * ?????????TOPIC???<BR> * parentFacilityId???facilityIds?? * ???? * * @version 3.1.0 * @since 1.0.0 * * @param parentFacilityId ??? * @param facilityIds ?? * @throws InvalidSetting * @throws InvalidRole * @throws HinemosUnknown */ public void releaseNodeScope(String parentFacilityId, String[] facilityIds, boolean topicSendFlg) throws InvalidSetting, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); //? RepositoryValidator.validateaAssignNodeScope(parentFacilityId, facilityIds); //?????? checkIsBuildInScope(parentFacilityId); /** ? */ FacilityModifier.releaseNodeFromScope(parentFacilityId, facilityIds, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), topicSendFlg); jtm.addCallback(new FacilityIdCacheInitCallback()); jtm.addCallback(new FacilityTreeCacheRefreshCallback()); jtm.addCallback(new RepositoryChangedNotificationCallback()); jtm.addCallback(new NodeToMonitorCacheChangeCallback()); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { for (String facilityId : facilityIds) { jtm.addCallback(new RepositoryListenerCallback(listener, Type.RELEASE_NODE_FROM_SCOPE, parentFacilityId, facilityId)); } } } finally { ListenerReadWriteLock.readUnlock(); } // // ?????????? new NodeMapControllerBean().deleteMapInfo(Arrays.asList(facilityIds), parentFacilityId); jtm.commit(); } catch (InvalidSetting | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (ObjectPrivilege_InvalidRole e) { if (jtm != null) jtm.rollback(); throw new InvalidRole(e.getMessage(), e); } catch (Exception e) { m_log.warn("releaseNodeScope() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } } /********************** * ???? **********************/ /** * ?????????<BR> * * ID?????????boolean???? * * @version 1.0.0 * @since 1.0.0 * * @param facilityIdID * @return truefalse:???? * @throws FacilityNotFound ??ID??????? * @throws InvalidRole * @throws HinemosUnknown */ public boolean isNode(String facilityId) throws FacilityNotFound, InvalidRole, HinemosUnknown { JpaTransactionManager jtm = null; boolean rtn = false; /** ? */ try { jtm = new JpaTransactionManager(); jtm.begin(); rtn = FacilitySelector.isNode(facilityId); jtm.commit(); } catch (FacilityNotFound | InvalidRole e) { if (jtm != null) { jtm.rollback(); } throw e; } catch (Exception e) { m_log.warn("isNode() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return rtn; } /** * ????<BR> * * ??? * * * @version 1.0.0 * @since 1.0.0 * * @return */ public String getSeparator() { /** ? */ return FacilitySelector.SEPARATOR; } /** * ???????? * * @version 3.2.0 * @since 3.2.0 * @return ArrayList<RepositoryTableInfo> * @throws HinemosUnknown */ public ArrayList<RepositoryTableInfo> getPlatformList() throws HinemosUnknown { ArrayList<RepositoryTableInfo> list = new ArrayList<RepositoryTableInfo>(); JpaTransactionManager jtm = null; try { jtm = new JpaTransactionManager(); jtm.begin(); List<CollectorPlatformMstEntity> ct = QueryUtil.getAllCollectorPlatformMst(); for (CollectorPlatformMstEntity bean : ct) { list.add(new RepositoryTableInfo(bean.getPlatformId(), bean.getPlatformName())); } jtm.commit(); } catch (Exception e) { m_log.warn("getPlatformList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????????? * * @version 3.2.0 * @since 3.2.0 * @return ArrayList * @throws HinemosUnknown */ public ArrayList<RepositoryTableInfo> getCollectorSubPlatformTableInfoList() throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<RepositoryTableInfo> list = new ArrayList<RepositoryTableInfo>(); try { jtm = new JpaTransactionManager(); jtm.begin(); List<CollectorSubPlatformMstEntity> ct = com.clustercontrol.repository.util.QueryUtil .getAllCollectorSubPlatformMstEntity(); for (CollectorSubPlatformMstEntity bean : ct) { list.add(new RepositoryTableInfo(bean.getSubPlatformId(), bean.getSubPlatformName())); } jtm.commit(); } catch (Exception e) { m_log.warn("getVmSolutionMstList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ????????? * * @version 3.2.0 * @since 3.2.0 * @return ArrayList * @throws HinemosUnknown */ public ArrayList<String> getVmProtocolMstList() throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<String> list = new ArrayList<String>(); try { jtm = new JpaTransactionManager(); jtm.begin(); List<String> ct = com.clustercontrol.vm.util.QueryUtil.getVmProtocolMstDistinctProtocol(); for (String protocol : ct) { list.add(protocol); } jtm.commit(); } catch (Exception e) { m_log.warn("getVmProtocolMstList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ??? * * @return */ public Date getLastUpdate() { Date updateTime = new Date(SettingUpdateInfo.getInstance().getRepositoryUpdateTime()); m_log.debug("getLastUpdate() lastUpdate = " + updateTime.toString()); return updateTime; } /** * ????<BR> * * @return * @throws HinemosUnknown */ public ArrayList<AgentStatusInfo> getAgentStatusList() throws HinemosUnknown { JpaTransactionManager jtm = null; ArrayList<AgentStatusInfo> list = null; m_log.debug("getAgentStatusList() "); try { jtm = new JpaTransactionManager(); jtm.begin(); list = AgentLibDownloader.getAgentStatusList(); jtm.commit(); } catch (HinemosUnknown e) { jtm.rollback(); throw e; } catch (Exception e) { m_log.warn("getAgentStatusList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); if (jtm != null) jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { if (jtm != null) jtm.close(); } return list; } /** * ?????<BR> * * * @param facilityIdID * @param agentCommand ?? * @see com.clustercontrol.repository.bean.AgentCommandConstant */ public void restartAgent(ArrayList<String> facilityIdList, int agentCommand) { // Local Variables TopicInfo topicInfo = null; // MAIN topicInfo = new TopicInfo(); /* * com.clustercontrol.repository.bean.AgentCommandConstant * public static int RESTART = 1; * public static int UPDATE = 2; */ topicInfo.setAgentCommand(agentCommand); // ????????? int restartSleep = 500; try { restartSleep = HinemosPropertyUtil .getHinemosPropertyNum("repository.restart.sleep", Long.valueOf(restartSleep)).intValue(); m_log.info("restartAgent() restart sleep = " + restartSleep); } catch (Exception e) { m_log.warn("restartAgent() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); } for (String facilityId : facilityIdList) { if (AgentConnectUtil.isValidAgent(facilityId)) { try { // ?? QueryUtil.getFacilityPK(facilityId, ObjectPrivilegeMode.EXEC); } catch (InvalidRole e) { // ????????ID??????? continue; } catch (FacilityNotFound e) { continue; } m_log.info("restart() : setTopic(" + facilityId + ")"); AgentConnectUtil.setTopic(facilityId, topicInfo); try { Thread.sleep(restartSleep); } catch (InterruptedException e) { m_log.info("restartAgent : " + e.getMessage()); } } else { m_log.info("restartAgent() agent does not connect. " + "(facilityId=" + facilityId + ")"); } } } /** * @param facilityIdID * @param agentCommand ?? * @throws HinemosUnknown * @see com.clustercontrol.repository.bean.AgentCommandConstant */ public HashMap<String, String> getAgentLibMap() throws HinemosUnknown { HashMap<String, String> map = null; try { map = AgentLibDownloader.getAgentLibMap(); } catch (Exception e) { m_log.warn("getAgentLibMap() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); throw new HinemosUnknown(e.getMessage(), e); } return map; } public void checkIsUseFacility(String facilityId) throws HinemosUnknown, UsedFacility { String message = ""; try { new JobControllerBean().isUseFacilityId(facilityId); } catch (UsedFacility e) { message += (e.getMessage() + "\n"); } try { new MonitorControllerBean().isUseFacilityId(facilityId); } catch (UsedFacility e) { message += (e.getMessage() + "\n"); } try { new NotifyControllerBean().isUseFacilityId(facilityId); } catch (UsedFacility e) { message += (e.getMessage() + "\n"); } try { new InfraControllerBean().isUseFacilityId(facilityId); } catch (UsedFacility e) { message += e.getMessage(); } if (message.trim().length() > 0) { UsedFacility ex = new UsedFacility(message); throw ex; } } /** * ???????IP??? * * @param hostname ?? * @return ID?? */ public Set<String> getNodeListByNodename(String hostname) { Set<String> ret = new HashSet<String>(); JpaTransactionManager jtm = null; /** ? */ try { jtm = new JpaTransactionManager(); jtm.begin(); ret = FacilitySelector.getNodeListByNodename(hostname); // ? jtm.commit(); } catch (Exception e) { m_log.warn("modifyUserInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); // ?? if (jtm != null) jtm.rollback(); } finally { if (jtm != null) jtm.close(); } return ret; } /** * IP??? * @param ipAddress IP * @return ID?? */ public Set<String> getNodeListByIpAddress(InetAddress ipAddress) { Set<String> ret = new HashSet<String>(); JpaTransactionManager jtm = null; /** ? */ try { // EntityManager? jtm = new JpaTransactionManager(); jtm.begin(); ret = FacilitySelector.getNodeListByIpAddress(ipAddress); // ? jtm.commit(); } catch (Exception e) { m_log.warn("modifyUserInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); // ?? if (jtm != null) jtm.rollback(); } finally { if (jtm != null) jtm.close(); } return ret; } /** * ?????? * @param hostname ?? * @return ID?? */ public Set<String> getNodeListByHostname(String hostname) { Set<String> ret = new HashSet<String>(); JpaTransactionManager jtm = null; /** ? */ try { // EntityManager? jtm = new JpaTransactionManager(); jtm.begin(); ret = FacilitySelector.getNodeListByHostname(hostname); // ? jtm.commit(); } catch (Exception e) { m_log.warn("modifyUserInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); // ?? if (jtm != null) jtm.rollback(); } finally { if (jtm != null) jtm.close(); } return ret; } /** * ID????????? * @param scopeFacilityId ?ID * @param nodeFacilityId ?ID * @param ownerRoleId ID * @return */ public boolean containsFaciliyId(String scopeFacilityId, String nodeFacilityId, String ownerRoleId) { boolean ret = false; JpaTransactionManager jtm = null; /** ? */ try { // EntityManager? jtm = new JpaTransactionManager(); jtm.begin(); ret = FacilitySelector.containsFaciliyId(scopeFacilityId, nodeFacilityId, ownerRoleId); // ? jtm.commit(); } catch (Exception e) { m_log.warn("modifyUserInfo() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); // ?? if (jtm != null) jtm.rollback(); } finally { if (jtm != null) jtm.close(); } return ret; } private void snmpv3Check(String securityLevel, String user, String authPass, String privPass) throws HinemosUnknown { if (securityLevel.equals(SnmpSecurityLevelConstant.AUTH_NOPRIV) || securityLevel.equals(SnmpSecurityLevelConstant.AUTH_PRIV)) { if (user == null || user.length() < 1) { throw new HinemosUnknown(MessageConstant.MESSAGE_PLEASE_SET_USER_NAME.getMessage()); } if (authPass == null || authPass.length() < 8) { throw new HinemosUnknown(MessageConstant.MESSAGE_PLEASE_SET_AUTHPASS_8CHARA_MINIMUM.getMessage()); } } if (securityLevel.equals(SnmpSecurityLevelConstant.AUTH_PRIV)) { if (privPass == null || privPass.length() < 8) { throw new HinemosUnknown(MessageConstant.MESSAGE_PLEASE_SET_PRIVPASS_8CHARA_MINIMUM.getMessage()); } } } /** * ????????<BR> * ?????????? * * @version 5.0.0 * @since 5.0.0 * * @param nodeInfo ?? * @throws FacilityDuplicate * @throws InvalidSetting * @throws HinemosUnknown */ public void addNodeWithoutRefresh(NodeInfo nodeInfo) throws FacilityDuplicate, InvalidSetting, HinemosUnknown { JpaTransactionManager jtm = new JpaTransactionManager(); try { jtm.begin(); // ??null????????????null?? nodeInfo.setDefaultInfo(); // ? RepositoryValidator.validateNodeInfo(nodeInfo); FacilityModifier.addNode(nodeInfo, (String) HinemosSessionContext.instance().getProperty(HinemosSessionContext.LOGIN_USER_ID), FacilitySortOrderConstant.DEFAULT_SORT_ORDER_NODE); final String facilityId = nodeInfo.getFacilityId(); jtm.addCallback(new NodeCacheRemoveCallback(facilityId)); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { jtm.addCallback(new RepositoryListenerCallback(listener, Type.ADD_NODE, null, facilityId)); } } finally { ListenerReadWriteLock.readUnlock(); } jtm.addCallback(new NodeToMonitorCacheChangeCallback()); final NodeInfo _nodeInfo = nodeInfo; jtm.addCallback(new EmptyJpaTransactionCallback() { @Override public void postCommit() { NodeMonitorPollerController.registNodeMonitorPoller(_nodeInfo); } }); jtm.commit(); } catch (EntityExistsException e) { String errMsg = " ipAddress=" + nodeInfo.getIpAddressV4() + " " + nodeInfo.getIpAddressV6() + " facilityID=" + nodeInfo.getFacilityId() + ","; m_log.warn( "addNodeWithoutRefresh() : " + errMsg + e.getClass().getSimpleName() + ", " + e.getMessage()); jtm.rollback(); throw new FacilityDuplicate(e.getMessage(), e); } catch (InvalidSetting | HinemosUnknown e) { jtm.rollback(); throw e; } catch (FacilityNotFound e) { jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } catch (Exception e) { m_log.warn("addNodeWithoutRefresh() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); jtm.rollback(); throw new HinemosUnknown(e.getMessage(), e); } finally { jtm.close(); } } /** * IRepositoryListener?. * @param listener ?IRepositoryListener */ public static void addListener(IRepositoryListener listener) { if (listener == null) { throw new NullPointerException("argument (listerer) is null."); } try { ListenerReadWriteLock.writeLock(); for (IRepositoryListener obj : _listenerList) { if (listener.equals(obj)) { m_log.info("skipped, listener already registered : listener = " + listener.getListenerId()); return; } } m_log.debug("adding new listener : listenerId = " + listener.getListenerId()); _listenerList.add(listener); } finally { ListenerReadWriteLock.writeUnlock(); } } public static void removeListener(String listenerId) { if (listenerId == null) { throw new NullPointerException("argument (listererId) is null."); } List<IRepositoryListener> listenerList = new ArrayList<IRepositoryListener>(); try { ListenerReadWriteLock.readLock(); for (IRepositoryListener listener : _listenerList) { if (listenerId.equals(listener.getListenerId())) { m_log.debug("removing listener : listenerId = " + listener.getListenerId()); listenerList.add(listener); } } } finally { ListenerReadWriteLock.readUnlock(); try { ListenerReadWriteLock.writeLock(); _listenerList.removeAll(listenerList); } finally { ListenerReadWriteLock.writeUnlock(); } } } private static class ListenerReadWriteLock { private static final ReentrantReadWriteLock _lock = new ReentrantReadWriteLock(); public static void readLock() { _lock.readLock().lock(); } public static void readUnlock() { _lock.readLock().unlock(); } public static void writeLock() { _lock.writeLock().lock(); } public static void writeUnlock() { _lock.writeLock().unlock(); } } /** * ???ID????????? * HinemosUnknown???? * * @version 5.0.0 * @since 5.0.0 * * @param facilityId ???ID * @throws FacilityDuplicate * @throws InvalidSetting * @throws HinemosUnknown */ private void checkIsBuildInScope(String facilityId) throws FacilityNotFound, InvalidRole, HinemosUnknown { ScopeInfo facility = QueryUtil.getScopePK(facilityId); if (FacilitySelector.isBuildinScope(facility)) { HinemosUnknown e = new HinemosUnknown( "this facility is built in scope. (facilityId = " + facilityId + ")"); m_log.info("deleteScopeRecursive() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } } }